improved handling of edge case where no portfolio defined

This commit is contained in:
David Kennedy 2024-08-01 18:41:43 -04:00
parent 9a6f5fc408
commit e614a0e6be
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -1,5 +1,6 @@
import logging import logging
from django.shortcuts import get_object_or_404, render from django.http import Http404
from django.shortcuts import render
from django.urls import reverse from django.urls import reverse
from django.contrib import messages from django.contrib import messages
from registrar.forms.portfolio import PortfolioOrgAddressForm from registrar.forms.portfolio import PortfolioOrgAddressForm
@ -50,8 +51,11 @@ class PortfolioOrganizationView(PortfolioBasePermissionView, FormMixin):
return context return context
def get_object(self, queryset=None): def get_object(self, queryset=None):
"""Get the portfolio object based on the URL parameter.""" """Get the portfolio object based on the request user."""
return get_object_or_404(Portfolio, id=self.request.user.portfolio.id) portfolio = self.request.user.portfolio
if portfolio is None:
raise Http404("No organization found for this user")
return portfolio
def get_form_kwargs(self): def get_form_kwargs(self):
"""Include the instance in the form kwargs.""" """Include the instance in the form kwargs."""