-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2618 from cisagov/ms/2451-additional-domain-reque…
…st-dates Issue #2541 additional domain request dates [getgov-litterbox]
- Loading branch information
Showing
24 changed files
with
219 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/registrar/management/commands/populate_domain_request_dates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
from django.core.management import BaseCommand | ||
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors | ||
from registrar.models import DomainRequest | ||
from auditlog.models import LogEntry | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand, PopulateScriptTemplate): | ||
help = "Loops through each domain request object and populates the last_status_update and first_submitted_date" | ||
|
||
def handle(self, **kwargs): | ||
"""Loops through each DomainRequest object and populates | ||
its last_status_update and first_submitted_date values""" | ||
self.mass_update_records(DomainRequest, None, ["last_status_update", "first_submitted_date"]) | ||
|
||
def update_record(self, record: DomainRequest): | ||
"""Defines how we update the first_submitted_date and last_status_update fields""" | ||
|
||
# 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_dict: | ||
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(): | ||
status = log_entry.changes_dict.get("status") | ||
if status and status[1] == "submitted": | ||
record.first_submitted_date = log_entry.timestamp.date() | ||
break | ||
|
||
logger.info( | ||
f"""{TerminalColors.OKCYAN}Updating {record} => | ||
first submitted date: {record.first_submitted_date}, | ||
last status update: {record.last_status_update}{TerminalColors.ENDC} | ||
""" | ||
) | ||
|
||
def should_skip_record(self, record) -> bool: | ||
# make sure the record had some kind of history | ||
return not LogEntry.objects.filter(object_pk=record.pk).exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/registrar/migrations/0120_add_domainrequest_submission_dates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 4.2.10 on 2024-08-16 15:28 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("registrar", "0119_remove_user_portfolio_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 the last status update", | ||
null=True, | ||
verbose_name="last updated on", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -777,13 +777,13 @@ def sharedSetUp(cls): | |
cls.domain_request_3.alternative_domains.add(website, website_2) | ||
cls.domain_request_3.current_websites.add(website_3, website_4) | ||
cls.domain_request_3.cisa_representative_email = "[email protected]" | ||
cls.domain_request_3.submission_date = get_time_aware_date(datetime(2024, 4, 2)) | ||
cls.domain_request_3.last_submitted_date = get_time_aware_date(datetime(2024, 4, 2)) | ||
cls.domain_request_3.save() | ||
|
||
cls.domain_request_4.submission_date = get_time_aware_date(datetime(2024, 4, 2)) | ||
cls.domain_request_4.last_submitted_date = get_time_aware_date(datetime(2024, 4, 2)) | ||
cls.domain_request_4.save() | ||
|
||
cls.domain_request_6.submission_date = get_time_aware_date(datetime(2024, 4, 2)) | ||
cls.domain_request_6.last_submitted_date = get_time_aware_date(datetime(2024, 4, 2)) | ||
cls.domain_request_6.save() | ||
|
||
@classmethod | ||
|
Oops, something went wrong.