mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
added debugging; removed duplicate get_object calls from views
This commit is contained in:
parent
1f97806255
commit
8e700e0ecb
2 changed files with 39 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
import logging
|
import logging
|
||||||
|
import inspect
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from string import digits
|
from string import digits
|
||||||
from django_fsm import FSMField, transition, TransitionNotAllowed # type: ignore
|
from django_fsm import FSMField, transition, TransitionNotAllowed # type: ignore
|
||||||
|
@ -50,8 +51,33 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
|
#self.print_calling_function()
|
||||||
|
logger.info("__init__ being called on domain")
|
||||||
super(Domain, self).__init__(*args, **kwargs)
|
super(Domain, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def print_calling_function(self):
|
||||||
|
# Get the current frame in the call stack
|
||||||
|
current_frame = inspect.currentframe()
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
# Get the calling frame
|
||||||
|
calling_frame = inspect.getouterframes(current_frame, 2)[i]
|
||||||
|
|
||||||
|
# Extract information about the calling function
|
||||||
|
calling_function_name = calling_frame.function
|
||||||
|
calling_module_name = calling_frame[0].f_globals['__name__']
|
||||||
|
calling_line_number = calling_frame[2]
|
||||||
|
|
||||||
|
# Print information about the calling function
|
||||||
|
print(f"Calling function: {calling_function_name} in module {calling_module_name} at line {calling_line_number}")
|
||||||
|
|
||||||
|
i+=1
|
||||||
|
except Exception as err:
|
||||||
|
print("========================================================")
|
||||||
|
break
|
||||||
|
|
||||||
class Status(models.TextChoices):
|
class Status(models.TextChoices):
|
||||||
"""
|
"""
|
||||||
The status codes we can receive from the registry.
|
The status codes we can receive from the registry.
|
||||||
|
@ -144,10 +170,12 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
|
|
||||||
def __get__(self, obj, objtype=None):
|
def __get__(self, obj, objtype=None):
|
||||||
"""Called during get. Example: `r = domain.registrant`."""
|
"""Called during get. Example: `r = domain.registrant`."""
|
||||||
|
logger.info("domain __get__ is called: %s", obj)
|
||||||
return super().__get__(obj, objtype)
|
return super().__get__(obj, objtype)
|
||||||
|
|
||||||
def __set__(self, obj, value):
|
def __set__(self, obj, value):
|
||||||
"""Called during set. Example: `domain.registrant = 'abc123'`."""
|
"""Called during set. Example: `domain.registrant = 'abc123'`."""
|
||||||
|
logger.info("domain __set__ is called: %s", obj)
|
||||||
super().__set__(obj, value)
|
super().__set__(obj, value)
|
||||||
# always invalidate cache after sending updates to the registry
|
# always invalidate cache after sending updates to the registry
|
||||||
obj._invalidate_cache()
|
obj._invalidate_cache()
|
||||||
|
@ -1223,6 +1251,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def _fetch_cache(self, fetch_hosts=False, fetch_contacts=False):
|
def _fetch_cache(self, fetch_hosts=False, fetch_contacts=False):
|
||||||
|
logger.info("fetch_cache called")
|
||||||
"""Contact registry for info about a domain."""
|
"""Contact registry for info about a domain."""
|
||||||
try:
|
try:
|
||||||
# get info from registry
|
# get info from registry
|
||||||
|
@ -1354,6 +1383,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
|
|
||||||
def _invalidate_cache(self):
|
def _invalidate_cache(self):
|
||||||
"""Remove cache data when updates are made."""
|
"""Remove cache data when updates are made."""
|
||||||
|
logger.debug("_invalidate_cache called")
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
|
|
||||||
def _get_property(self, property):
|
def _get_property(self, property):
|
||||||
|
|
|
@ -54,7 +54,7 @@ class DomainOrgNameAddressView(DomainPermissionView, FormMixin):
|
||||||
def get_form_kwargs(self, *args, **kwargs):
|
def get_form_kwargs(self, *args, **kwargs):
|
||||||
"""Add domain_info.organization_name instance to make a bound form."""
|
"""Add domain_info.organization_name instance to make a bound form."""
|
||||||
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
||||||
form_kwargs["instance"] = self.get_object().domain_info
|
form_kwargs["instance"] = self.object.domain_info
|
||||||
return form_kwargs
|
return form_kwargs
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -97,7 +97,7 @@ class DomainAuthorizingOfficialView(DomainPermissionView, FormMixin):
|
||||||
def get_form_kwargs(self, *args, **kwargs):
|
def get_form_kwargs(self, *args, **kwargs):
|
||||||
"""Add domain_info.authorizing_official instance to make a bound form."""
|
"""Add domain_info.authorizing_official instance to make a bound form."""
|
||||||
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
||||||
form_kwargs["instance"] = self.get_object().domain_info.authorizing_official
|
form_kwargs["instance"] = self.object.domain_info.authorizing_official
|
||||||
return form_kwargs
|
return form_kwargs
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -137,8 +137,11 @@ class DomainNameserversView(DomainPermissionView, FormMixin):
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
"""The initial value for the form (which is a formset here)."""
|
"""The initial value for the form (which is a formset here)."""
|
||||||
domain = self.get_object()
|
logger.info("DomainNameserversView.get_initial()")
|
||||||
|
domain = self.object
|
||||||
|
logger.info("DomainNameserversView.get_initial:: after get_object")
|
||||||
nameservers = domain.nameservers
|
nameservers = domain.nameservers
|
||||||
|
logger.info("DomainNameserversView.get_initial:: after set nameservers")
|
||||||
initial_data = []
|
initial_data = []
|
||||||
|
|
||||||
if nameservers is not None:
|
if nameservers is not None:
|
||||||
|
@ -196,7 +199,7 @@ class DomainNameserversView(DomainPermissionView, FormMixin):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# no server information in this field, skip it
|
# no server information in this field, skip it
|
||||||
pass
|
pass
|
||||||
domain = self.get_object()
|
domain = self.object
|
||||||
domain.nameservers = nameservers
|
domain.nameservers = nameservers
|
||||||
|
|
||||||
messages.success(
|
messages.success(
|
||||||
|
@ -257,7 +260,7 @@ class DomainSecurityEmailView(DomainPermissionView, FormMixin):
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
"""The initial value for the form."""
|
"""The initial value for the form."""
|
||||||
domain = self.get_object()
|
domain = self.object
|
||||||
initial = super().get_initial()
|
initial = super().get_initial()
|
||||||
security_contact = domain.security_contact
|
security_contact = domain.security_contact
|
||||||
if security_contact is None or security_contact.email == "dotgov@cisa.dhs.gov":
|
if security_contact is None or security_contact.email == "dotgov@cisa.dhs.gov":
|
||||||
|
@ -286,7 +289,7 @@ class DomainSecurityEmailView(DomainPermissionView, FormMixin):
|
||||||
# Set the security email from the form
|
# Set the security email from the form
|
||||||
new_email = form.cleaned_data.get("security_email", "")
|
new_email = form.cleaned_data.get("security_email", "")
|
||||||
|
|
||||||
domain = self.get_object()
|
domain = self.object
|
||||||
contact = domain.security_contact
|
contact = domain.security_contact
|
||||||
contact.email = new_email
|
contact.email = new_email
|
||||||
contact.save()
|
contact.save()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue