mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 04:59:59 +02:00
improved handling of edge case where no portfolio defined
This commit is contained in:
parent
9a6f5fc408
commit
e614a0e6be
1 changed files with 7 additions and 3 deletions
|
@ -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."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue