mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-16 22:44:11 +02:00
Update portfolio.py
This commit is contained in:
parent
d4bcd03a96
commit
88e8b2dbeb
1 changed files with 23 additions and 23 deletions
|
@ -300,29 +300,6 @@ class BasePortfolioMemberForm(forms.ModelForm):
|
||||||
|
|
||||||
return cleaned_data
|
return cleaned_data
|
||||||
|
|
||||||
def _post_clean(self):
|
|
||||||
"""
|
|
||||||
Override _post_clean to customize model validation errors.
|
|
||||||
This runs after form clean is complete, but before the errors are displayed.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
super()._post_clean()
|
|
||||||
self.instance.clean()
|
|
||||||
except forms.ValidationError as e:
|
|
||||||
override_error = False
|
|
||||||
if hasattr(e, "code"):
|
|
||||||
field = "email" if "email" in self.fields else None
|
|
||||||
if e.code == "has_existing_permissions":
|
|
||||||
self.add_error(field, "This user is already a member of another .gov organization.")
|
|
||||||
override_error = True
|
|
||||||
elif e.code == "has_existing_invitations":
|
|
||||||
self.add_error(field, "This user has already been invited to another .gov organization.")
|
|
||||||
override_error = True
|
|
||||||
|
|
||||||
if override_error:
|
|
||||||
if "__all__" in self._errors:
|
|
||||||
del self._errors["__all__"]
|
|
||||||
|
|
||||||
def map_instance_to_initial(self):
|
def map_instance_to_initial(self):
|
||||||
"""
|
"""
|
||||||
Maps self.instance to self.initial, handling roles and permissions.
|
Maps self.instance to self.initial, handling roles and permissions.
|
||||||
|
@ -468,3 +445,26 @@ class PortfolioNewMemberForm(BasePortfolioMemberForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PortfolioInvitation
|
model = PortfolioInvitation
|
||||||
fields = ["portfolio", "email", "roles", "additional_permissions"]
|
fields = ["portfolio", "email", "roles", "additional_permissions"]
|
||||||
|
|
||||||
|
def _post_clean(self):
|
||||||
|
"""
|
||||||
|
Override _post_clean to customize model validation errors.
|
||||||
|
This runs after form clean is complete, but before the errors are displayed.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
super()._post_clean()
|
||||||
|
self.instance.clean()
|
||||||
|
except forms.ValidationError as e:
|
||||||
|
override_error = False
|
||||||
|
if hasattr(e, "code"):
|
||||||
|
field = "email" if "email" in self.fields else None
|
||||||
|
if e.code == "has_existing_permissions":
|
||||||
|
self.add_error(field, "This user is already a member of another .gov organization.")
|
||||||
|
override_error = True
|
||||||
|
elif e.code == "has_existing_invitations":
|
||||||
|
self.add_error(field, "This user has already been invited to another .gov organization.")
|
||||||
|
override_error = True
|
||||||
|
|
||||||
|
if override_error:
|
||||||
|
if "__all__" in self._errors:
|
||||||
|
del self._errors["__all__"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue