mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 13:09:41 +02:00
Form to edit a domain's authorizing official
This commit is contained in:
parent
a3606d6497
commit
e277c3a64c
8 changed files with 138 additions and 3 deletions
|
@ -83,6 +83,11 @@ urlpatterns = [
|
||||||
views.DomainNameserversView.as_view(),
|
views.DomainNameserversView.as_view(),
|
||||||
name="domain-nameservers",
|
name="domain-nameservers",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"domain/<int:pk>/authorizing-official",
|
||||||
|
views.DomainAuthorizingOfficialView.as_view(),
|
||||||
|
name="domain-authorizing-official",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"domain/<int:pk>/users/add",
|
"domain/<int:pk>/users/add",
|
||||||
views.DomainAddUserView.as_view(),
|
views.DomainAddUserView.as_view(),
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
from .application_wizard import *
|
from .application_wizard import *
|
||||||
from .domain import DomainAddUserForm, NameserverFormset
|
from .domain import DomainAddUserForm, NameserverFormset, ContactForm
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms import formset_factory
|
from django.forms import formset_factory
|
||||||
|
|
||||||
|
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||||
|
|
||||||
|
from ..models import Contact
|
||||||
|
|
||||||
class DomainAddUserForm(forms.Form):
|
class DomainAddUserForm(forms.Form):
|
||||||
|
|
||||||
|
@ -22,3 +25,40 @@ NameserverFormset = formset_factory(
|
||||||
DomainNameserverForm,
|
DomainNameserverForm,
|
||||||
extra=1,
|
extra=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ContactForm(forms.ModelForm):
|
||||||
|
|
||||||
|
"""Form for updating contacts."""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Contact
|
||||||
|
fields = ["first_name", "middle_name", "last_name", "title", "email", "phone"]
|
||||||
|
widgets = {
|
||||||
|
"first_name": forms.TextInput,
|
||||||
|
"middle_name": forms.TextInput,
|
||||||
|
"last_name": forms.TextInput,
|
||||||
|
"title": forms.TextInput,
|
||||||
|
"email": forms.EmailInput,
|
||||||
|
"phone": RegionalPhoneNumberWidget,
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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 = [
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"title",
|
||||||
|
"email",
|
||||||
|
"phone"
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
# take off maxlength attribute for the phone number field
|
||||||
|
# which interferes with out input_with_errors template tag
|
||||||
|
self.fields['phone'].widget.attrs.pop('maxlength', None)
|
||||||
|
|
||||||
|
for field_name in self.required:
|
||||||
|
self.fields[field_name].required = True
|
||||||
|
|
|
@ -20,6 +20,7 @@ class Contact(TimeStampedModel):
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text="First name",
|
help_text="First name",
|
||||||
|
verbose_name="first name / given name",
|
||||||
db_index=True,
|
db_index=True,
|
||||||
)
|
)
|
||||||
middle_name = models.TextField(
|
middle_name = models.TextField(
|
||||||
|
@ -31,12 +32,14 @@ class Contact(TimeStampedModel):
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text="Last name",
|
help_text="Last name",
|
||||||
|
verbose_name="last name / family name",
|
||||||
db_index=True,
|
db_index=True,
|
||||||
)
|
)
|
||||||
title = models.TextField(
|
title = models.TextField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text="Title",
|
help_text="Title",
|
||||||
|
verbose_name="title or role in your organization",
|
||||||
)
|
)
|
||||||
email = models.TextField(
|
email = models.TextField(
|
||||||
null=True,
|
null=True,
|
||||||
|
|
43
src/registrar/templates/domain_authorizing_official.html
Normal file
43
src/registrar/templates/domain_authorizing_official.html
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{% extends "domain_base.html" %}
|
||||||
|
{% load static field_helpers%}
|
||||||
|
|
||||||
|
{% block title %}Domain authorizing official | {{ domain.name }} | {% endblock %}
|
||||||
|
|
||||||
|
{% block domain_content %}
|
||||||
|
{# this is right after the messages block in the parent template #}
|
||||||
|
{% include "includes/form_errors.html" with form=form %}
|
||||||
|
|
||||||
|
<h1>Authorizing official</h1>
|
||||||
|
|
||||||
|
<p>Your authorizing official is the person within your organization who can
|
||||||
|
authorize domain requests. This is generally the highest-ranking or
|
||||||
|
highest-elected official in your organization. <a class="usa-link"
|
||||||
|
href="https://federalist-877ab29f-16f6-4f12-961c-96cf064cf070.sites.pages.cloud.gov/site/cisagov/getgov-home/domains/eligibility/#you-must-have-approval-from-an-authorizing-official-within-your-organization">Read more about who can serve
|
||||||
|
as an authorizing official.</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.first_name %}
|
||||||
|
|
||||||
|
{% input_with_errors form.middle_name %}
|
||||||
|
|
||||||
|
{% input_with_errors form.last_name %}
|
||||||
|
|
||||||
|
{% input_with_errors form.title %}
|
||||||
|
|
||||||
|
{% input_with_errors form.email %}
|
||||||
|
|
||||||
|
{% input_with_errors form.phone %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="usa-button"
|
||||||
|
>Save</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %} {# domain_content #}
|
|
@ -31,7 +31,7 @@
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="usa-sidenav__item">
|
<li class="usa-sidenav__item">
|
||||||
{% url 'todo' as url %}
|
{% url 'domain-authorizing-official' pk=domain.id as url %}
|
||||||
<a href="{{ url }}"
|
<a href="{{ url }}"
|
||||||
{% if request.path == url %}class="usa-current"{% endif %}
|
{% if request.path == url %}class="usa-current"{% endif %}
|
||||||
>
|
>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from .application import *
|
from .application import *
|
||||||
from .domain import (
|
from .domain import (
|
||||||
DomainView,
|
DomainView,
|
||||||
|
DomainAuthorizingOfficialView,
|
||||||
DomainNameserversView,
|
DomainNameserversView,
|
||||||
DomainUsersView,
|
DomainUsersView,
|
||||||
DomainAddUserView,
|
DomainAddUserView,
|
||||||
|
|
|
@ -12,7 +12,7 @@ from django.views.generic.edit import DeleteView, FormMixin
|
||||||
|
|
||||||
from registrar.models import Domain, DomainInvitation, User, UserDomainRole
|
from registrar.models import Domain, DomainInvitation, User, UserDomainRole
|
||||||
|
|
||||||
from ..forms import DomainAddUserForm, NameserverFormset
|
from ..forms import DomainAddUserForm, NameserverFormset, ContactForm
|
||||||
from ..utility.email import send_templated_email, EmailSendingError
|
from ..utility.email import send_templated_email, EmailSendingError
|
||||||
from .utility import DomainPermission
|
from .utility import DomainPermission
|
||||||
|
|
||||||
|
@ -29,6 +29,49 @@ class DomainView(DomainPermission, DetailView):
|
||||||
context_object_name = "domain"
|
context_object_name = "domain"
|
||||||
|
|
||||||
|
|
||||||
|
class DomainAuthorizingOfficialView(DomainPermission, FormMixin, DetailView):
|
||||||
|
|
||||||
|
"""Domain authorizing official editing view."""
|
||||||
|
|
||||||
|
model = Domain
|
||||||
|
template_name = "domain_authorizing_official.html"
|
||||||
|
context_object_name = "domain"
|
||||||
|
form_class = ContactForm
|
||||||
|
|
||||||
|
def get_form_kwargs(self, *args, **kwargs):
|
||||||
|
"""Add domain_info.authorizing_official instance to make a bound form."""
|
||||||
|
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
||||||
|
form_kwargs["instance"] = self.get_object().domain_info.authorizing_official
|
||||||
|
return form_kwargs
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
"""Redirect to the overview page for the domain."""
|
||||||
|
return reverse("domain-authorizing-official", kwargs={"pk": self.object.pk})
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
"""Form submission posts to this view.
|
||||||
|
|
||||||
|
This post method harmonizes using DetailView and FormMixin together.
|
||||||
|
"""
|
||||||
|
self.object = self.get_object()
|
||||||
|
form = self.get_form()
|
||||||
|
if form.is_valid():
|
||||||
|
return self.form_valid(form)
|
||||||
|
else:
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
"""The form is valid, save the authorizing official."""
|
||||||
|
domain = self.get_object()
|
||||||
|
form.save()
|
||||||
|
|
||||||
|
messages.success(
|
||||||
|
self.request, "The authorizing official for this domain has been updated."
|
||||||
|
)
|
||||||
|
# superclass has the redirect
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class DomainNameserversView(DomainPermission, FormMixin, DetailView):
|
class DomainNameserversView(DomainPermission, FormMixin, DetailView):
|
||||||
|
|
||||||
"""Domain nameserver editing view."""
|
"""Domain nameserver editing view."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue