mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-17 15:04:11 +02:00
updated handling of expired
This commit is contained in:
parent
9489d68235
commit
811f06f511
1 changed files with 9 additions and 8 deletions
|
@ -1,4 +1,3 @@
|
||||||
from datetime import timezone
|
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from registrar.models import UserDomainRole, Domain
|
from registrar.models import UserDomainRole, Domain
|
||||||
|
@ -30,11 +29,11 @@ def get_domains_json(request):
|
||||||
# Handle state
|
# Handle state
|
||||||
status_param = request.GET.get("status")
|
status_param = request.GET.get("status")
|
||||||
if status_param:
|
if status_param:
|
||||||
status_list = status_param.split(',')
|
status_list = status_param.split(",")
|
||||||
|
|
||||||
# Split the status list into normal states and custom states
|
# Split the status list into normal states and custom states
|
||||||
normal_states = [state for state in status_list if state in Domain.State.values]
|
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
|
# Construct Q objects for normal states that can be queried through ORM
|
||||||
state_query = Q()
|
state_query = Q()
|
||||||
|
@ -42,16 +41,18 @@ def get_domains_json(request):
|
||||||
state_query |= Q(state__in=normal_states)
|
state_query |= Q(state__in=normal_states)
|
||||||
|
|
||||||
# Handle custom states in Python, as expired can not be queried through ORM
|
# Handle custom states in Python, as expired can not be queried through ORM
|
||||||
if 'expired' in custom_states:
|
if "expired" in custom_states:
|
||||||
expired_domains = [domain.id for domain in objects if domain.state_display() == 'Expired']
|
expired_domains = [domain.id for domain in objects if domain.state_display() == "Expired"]
|
||||||
state_query |= Q(id__in=expired_domains)
|
state_query |= Q(id__in=expired_domains)
|
||||||
|
|
||||||
# Apply the combined query
|
# Apply the combined query
|
||||||
objects = objects.filter(state_query)
|
objects = objects.filter(state_query)
|
||||||
|
|
||||||
# NOTE: when a domain has a state of 'ready' and is_expired(), a search for
|
# If there are filtered states, and expired is not one of them, domains with
|
||||||
# status=ready will include the domain, even though the domain's state_display
|
# state_display of 'Expired' must be removed
|
||||||
# is Expired.
|
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":
|
if sort_by == "state_display":
|
||||||
# Fetch the objects and sort them in Python
|
# Fetch the objects and sort them in Python
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue