updated handling of expired

This commit is contained in:
David Kennedy 2024-06-20 18:34:58 -04:00
parent 9489d68235
commit 811f06f511
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -1,4 +1,3 @@
from datetime import timezone
from django.http import JsonResponse
from django.core.paginator import Paginator
from registrar.models import UserDomainRole, Domain
@ -30,11 +29,11 @@ def get_domains_json(request):
# Handle state
status_param = request.GET.get("status")
if status_param:
status_list = status_param.split(',')
status_list = status_param.split(",")
# Split the status list into normal states and custom states
normal_states = [state for state in status_list if state in Domain.State.values]
custom_states = [state for state in status_list if state == 'expired']
custom_states = [state for state in status_list if state == "expired"]
# Construct Q objects for normal states that can be queried through ORM
state_query = Q()
@ -42,16 +41,18 @@ def get_domains_json(request):
state_query |= Q(state__in=normal_states)
# Handle custom states in Python, as expired can not be queried through ORM
if 'expired' in custom_states:
expired_domains = [domain.id for domain in objects if domain.state_display() == 'Expired']
if "expired" in custom_states:
expired_domains = [domain.id for domain in objects if domain.state_display() == "Expired"]
state_query |= Q(id__in=expired_domains)
# Apply the combined query
objects = objects.filter(state_query)
# NOTE: when a domain has a state of 'ready' and is_expired(), a search for
# status=ready will include the domain, even though the domain's state_display
# is Expired.
# If there are filtered states, and expired is not one of them, domains with
# state_display of 'Expired' must be removed
if "expired" not in custom_states:
expired_domains = [domain.id for domain in objects if domain.state_display() == "Expired"]
objects = objects.exclude(id__in=expired_domains)
if sort_by == "state_display":
# Fetch the objects and sort them in Python