Basic view

This commit is contained in:
zandercymatics 2024-07-22 09:57:07 -06:00
parent cfd6248fc3
commit 2c9916b214
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
7 changed files with 110 additions and 10 deletions

View file

@ -182,6 +182,11 @@ urlpatterns = [
views.DomainOrgNameAddressView.as_view(),
name="domain-org-name-address",
),
path(
"domain/<int:pk>/suborganization",
views.DomainSubOrganizationView.as_view(),
name="domain-suborganization",
),
path(
"domain/<int:pk>/senior-official",
views.DomainSeniorOfficialView.as_view(),

View file

@ -16,7 +16,7 @@ from registrar.utility.errors import (
SecurityEmailErrorCodes,
)
from ..models import Contact, DomainInformation, Domain, User
from ..models import Contact, DomainInformation, Domain, User, Suborganization
from .common import (
ALGORITHM_CHOICES,
DIGEST_TYPE_CHOICES,
@ -508,6 +508,41 @@ class DomainOrgNameAddressForm(forms.ModelForm):
return old_value == new_value
class DomainSuborganizationForm(forms.ModelForm):
"""Form for updating the suborganization"""
class Meta:
model = DomainInformation
fields = [
"sub_organization",
]
error_messages = {
"sub_organization": {"required": "Select a suborganization."},
}
widgets = {
"sub_organization": forms.Select(
attrs={
"required": False,
},
),
}
# the database fields have blank=True so ModelForm doesn't create
# required fields by default. Use this list in __init__ to mark each
# of these fields as required
required = ["sub_organization"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["sub_organization"].required = False
if self.instance and self.instance.portfolio:
self.fields['sub_organization'].queryset = Suborganization.objects.filter(
portfolio=self.instance.portfolio
)
else:
self.fields['sub_organization'].queryset = Suborganization.objects.none()
class DomainDnssecForm(forms.Form):
"""Form for enabling and disabling dnssec"""

View file

@ -54,15 +54,12 @@
</ul>
{% endif %}
</li>
<li class="usa-sidenav__item">
{% url 'domain-org-name-address' pk=domain.id as url %}
<a href="{{ url }}"
{% if request.path == url %}class="usa-current"{% endif %}
>
Organization name and mailing address
</a>
</li>
{% if is_org_user %}
{% include "includes/domain_sidenav_item.html" with url_name="domain-suborganization" item_text="Suborganization"%}
{% else %}
{% include "includes/domain_sidenav_item.html" with url_name="domain-org-name-address" item_text="Organization name and mailing address"%}
{% endif %}
<li class="usa-sidenav__item">
{% url 'domain-senior-official' pk=domain.id as url %}

View file

@ -0,0 +1,25 @@
{% extends "domain_base.html" %}
{% load static field_helpers%}
{% block title %}Suborganization{% endblock %}
{% block domain_content %}
{# this is right after the messages block in the parent template #}
{% include "includes/form_errors.html" with form=form %}
<h1>Organization name and mailing address </h1>
<p>
The name of your suborganization will be publicly listed as the domain registrant.
This list of suborganizations has been populated the .gov program.
If you believe there is an error please contact <a href="mailto:help@get.gov" class="usa-link">help@get.gov</a>.
</p>
{% include "includes/required_fields.html" %}
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
{% csrf_token %}
{% input_with_errors form.sub_organization %}
<button type="submit" class="usa-button">Save</button>
</form>
{% endblock %}

View file

@ -0,0 +1,8 @@
<li class="usa-sidenav__item">
{% url url_name pk=domain.id as url %}
<a href="{{ url }}"
{% if request.path == url %}class="usa-current"{% endif %}
>
{{ item_text }}
</a>
</li>

View file

@ -3,6 +3,7 @@ from .domain import (
DomainView,
DomainSeniorOfficialView,
DomainOrgNameAddressView,
DomainSubOrganizationView,
DomainDNSView,
DomainNameserversView,
DomainDNSSECView,

View file

@ -16,6 +16,7 @@ from django.urls import reverse
from django.views.generic.edit import FormMixin
from django.conf import settings
from registrar.forms.domain import DomainSuborganizationForm
from registrar.models import (
Domain,
DomainRequest,
@ -221,6 +222,34 @@ class DomainOrgNameAddressView(DomainFormBaseView):
return super().form_valid(form)
class DomainSubOrganizationView(DomainFormBaseView):
"""Suborganization view"""
model = Domain
template_name = "domain_suborganization.html"
context_object_name = "domain"
form_class = DomainSuborganizationForm
def get_form_kwargs(self, *args, **kwargs):
"""Add domain_info.organization_name instance to make a bound form."""
form_kwargs = super().get_form_kwargs(*args, **kwargs)
form_kwargs["instance"] = self.object.domain_info
return form_kwargs
def get_success_url(self):
"""Redirect to the overview page for the domain."""
return reverse("domain-suborganization", kwargs={"pk": self.object.pk})
def form_valid(self, form):
"""The form is valid, save the organization name and mailing address."""
form.save()
messages.success(self.request, "The suborganization name for this domain has been updated.")
# superclass has the redirect
return super().form_valid(form)
class DomainSeniorOfficialView(DomainFormBaseView):
"""Domain senior official editing view."""