mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
First complete pass
This commit is contained in:
parent
50d1abf253
commit
f054cfa5cf
5 changed files with 78 additions and 11 deletions
|
@ -1649,7 +1649,9 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
# Columns
|
# Columns
|
||||||
list_display = [
|
list_display = [
|
||||||
"requested_domain",
|
"requested_domain",
|
||||||
"submission_date",
|
"first_submitted_date",
|
||||||
|
"last_submitted_date",
|
||||||
|
"last_status_update",
|
||||||
"status",
|
"status",
|
||||||
"generic_org_type",
|
"generic_org_type",
|
||||||
"federal_type",
|
"federal_type",
|
||||||
|
@ -1852,7 +1854,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
# Table ordering
|
# Table ordering
|
||||||
# NOTE: This impacts the select2 dropdowns (combobox)
|
# NOTE: This impacts the select2 dropdowns (combobox)
|
||||||
# Currentl, there's only one for requests on DomainInfo
|
# Currentl, there's only one for requests on DomainInfo
|
||||||
ordering = ["-submission_date", "requested_domain__name"]
|
ordering = ["-last_submitted_date", "requested_domain__name"]
|
||||||
|
|
||||||
change_form_template = "django/admin/domain_request_change_form.html"
|
change_form_template = "django/admin/domain_request_change_form.html"
|
||||||
|
|
||||||
|
|
|
@ -2,20 +2,41 @@ import logging
|
||||||
from django.core.management import BaseCommand
|
from django.core.management import BaseCommand
|
||||||
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors
|
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors
|
||||||
from registrar.models import DomainRequest
|
from registrar.models import DomainRequest
|
||||||
|
from auditlog.models import LogEntry
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand, PopulateScriptTemplate):
|
class Command(BaseCommand, PopulateScriptTemplate):
|
||||||
help = "Loops through each valid domain request object and populates the last_status_update and first_submitted_date"
|
help = "Loops through each domain request object and populates the last_status_update and first_submitted_date"
|
||||||
|
|
||||||
def handle(self, **kwargs):
|
def handle(self, **kwargs):
|
||||||
"""Loops through each valid DomainRequest object and populates its last_status_update and first_submitted_date values"""
|
"""Loops through each DomainRequest object and populates its last_status_update and first_submitted_date values"""
|
||||||
self.mass_update_records(DomainRequest, ["last_status_update", "last_submitted_date"])
|
self.mass_update_records(DomainRequest, None, ["last_status_update", "first_submitted_date"])
|
||||||
|
|
||||||
def update_record(self, record: DomainRequest):
|
def update_record(self, record: DomainRequest):
|
||||||
"""Defines how we update the first_submitted_date and last_status_update fields"""
|
"""Defines how we update the first_submitted_date and last_status_update fields"""
|
||||||
record.set_dates()
|
try:
|
||||||
|
# Retrieve and order audit log entries by timestamp in descending order
|
||||||
|
audit_log_entries = LogEntry.objects.filter(object_pk=record.pk).order_by("-timestamp")
|
||||||
|
|
||||||
|
# Loop through logs in descending order to find most recent status change
|
||||||
|
for log_entry in audit_log_entries:
|
||||||
|
if "status" in log_entry.changes:
|
||||||
|
record.last_status_update = log_entry.timestamp.date()
|
||||||
|
break
|
||||||
|
|
||||||
|
# Loop through logs in ascending order to find first submission
|
||||||
|
for log_entry in audit_log_entries.reverse():
|
||||||
|
if log_entry.changes_dict['status'](1) == 'Submitted':
|
||||||
|
record.first_submitted_date = log_entry.timestamp.date()
|
||||||
|
|
||||||
|
except ObjectDoesNotExist as e:
|
||||||
|
logger.error(f"Object with object_pk {record.pk} does not exist: {e}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"An error occurred during update_record: {e}")
|
||||||
|
|
||||||
logger.info(
|
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}"
|
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}"
|
||||||
)
|
)
|
||||||
|
|
|
@ -86,7 +86,7 @@ class PopulateScriptTemplate(ABC):
|
||||||
You must define update_record before you can use this function.
|
You must define update_record before you can use this function.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
records = object_class.objects.filter(**filter_conditions)
|
records = object_class.objects.filter(**filter_conditions) if filter_conditions else object_class.objects.all()
|
||||||
readable_class_name = self.get_class_name(object_class)
|
readable_class_name = self.get_class_name(object_class)
|
||||||
|
|
||||||
# Code execution will stop here if the user prompts "N"
|
# Code execution will stop here if the user prompts "N"
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Generated by Django 4.2.10 on 2024-08-16 15:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0117_alter_portfolioinvitation_portfolio_additional_permissions_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="domainrequest",
|
||||||
|
old_name="submission_date",
|
||||||
|
new_name="last_submitted_date",
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="domainrequest",
|
||||||
|
name="last_submitted_date",
|
||||||
|
field=models.DateField(
|
||||||
|
blank=True, default=None, help_text="Date last submitted", null=True, verbose_name="last submitted on"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="domainrequest",
|
||||||
|
name="first_submitted_date",
|
||||||
|
field=models.DateField(
|
||||||
|
blank=True, default=None, help_text="Date initially submitted", null=True, verbose_name="first submitted on"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="domainrequest",
|
||||||
|
name="last_status_update",
|
||||||
|
field=models.DateField(
|
||||||
|
blank=True,
|
||||||
|
default=None,
|
||||||
|
help_text="Date of last status updated",
|
||||||
|
null=True,
|
||||||
|
verbose_name="last updated on",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -568,7 +568,7 @@ class DomainRequest(TimeStampedModel):
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
default=None,
|
default=None,
|
||||||
verbose_name="submitted at",
|
verbose_name="first submitted on",
|
||||||
help_text="Date initially submitted",
|
help_text="Date initially submitted",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -577,7 +577,7 @@ class DomainRequest(TimeStampedModel):
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
default=None,
|
default=None,
|
||||||
verbose_name="submitted at",
|
verbose_name="last submitted on",
|
||||||
help_text="Date last submitted",
|
help_text="Date last submitted",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -586,7 +586,7 @@ class DomainRequest(TimeStampedModel):
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
default=None,
|
default=None,
|
||||||
verbose_name="last updated at",
|
verbose_name="last updated on",
|
||||||
help_text="Date of last status updated",
|
help_text="Date of last status updated",
|
||||||
)
|
)
|
||||||
notes = models.TextField(
|
notes = models.TextField(
|
||||||
|
@ -816,7 +816,8 @@ 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 the domain has not been submitted before this must be the first time
|
||||||
if not self.first_submitted_date:
|
if not self.first_submitted_date:
|
||||||
self.first_submitted_date = timezone.now().date()
|
self.first_submitted_date = timezone.now().date()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue