updated comments in code for readability; cleaned up debugging messages

This commit is contained in:
David Kennedy 2024-01-16 17:06:20 -05:00
parent adea22fe9f
commit b568104194
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 12 additions and 13 deletions

View file

@ -1,7 +1,5 @@
"""Forms for domain management."""
import logging
from django import forms
from django.core.validators import MinValueValidator, MaxValueValidator, RegexValidator
from django.forms import formset_factory
@ -24,8 +22,6 @@ from .common import (
import re
logger = logging.getLogger(__name__)
class DomainAddUserForm(forms.Form):
"""Form for adding a user to a domain."""
@ -239,21 +235,21 @@ class AuthorizingOfficialContactForm(ContactForm):
self.domainInfo = None
def setDomainInfo(self, domainInfo):
"""Set the domain information for the form.
The form instance is associated with the contact itself. In order to access the associated
domain information object, this needs to be set in the form by the view."""
self.domainInfo = domainInfo
def save(self, commit=True):
logger.info(f"in save: {self.instance}")
logger.info(f"{self.instance.__class__.__name__}")
logger.info(f"{self.instance.id}")
logger.info(f"self.fields => {self.fields}")
logger.info(f"domain info: {self.instance.information_authorizing_official}")
"""Override the save() method of the BaseModelForm."""
# get db object
# Get the Contact object from the db for the Authorizing Official
db_ao = Contact.objects.get(id=self.instance.id)
logger.info(f"db_ao.information_authorizing_official {db_ao.information_authorizing_official}")
if self.domainInfo and db_ao.has_more_than_one_join("information_authorizing_official"):
logger.info(f"domain info => {self.domainInfo}")
logger.info(f"authorizing official id => {self.domainInfo.authorizing_official.id}")
# Handle the case where the domain information object is available and the AO Contact
# has more than one joined object.
# In this case, create a new Contact, and update the new Contact with form data.
# Then associate with domain information object as the authorizing_official
contact = Contact()
for name, value in self.cleaned_data.items():
setattr(contact, name, value)

View file

@ -222,6 +222,9 @@ class DomainAuthorizingOfficialView(DomainFormBaseView):
def form_valid(self, form):
"""The form is valid, save the authorizing official."""
# Set the domain information in the form so that it can be accessible
# to associate a new Contact as authorizing official, if new Contact is needed
# in the save() method
form.setDomainInfo(self.object.domain_info)
form.save()