mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-15 05:54:11 +02:00
Vie, Form, Template for Contact Info
This commit is contained in:
parent
23672f4265
commit
659941368a
8 changed files with 148 additions and 7 deletions
|
@ -1,2 +1,2 @@
|
||||||
from .application_wizard import *
|
from .application_wizard import *
|
||||||
from .domain import DomainAddUserForm, NameserverFormset, DomainSecurityEmailForm
|
from .domain import DomainAddUserForm, NameserverFormset, DomainSecurityEmailForm, ContactForm
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
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):
|
||||||
|
|
||||||
|
@ -29,3 +33,42 @@ class DomainSecurityEmailForm(forms.Form):
|
||||||
"""Form for adding or editing a security email to a domain."""
|
"""Form for adding or editing a security email to a domain."""
|
||||||
|
|
||||||
security_email = forms.EmailField(label="Security email")
|
security_email = forms.EmailField(label="Security email")
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="usa-sidenav__item">
|
<li class="usa-sidenav__item">
|
||||||
{% url 'todo' as url %}
|
{% url 'domain-your-contact-information' 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 %}
|
||||||
>
|
>
|
||||||
|
|
35
src/registrar/templates/domain_your_contact_information.html
Normal file
35
src/registrar/templates/domain_your_contact_information.html
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{% extends "domain_base.html" %}
|
||||||
|
{% load static field_helpers %}
|
||||||
|
|
||||||
|
{% block title %}Domain contact information | {{ domain.name }} | {% endblock %}
|
||||||
|
|
||||||
|
{% block domain_content %}
|
||||||
|
|
||||||
|
<h1>Domain contact information</h1>
|
||||||
|
|
||||||
|
<p>If you’d like us to use a different name, email, or phone number you can make those changes below. Changing your contact information here won’t affect your Login.gov account information.</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 #}
|
|
@ -2,6 +2,7 @@ from .application import *
|
||||||
from .domain import (
|
from .domain import (
|
||||||
DomainView,
|
DomainView,
|
||||||
DomainNameserversView,
|
DomainNameserversView,
|
||||||
|
DomainYourContactInformationView,
|
||||||
DomainSecurityEmailView,
|
DomainSecurityEmailView,
|
||||||
DomainUsersView,
|
DomainUsersView,
|
||||||
DomainAddUserView,
|
DomainAddUserView,
|
||||||
|
|
|
@ -10,9 +10,9 @@ from django.urls import reverse
|
||||||
from django.views.generic import DetailView
|
from django.views.generic import DetailView
|
||||||
from django.views.generic.edit import DeleteView, FormMixin
|
from django.views.generic.edit import DeleteView, FormMixin
|
||||||
|
|
||||||
from registrar.models import Domain, DomainInvitation, User, UserDomainRole
|
from registrar.models import Domain, DomainInvitation, User, UserDomainRole, DomainInformation
|
||||||
|
|
||||||
from ..forms import DomainAddUserForm, NameserverFormset, DomainSecurityEmailForm
|
from ..forms import DomainAddUserForm, NameserverFormset, DomainSecurityEmailForm, 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
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class DomainNameserversView(DomainPermission, FormMixin, DetailView):
|
||||||
return [{"server": server} for server in domain.nameservers()]
|
return [{"server": server} for server in domain.nameservers()]
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
"""Redirect to the overview page for the domain."""
|
"""Redirect to the nameservers page for the domain."""
|
||||||
return reverse("domain-nameservers", kwargs={"pk": self.object.pk})
|
return reverse("domain-nameservers", kwargs={"pk": self.object.pk})
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
@ -96,6 +96,64 @@ class DomainNameserversView(DomainPermission, FormMixin, DetailView):
|
||||||
return super().form_valid(formset)
|
return super().form_valid(formset)
|
||||||
|
|
||||||
|
|
||||||
|
class DomainYourContactInformationView(DomainPermission, FormMixin, DetailView):
|
||||||
|
|
||||||
|
"""Domain your contact information editing view."""
|
||||||
|
|
||||||
|
model = Domain
|
||||||
|
template_name = "domain_your_contact_information.html"
|
||||||
|
context_object_name = "domain"
|
||||||
|
form_class = ContactForm
|
||||||
|
|
||||||
|
# def get_initial(self):
|
||||||
|
# """The initial value for the form."""
|
||||||
|
# domainInformation = self.get_object()
|
||||||
|
# initial = super().get_initial()
|
||||||
|
# initial["first_name"] = domainInformation.submitter.first_name
|
||||||
|
# initial["middle_name"] = domainInformation.submitter.middle_name
|
||||||
|
# initial["last_name"] = domainInformation.submitter.last_name
|
||||||
|
# initial["title"] = domainInformation.submitter.title
|
||||||
|
# initial["email"] = domainInformation.submitter.email
|
||||||
|
# initial["phone"] = domainInformation.submitter.phone
|
||||||
|
# return initial
|
||||||
|
|
||||||
|
def get_form_kwargs(self, *args, **kwargs):
|
||||||
|
"""Add domain_info.submitter instance to make a bound form."""
|
||||||
|
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
||||||
|
form_kwargs["instance"] = self.get_object().domain_info.submitter
|
||||||
|
return form_kwargs
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
"""Redirect to the your contact information for the domain."""
|
||||||
|
return reverse("domain-your-contact-information", kwargs={"pk": self.object.pk})
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
"""Form submission posts to this view."""
|
||||||
|
self.object = self.get_object()
|
||||||
|
form = self.get_form()
|
||||||
|
if form.is_valid():
|
||||||
|
# there is a valid email address in the form
|
||||||
|
return self.form_valid(form)
|
||||||
|
else:
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
"""The form is valid, call setter in model."""
|
||||||
|
|
||||||
|
# Post to DB using values from the form
|
||||||
|
# new_email = form.cleaned_data["security_email"]
|
||||||
|
# domain = self.get_object()
|
||||||
|
# domain.set_security_email(new_email)
|
||||||
|
domain = self.get_object()
|
||||||
|
form.save()
|
||||||
|
|
||||||
|
messages.success(
|
||||||
|
self.request, "Your contact information for this domain have been updated."
|
||||||
|
)
|
||||||
|
# superclass has the redirect
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class DomainSecurityEmailView(DomainPermission, FormMixin, DetailView):
|
class DomainSecurityEmailView(DomainPermission, FormMixin, DetailView):
|
||||||
|
|
||||||
"""Domain security email editing view."""
|
"""Domain security email editing view."""
|
||||||
|
@ -113,11 +171,11 @@ class DomainSecurityEmailView(DomainPermission, FormMixin, DetailView):
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
"""Redirect to the overview page for the domain."""
|
"""Redirect to the security email page for the domain."""
|
||||||
return reverse("domain-security-email", kwargs={"pk": self.object.pk})
|
return reverse("domain-security-email", kwargs={"pk": self.object.pk})
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
"""Formset submission posts to this view."""
|
"""Form submission posts to this view."""
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
10038 OUTOFSCOPE http://app:8080/users
|
10038 OUTOFSCOPE http://app:8080/users
|
||||||
10038 OUTOFSCOPE http://app:8080/users/add
|
10038 OUTOFSCOPE http://app:8080/users/add
|
||||||
10038 OUTOFSCOPE http://app:8080/nameservers
|
10038 OUTOFSCOPE http://app:8080/nameservers
|
||||||
|
10038 OUTOFSCOPE http://app:8080/your-contact-information
|
||||||
10038 OUTOFSCOPE http://app:8080/security-email
|
10038 OUTOFSCOPE http://app:8080/security-email
|
||||||
10038 OUTOFSCOPE http://app:8080/delete
|
10038 OUTOFSCOPE http://app:8080/delete
|
||||||
10038 OUTOFSCOPE http://app:8080/withdraw
|
10038 OUTOFSCOPE http://app:8080/withdraw
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue