mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 19:20:47 +02:00
Readonly logic
This commit is contained in:
parent
1dc93f7d0f
commit
a9a93df5cd
3 changed files with 29 additions and 26 deletions
|
@ -70,27 +70,22 @@ class PortfolioOrgAddressForm(forms.ModelForm):
|
||||||
|
|
||||||
|
|
||||||
class PortfolioSeniorOfficialForm(forms.ModelForm):
|
class PortfolioSeniorOfficialForm(forms.ModelForm):
|
||||||
"""Form for updating the portfolio senior official."""
|
"""
|
||||||
|
Form for updating the portfolio senior official.
|
||||||
|
This form is readonly for now.
|
||||||
|
"""
|
||||||
|
|
||||||
JOIN = "senior_official"
|
JOIN = "senior_official"
|
||||||
|
full_name = forms.CharField(label="Full name", required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SeniorOfficial
|
model = SeniorOfficial
|
||||||
# TODO - add full name
|
|
||||||
fields = [
|
fields = [
|
||||||
"first_name",
|
"first_name",
|
||||||
"last_name",
|
"last_name",
|
||||||
"title",
|
"title",
|
||||||
"email",
|
"email",
|
||||||
]
|
]
|
||||||
|
|
||||||
# error_messages = {
|
|
||||||
# "address_line1": {"required": "Enter the street address of your organization."},
|
|
||||||
# "city": {"required": "Enter the city where your organization is located."},
|
|
||||||
# "state_territory": {
|
|
||||||
# "required": "Select the state, territory, or military post where your organization is located."
|
|
||||||
# },
|
|
||||||
# }
|
|
||||||
widgets = {
|
widgets = {
|
||||||
# We need to set the required attributed for State/territory
|
# We need to set the required attributed for State/territory
|
||||||
# because for this fields we are creating an individual
|
# because for this fields we are creating an individual
|
||||||
|
@ -100,14 +95,17 @@ class PortfolioSeniorOfficialForm(forms.ModelForm):
|
||||||
"last_name": forms.TextInput,
|
"last_name": forms.TextInput,
|
||||||
"title": forms.TextInput,
|
"title": forms.TextInput,
|
||||||
"email": forms.TextInput,
|
"email": forms.TextInput,
|
||||||
|
"full_name": forms.TextInput(attrs={"readonly": "readonly"})
|
||||||
}
|
}
|
||||||
|
|
||||||
# the database fields have blank=True so ModelForm doesn't create
|
# the database fields have blank=True so ModelForm doesn't create
|
||||||
# required fields by default. Use this list in __init__ to mark each
|
# required fields by default. Use this list in __init__ to mark each
|
||||||
# of these fields as required
|
# of these fields as required
|
||||||
required = ["first_name", "last_name", "title", "email"]
|
required = ["first_name", "last_name", "title", "email"]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
for field_name in self.required:
|
for field_name in self.required:
|
||||||
self.fields[field_name].required = True
|
self.fields[field_name].required = True
|
||||||
|
|
||||||
|
if self.instance:
|
||||||
|
self.fields["full_name"].initial = self.instance.get_formatted_name()
|
||||||
|
|
|
@ -23,9 +23,7 @@
|
||||||
|
|
||||||
<p>Your senior official is a person within your organization who can authorize domain requests.</p>
|
<p>Your senior official is a person within your organization who can authorize domain requests.</p>
|
||||||
|
|
||||||
<p>The senior official for your organization can’t be updated here. To suggest an update, email <a href="mailto:help@get.gov" class="usa-link">help@get.gov</a></p>
|
{% if santa_exists %}
|
||||||
|
|
||||||
{% if has_edit_org_portfolio_permission %}
|
|
||||||
{% include "includes/form_errors.html" with form=form %}
|
{% include "includes/form_errors.html" with form=form %}
|
||||||
{% include "includes/required_fields.html" %}
|
{% include "includes/required_fields.html" %}
|
||||||
<form class="usa-form usa-form--large" method="post" novalidate>
|
<form class="usa-form usa-form--large" method="post" novalidate>
|
||||||
|
@ -39,15 +37,20 @@
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<h4 class="read-only-label">Full name</h4>
|
<p>The senior official for your organization can’t be updated here. To suggest an update, email <a href="mailto:help@get.gov" class="usa-link">help@get.gov</a></p>
|
||||||
<p class="read-only-value">
|
|
||||||
{{ portfolio.senior_official.get_formatted_name }}
|
{% if not senior_official %}
|
||||||
</p>
|
<h4>No senior official was found for this portfolio.</h4>
|
||||||
{% if form.city.value is not None %}
|
{% else %}
|
||||||
{% include "includes/input_read_only.html" with field=form.title %}
|
{% if form.full_name.value is not None %}
|
||||||
{% endif %}
|
{% include "includes/input_read_only.html" with field=form.full_name %}
|
||||||
{% if form.state_territory.value is not None %}
|
{% endif %}
|
||||||
{% include "includes/input_read_only.html" with field=form.email %}
|
{% if form.title.value is not None %}
|
||||||
|
{% include "includes/input_read_only.html" with field=form.title %}
|
||||||
|
{% endif %}
|
||||||
|
{% if form.email.value is not None %}
|
||||||
|
{% include "includes/input_read_only.html" with field=form.email %}
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class PortfolioOrganizationView(PortfolioBasePermissionView, FormMixin):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""Add additional context data to the template."""
|
"""Add additional context data to the template."""
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["has_edit_org_portfolio_permission"] = self.request.user.has_edit_org_portfolio_permission()
|
# context["has_edit_org_portfolio_permission"]
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
|
@ -109,7 +109,7 @@ class PortfolioSeniorOfficialView(PortfolioBasePermissionView, FormMixin):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""Add additional context data to the template."""
|
"""Add additional context data to the template."""
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["has_edit_org_portfolio_permission"] = self.request.user.has_edit_org_portfolio_permission()
|
context["senior_official"] = self.get_object().senior_official
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
|
@ -131,6 +131,8 @@ class PortfolioSeniorOfficialView(PortfolioBasePermissionView, FormMixin):
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
return self.render_to_response(self.get_context_data(form=form))
|
return self.render_to_response(self.get_context_data(form=form))
|
||||||
|
|
||||||
|
# These functions are included for future compatibility, but for now
|
||||||
|
# we do not offer an edit mode for senior officials.
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
"""Handle POST requests to process form submission."""
|
"""Handle POST requests to process form submission."""
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
@ -155,4 +157,4 @@ class PortfolioSeniorOfficialView(PortfolioBasePermissionView, FormMixin):
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
"""Redirect to the overview page for the portfolio."""
|
"""Redirect to the overview page for the portfolio."""
|
||||||
return reverse("senior-official")
|
return reverse("senior-official")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue