This commit is contained in:
zandercymatics 2024-01-17 09:07:00 -07:00
parent f623d00fc2
commit 816d1fe599
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 10 additions and 17 deletions

View file

@ -1,6 +1,5 @@
import logging
from django.db.models import Q
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect, render
from django.urls import resolve, reverse
@ -11,8 +10,6 @@ from django.contrib import messages
from registrar.forms import application_wizard as forms
from registrar.models import DomainApplication
from registrar.models.draft_domain import DraftDomain
from registrar.models.user import User
from registrar.utility import StrEnum
from registrar.views.utility import StepsHelper
from registrar.views.utility.permission_views import DomainApplicationPermissionDeleteView
@ -143,9 +140,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
except DomainApplication.DoesNotExist:
logger.debug("Application id %s did not have a DomainApplication" % id)
self._application = DomainApplication.objects.create(
creator=self.request.user
)
self._application = DomainApplication.objects.create(creator=self.request.user)
self.storage["application_id"] = self._application.id
return self._application

View file

@ -1,4 +1,3 @@
from django.utils import timezone
from django.shortcuts import render
from registrar.models import DomainApplication, Domain, UserDomainRole
@ -9,9 +8,9 @@ def index(request):
"""This page is available to anyone without logging in."""
context = {}
if request.user.is_authenticated:
# Get all domain applications the user has access to
applications, deletable_applications = _get_applications(request)
applications, deletable_applications = _get_applications(request)
context["domain_applications"] = applications
# Get all domains the user has access to
@ -34,8 +33,9 @@ def index(request):
return render(request, "home.html", context)
def _get_applications(request):
"""Given the current request,
"""Given the current request,
get all DomainApplications that are associated with the UserDomainRole object.
Returns a tuple of all applications, and those that are deletable by the user.
@ -47,22 +47,20 @@ def _get_applications(request):
# Create a placeholder DraftDomain for each incomplete draft
valid_statuses = [DomainApplication.ApplicationStatus.STARTED, DomainApplication.ApplicationStatus.WITHDRAWN]
deletable_applications = applications.filter(status__in=valid_statuses, requested_domain=None)
deletable_applications = applications.filter(status__in=valid_statuses)
for application in applications:
if application in deletable_applications:
if application in deletable_applications and application.requested_domain is None:
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
)
default_draft_domain = DraftDomain(name=_name, is_complete=False)
application.requested_domain = default_draft_domain
return (applications, deletable_applications)
def _get_domains(request):
"""Given the current request,
"""Given the current request,
get all domains that are associated with the UserDomainRole object"""
user_domain_roles = UserDomainRole.objects.filter(user=request.user)
domain_ids = user_domain_roles.values_list("domain_id", flat=True)