From 5673d5951ef197ee6ef8edd2c4811bf16cecf605 Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Mon, 15 Apr 2024 08:50:13 -0400 Subject: [PATCH 1/2] default filter applied when clicking domain requests from editing a domain request --- src/registrar/admin.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 05bfc06b6..efd8c29c9 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1435,12 +1435,35 @@ class DomainRequestAdmin(ListHeaderAdmin): """ Override changelist_view to set the selected value of status filter. """ + # there are two conditions which should set the default selected filter: + # 1 - there are no query parameters in the request and the request is the + # initial request for this view + # 2 - there are no query parameters in the request and the referring url is + # the change view for a domain request + should_apply_default_filter = False # use http_referer in order to distinguish between request as a link from another page # and request as a removal of all filters http_referer = request.META.get("HTTP_REFERER", "") # if there are no query parameters in the request - # and the request is the initial request for this view - if not bool(request.GET) and request.path not in http_referer: + if not bool(request.GET): + # if the request is the initial request for this view + if request.path not in http_referer: + should_apply_default_filter = True + # elif the request is a referral from changelist view or from + # domain request change view + elif request.path in http_referer: + # find the index to determine the referring url after the path + index = http_referer.find(request.path) + # Check if there is a character following the path in http_referer + if index + len(request.path) < len(http_referer): + next_char = http_referer[index + len(request.path)] + + # Check if the next character is a digit, if so, this indicates + # a change view for domain request + if next_char.isdigit(): + should_apply_default_filter = True + + if should_apply_default_filter: # modify the GET of the request to set the selected filter modified_get = copy.deepcopy(request.GET) modified_get["status__in"] = "submitted,in review,action needed" From c1c428b6c3025fbf87f84cee049a3c15e7facf14 Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Wed, 17 Apr 2024 12:40:27 -0400 Subject: [PATCH 2/2] updated code for readability --- src/registrar/admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index efd8c29c9..a0d2a0b6b 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1455,8 +1455,9 @@ class DomainRequestAdmin(ListHeaderAdmin): # find the index to determine the referring url after the path index = http_referer.find(request.path) # Check if there is a character following the path in http_referer - if index + len(request.path) < len(http_referer): - next_char = http_referer[index + len(request.path)] + next_char_index = index + len(request.path) + if index + next_char_index < len(http_referer): + next_char = http_referer[next_char_index] # Check if the next character is a digit, if so, this indicates # a change view for domain request