diff --git a/src/registrar/views/index.py b/src/registrar/views/index.py index 3c0f7c723..0a682b855 100644 --- a/src/registrar/views/index.py +++ b/src/registrar/views/index.py @@ -9,41 +9,21 @@ def index(request): """This page is available to anyone without logging in.""" context = {} if request.user.is_authenticated: - # Let's exclude the approved applications since our - # domain_applications context will be used to populate - # the active applications table - applications = DomainApplication.objects.filter(creator=request.user).exclude(status="approved") - - valid_statuses = [DomainApplication.ApplicationStatus.STARTED, DomainApplication.ApplicationStatus.WITHDRAWN] - - # Create a placeholder DraftDomain for each incomplete draft - deletable_applications = applications.filter(status__in=valid_statuses, requested_domain=None) - for application in applications: - if application in deletable_applications: - created_at = application.created_at.strftime("%b. %d, %Y, %I:%M %p UTC") - _name = f"New domain request ({created_at})" - default_draft_domain = DraftDomain( - name=_name, - is_complete=False - ) - - application.requested_domain = default_draft_domain - - # Pass the final context to the application + # Get all domain applications the user has access to + applications, deletable_applications = _get_applications(request) context["domain_applications"] = applications - user_domain_roles = UserDomainRole.objects.filter(user=request.user) - domain_ids = user_domain_roles.values_list("domain_id", flat=True) - domains = Domain.objects.filter(id__in=domain_ids) - + # Get all domains the user has access to + domains = _get_domains(request) context["domains"] = domains # Determine if the user will see applications that they can delete has_deletable_applications = deletable_applications.exists() context["has_deletable_applications"] = has_deletable_applications - if has_deletable_applications: + # If they can delete applications, add the delete button to the context + if has_deletable_applications: # Add the delete modal button to the context modal_button = ( '