initial work for migrating domainrequest model

This commit is contained in:
Matthew Spence 2024-08-16 10:03:40 -05:00
parent 2ebeb148fb
commit 50d1abf253
No known key found for this signature in database
2 changed files with 49 additions and 5 deletions

View file

@ -0,0 +1,21 @@
import logging
from django.core.management import BaseCommand
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors
from registrar.models import DomainRequest
logger = logging.getLogger(__name__)
class Command(BaseCommand, PopulateScriptTemplate):
help = "Loops through each valid domain request object and populates the last_status_update and first_submitted_date"
def handle(self, **kwargs):
"""Loops through each valid DomainRequest object and populates its last_status_update and first_submitted_date values"""
self.mass_update_records(DomainRequest, ["last_status_update", "last_submitted_date"])
def update_record(self, record: DomainRequest):
"""Defines how we update the first_submitted_date and last_status_update fields"""
record.set_dates()
logger.info(
f"{TerminalColors.OKCYAN}Updating {record} => first submitted date: " f"{record.first_submitted_date}{TerminalColors.OKCYAN}, last status update:" f"{record.last_status_update}{TerminalColors.OKCYAN}"
)

View file

@ -563,15 +563,32 @@ class DomainRequest(TimeStampedModel):
help_text="Acknowledged .gov acceptable use policy",
)
# submission date records when domain request is submitted
submission_date = models.DateField(
# initial submission date records when domain request was first submitted
first_submitted_date = models.DateField(
null=True,
blank=True,
default=None,
verbose_name="submitted at",
help_text="Date submitted",
help_text="Date initially submitted",
)
# last submission date records when domain request was last submitted
last_submitted_date = models.DateField(
null=True,
blank=True,
default=None,
verbose_name="submitted at",
help_text="Date last submitted",
)
# last status update records when domain request status was last updated by an admin or analyst
last_status_update = models.DateField(
null=True,
blank=True,
default=None,
verbose_name="last updated at",
help_text="Date of last status updated",
)
notes = models.TextField(
null=True,
blank=True,
@ -621,6 +638,9 @@ class DomainRequest(TimeStampedModel):
self.sync_organization_type()
self.sync_yes_no_form_fields()
if self._cached_status != self.status:
self.last_status_update = timezone.now().date()
super().save(*args, **kwargs)
# Handle the action needed email.
@ -797,8 +817,11 @@ class DomainRequest(TimeStampedModel):
if not DraftDomain.string_could_be_domain(self.requested_domain.name):
raise ValueError("Requested domain is not a valid domain name.")
# Update submission_date to today
self.submission_date = timezone.now().date()
if not self.first_submitted_date:
self.first_submitted_date = timezone.now().date()
# Update last_submission_date to today
self.last_submitted_date = timezone.now().date()
self.save()
# Limit email notifications to transitions from Started and Withdrawn