mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 03:58:39 +02:00
Replace form with modelform
Pull in content from related PR and refactor around it
This commit is contained in:
parent
d202d2601f
commit
9a6ccc1c44
10 changed files with 230 additions and 363 deletions
|
@ -55,6 +55,34 @@ class UserProfileForm(forms.ModelForm):
|
|||
"required": "Enter your email address in the required format, like name@example.com."
|
||||
}
|
||||
self.fields["phone"].error_messages["required"] = "Enter your phone number."
|
||||
self.domainInfo = None
|
||||
|
||||
DomainHelper.disable_field(self.fields["email"], disable_required=True)
|
||||
|
||||
|
||||
class FinishSetupProfileForm(UserProfileForm):
|
||||
"""Form for updating user profile."""
|
||||
|
||||
full_name = forms.CharField(required=True, label="Full name")
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
# Remove the full name property
|
||||
if "full_name" in cleaned_data:
|
||||
# Delete the full name element as its purely decorative.
|
||||
# We include it as a normal Charfield for all the advantages
|
||||
# and utility that it brings, but we're playing pretend.
|
||||
del cleaned_data["full_name"]
|
||||
return cleaned_data
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Override the inerited __init__ method to update the fields."""
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set custom form label for email
|
||||
self.fields["email"].label = "Organization email"
|
||||
self.fields["title"].label = "Title or role in your organization"
|
||||
|
||||
# Define the "full_name" value
|
||||
if self.instance and hasattr(self.instance, 'full_name'):
|
||||
self.fields["full_name"].initial = self.instance.get_formatted_name()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue