mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
initial work for migrating domainrequest model
This commit is contained in:
parent
2ebeb148fb
commit
50d1abf253
2 changed files with 49 additions and 5 deletions
|
@ -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}"
|
||||||
|
)
|
|
@ -563,15 +563,32 @@ class DomainRequest(TimeStampedModel):
|
||||||
help_text="Acknowledged .gov acceptable use policy",
|
help_text="Acknowledged .gov acceptable use policy",
|
||||||
)
|
)
|
||||||
|
|
||||||
# submission date records when domain request is submitted
|
# initial submission date records when domain request was first submitted
|
||||||
submission_date = models.DateField(
|
first_submitted_date = models.DateField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
default=None,
|
default=None,
|
||||||
verbose_name="submitted at",
|
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(
|
notes = models.TextField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
|
@ -621,6 +638,9 @@ class DomainRequest(TimeStampedModel):
|
||||||
self.sync_organization_type()
|
self.sync_organization_type()
|
||||||
self.sync_yes_no_form_fields()
|
self.sync_yes_no_form_fields()
|
||||||
|
|
||||||
|
if self._cached_status != self.status:
|
||||||
|
self.last_status_update = timezone.now().date()
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
# Handle the action needed email.
|
# Handle the action needed email.
|
||||||
|
@ -796,9 +816,12 @@ class DomainRequest(TimeStampedModel):
|
||||||
DraftDomain = apps.get_model("registrar.DraftDomain")
|
DraftDomain = apps.get_model("registrar.DraftDomain")
|
||||||
if not DraftDomain.string_could_be_domain(self.requested_domain.name):
|
if not DraftDomain.string_could_be_domain(self.requested_domain.name):
|
||||||
raise ValueError("Requested domain is not a valid domain name.")
|
raise ValueError("Requested domain is not a valid domain name.")
|
||||||
|
|
||||||
|
if not self.first_submitted_date:
|
||||||
|
self.first_submitted_date = timezone.now().date()
|
||||||
|
|
||||||
# Update submission_date to today
|
# Update last_submission_date to today
|
||||||
self.submission_date = timezone.now().date()
|
self.last_submitted_date = timezone.now().date()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
# Limit email notifications to transitions from Started and Withdrawn
|
# Limit email notifications to transitions from Started and Withdrawn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue