mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 10:07:04 +02:00
Error handling
This commit is contained in:
parent
8980d98be9
commit
b91d454fa2
1 changed files with 47 additions and 50 deletions
|
@ -33,6 +33,7 @@ from django.contrib.auth.forms import UserChangeForm, UsernameField
|
|||
from django_admin_multiple_choice_list_filter.list_filters import MultipleChoiceListFilter
|
||||
from import_export import resources
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
@ -1817,12 +1818,13 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
obj = self.get_object(request, object_id)
|
||||
self.display_restricted_warning(request, obj)
|
||||
|
||||
# Retrieve and order audit log entries by timestamp in ascending order
|
||||
audit_log_entries = LogEntry.objects.filter(object_id=object_id).order_by("timestamp")
|
||||
|
||||
# Initialize variables for tracking status changes and filtered entries
|
||||
filtered_entries = []
|
||||
|
||||
try:
|
||||
# Retrieve and order audit log entries by timestamp in ascending order
|
||||
audit_log_entries = LogEntry.objects.filter(object_id=object_id).order_by("timestamp")
|
||||
|
||||
# Process each log entry to filter based on the change criteria
|
||||
for log_entry in audit_log_entries:
|
||||
changes = log_entry.changes
|
||||
|
@ -1836,14 +1838,16 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
|
||||
# Handle status change
|
||||
if status_changed:
|
||||
entry["status"] = DomainRequest.DomainRequestStatus(changes["status"][1]).label
|
||||
# last_status = entry["status"]
|
||||
status_value = changes.get("status", [None, None])[1]
|
||||
if status_value:
|
||||
entry["status"] = DomainRequest.DomainRequestStatus(status_value).label
|
||||
|
||||
# Handle rejection reason change
|
||||
if rejection_reason_changed:
|
||||
rejection_reason = changes["rejection_reason"][1]
|
||||
rejection_reason_value = changes.get("rejection_reason", [None, None])[1]
|
||||
if rejection_reason_value:
|
||||
entry["rejection_reason"] = (
|
||||
"" if rejection_reason == "None" else DomainRequest.RejectionReasons(rejection_reason).label
|
||||
"" if rejection_reason_value == "None" else DomainRequest.RejectionReasons(rejection_reason_value).label
|
||||
)
|
||||
# Handle case where rejection reason changed but not status
|
||||
if not status_changed:
|
||||
|
@ -1851,11 +1855,10 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
|
||||
# Handle action needed reason change
|
||||
if action_needed_reason_changed:
|
||||
action_needed_reason = changes["action_needed_reason"][1]
|
||||
action_needed_reason_value = changes.get("action_needed_reason", [None, None])[1]
|
||||
if action_needed_reason_value:
|
||||
entry["action_needed_reason"] = (
|
||||
""
|
||||
if action_needed_reason == "None"
|
||||
else DomainRequest.ActionNeededReasons(action_needed_reason).label
|
||||
"" if action_needed_reason_value == "None" else DomainRequest.ActionNeededReasons(action_needed_reason_value).label
|
||||
)
|
||||
# Handle case where action needed reason changed but not status
|
||||
if not status_changed:
|
||||
|
@ -1868,16 +1871,10 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
# Append the filtered entry to the list
|
||||
filtered_entries.append(entry)
|
||||
|
||||
# Reverse the filtered entries list to get newest to oldest order
|
||||
filtered_entries.reverse()
|
||||
|
||||
# Initialize extra_context and add filtered entries
|
||||
if extra_context is None:
|
||||
extra_context = {}
|
||||
extra_context["filtered_entries"] = filtered_entries
|
||||
|
||||
return super().change_view(request, object_id, form_url, extra_context)
|
||||
|
||||
except ObjectDoesNotExist as e:
|
||||
logger.error(f"Object with object_id {object_id} does not exist: {e}")
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred during change_view: {e}")
|
||||
|
||||
class TransitionDomainAdmin(ListHeaderAdmin):
|
||||
"""Custom transition domain admin class."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue