diff --git a/src/registrar/forms/application_wizard.py b/src/registrar/forms/application_wizard.py index d731c3965..157d4b234 100644 --- a/src/registrar/forms/application_wizard.py +++ b/src/registrar/forms/application_wizard.py @@ -511,9 +511,7 @@ class DotGovDomainForm(RegistrarForm): values = {} requested_domain = getattr(obj, "requested_domain", None) if requested_domain is not None: - is_incomplete = requested_domain.is_incomplete - # Only display a preexisting name if the application was completed - domain_name = requested_domain.name if not is_incomplete else "" + domain_name = requested_domain.name values["requested_domain"] = Domain.sld(domain_name) return values diff --git a/src/registrar/migrations/0063_draftdomain_draft_number_draftdomain_is_incomplete.py b/src/registrar/migrations/0063_draftdomain_draft_number_draftdomain_is_incomplete.py deleted file mode 100644 index 1ea545c70..000000000 --- a/src/registrar/migrations/0063_draftdomain_draft_number_draftdomain_is_incomplete.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.2.7 on 2024-01-12 16:17 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("registrar", "0062_alter_host_name"), - ] - - operations = [ - migrations.AddField( - model_name="draftdomain", - name="draft_number", - field=models.IntegerField( - help_text="The draft number in the event a user doesn't save at this stage", null=True - ), - ), - migrations.AddField( - model_name="draftdomain", - name="is_incomplete", - field=models.BooleanField(default=False, help_text="Determines if this Draft is complete or not"), - ), - ] diff --git a/src/registrar/migrations/0063_draftdomain_is_complete.py b/src/registrar/migrations/0063_draftdomain_is_complete.py new file mode 100644 index 000000000..d17e59400 --- /dev/null +++ b/src/registrar/migrations/0063_draftdomain_is_complete.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.7 on 2024-01-16 20:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("registrar", "0062_alter_host_name"), + ] + + operations = [ + migrations.AddField( + model_name="draftdomain", + name="is_complete", + field=models.BooleanField(default=True, help_text="Determines if this Draft is complete or not"), + ), + ] diff --git a/src/registrar/models/domain_application.py b/src/registrar/models/domain_application.py index d93c429f9..51c322283 100644 --- a/src/registrar/models/domain_application.py +++ b/src/registrar/models/domain_application.py @@ -632,10 +632,6 @@ class DomainApplication(TimeStampedModel): # Update submission_date to today self.submission_date = timezone.now().date() - # Mark the draft domain as complete - if self.requested_domain.is_incomplete: - self.requested_domain.is_incomplete = False - self.save() self._send_status_update_email( diff --git a/src/registrar/models/draft_domain.py b/src/registrar/models/draft_domain.py index 5fe00257e..a750771b5 100644 --- a/src/registrar/models/draft_domain.py +++ b/src/registrar/models/draft_domain.py @@ -21,13 +21,7 @@ class DraftDomain(TimeStampedModel, DomainHelper): help_text="Fully qualified domain name", ) - draft_number = models.IntegerField( - null=True, - help_text="The draft number in the event a user doesn't save at this stage", + is_complete = models.BooleanField( + default=True, + help_text="Determines if this Draft is complete or not" ) - - is_incomplete = models.BooleanField(default=False, help_text="Determines if this Draft is complete or not") - - def get_default_request_name(self): - """Returns the draft name that would be used for applications if no name exists""" - return f"New domain request {self.draft_number}" diff --git a/src/registrar/templates/home.html b/src/registrar/templates/home.html index 54daa4aa4..1ab4a135e 100644 --- a/src/registrar/templates/home.html +++ b/src/registrar/templates/home.html @@ -124,7 +124,13 @@ {% for application in domain_applications %} - {{ application.requested_domain.name|default:"New domain request" }} + {% if application.requested_domain is None or not application.requested_domain.is_complete %} + New domain request +
+ ({{ application.created_at }}) + {% else %} + {{ application.requested_domain.name }} + {% endif %} {% if application.submission_date %} @@ -140,13 +146,13 @@ - Edit {{ application.requested_domain.name|default:"New domain request" }} + Edit {{ application.requested_domain.name|default:"New domain request ("|add:application.created_at|add:")" }} {% else %} - Manage {{ application.requested_domain.name|default:"New domain request" }} + Manage {{ application.requested_domain.name|default:"New domain request ("|add:application.created_at|add:")" }} {% endif %} @@ -164,7 +170,7 @@ - Delete {{ application.requested_domain.name|default:"New domain request" }} + Delete {{ application.requested_domain.name|default:"New domain request ("|add:application.created_at|add:")" }}
- {% if application.requested_domain %} - {% include 'includes/modal.html' with modal_heading="Are you sure you want to delete "|add:application.requested_domain.name|add:"?" modal_description="This will remove the domain request from the .gov registrar. This action cannot be undone." modal_button=modal_button|safe %} - {% else %} - {% include 'includes/modal.html' with modal_heading="Are you sure you want to delete your domain request?" modal_description="This will remove the domain request from the .gov registrar. This action cannot be undone." modal_button=modal_button|safe %} - {% endif %} + {% include 'includes/modal.html' with modal_heading="Are you sure you want to delete "|add:application.requested_domain.name|add:"?" modal_description="This will remove the domain request from the .gov registrar. This action cannot be undone." modal_button=modal_button|safe %}
{% endif %} diff --git a/src/registrar/views/application.py b/src/registrar/views/application.py index c76d285a7..80ff1eff1 100644 --- a/src/registrar/views/application.py +++ b/src/registrar/views/application.py @@ -143,93 +143,13 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView): except DomainApplication.DoesNotExist: logger.debug("Application id %s did not have a DomainApplication" % id) - draft_domain = self._create_default_draft_domain() - - # Check added for linting purposes - if self.request.user and isinstance(self.request.user, User): - self._application = DomainApplication.objects.create( - creator=self.request.user, - requested_domain=draft_domain, - ) - else: - # TODO - Need some sort of front end display for this - raise ValueError("Invalid type for user") + self._application = DomainApplication.objects.create( + creator=self.request.user + ) self.storage["application_id"] = self._application.id return self._application - def _create_default_draft_domain(self): - "Set a default draft name for if the user exits without completing" - default_draft_text = "New domain request" - - # Does the user have any incomplete drafts? - existing_applications = DomainApplication.objects.filter( - Q(requested_domain=None) | Q(requested_domain__is_incomplete=True), - creator=self.request.user, - ) - - name_field = "requested_domain__name" - - incomplete_drafts = ( - existing_applications.exclude(requested_domain=None) - .filter(requested_domain__name__icontains=default_draft_text) - .order_by(name_field) - ) - - incomplete_draft_names = incomplete_drafts.values_list(name_field, flat=True) - - proposed_draft_number = incomplete_drafts.count() + 1 - draft_number = 1 - for application in existing_applications: - if application.requested_domain is not None and application.requested_domain.name is not None: - name = application.requested_domain.name - - # If we already have a list of draft numbers, base the - # subsequent number off of the last numbered field. - # This is to avoid a scenario in which drafts 1, 2, 3 and exist - # and 2 is deleted - meaning we would get two duplicate "3"s if we added another - if name in incomplete_draft_names: - # Get the last numbered draft - last_draft = incomplete_drafts.last() - last_draft_number = last_draft.requested_domain.draft_number - - smallest_number = self._find_smallest_missing_number(incomplete_drafts) - smallest_name = f"New domain request {smallest_number}" - if smallest_name not in incomplete_draft_names: - draft_number = smallest_number - elif proposed_draft_number == last_draft_number: - # If the draft number we are trying to create matches the last draft number, - # simply add one to that number - draft_number = last_draft_number + 1 - - draft_domain = DraftDomain( - # Save a blank string rather then None due to DB requirements - name="", - draft_number=draft_number, - is_incomplete=True, - ) - # Generate a default name based off of a draft_number - draft_domain.name = draft_domain.get_default_request_name() - draft_domain.save() - - return draft_domain - - def _find_smallest_missing_number(self, incomplete_drafts): - draft_numbers = [] - for draft in incomplete_drafts: - number = draft.requested_domain.draft_number - if number is not None: - draft_numbers.append(number) - - draft_numbers = sorted(draft_numbers) - smallest_missing = 1 - for number in draft_numbers: - if number == smallest_missing: - smallest_missing += 1 - elif number > smallest_missing: - break - return smallest_missing - @property def storage(self): # marking session as modified on every access @@ -409,7 +329,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView): # Build the submit button that we'll pass to the modal. modal_button = '" # Concatenate the modal header that we'll pass to the modal. - if self.application.requested_domain and not self.application.requested_domain.is_incomplete: + if self.application.requested_domain: modal_heading = "You are about to submit a domain request for " + str(self.application.requested_domain) else: modal_heading = "You are about to submit an incomplete request" @@ -556,14 +476,6 @@ class DotgovDomain(ApplicationWizard): context["federal_type"] = self.application.federal_type return context - def post(self, request, *args, **kwargs): - """Override for the post method to mark the DraftDomain as complete""" - # Set the DraftDomain to "complete" - print(f"what is the request at this time? {request}") - self.application.requested_domain.is_incomplete = False - response = super().post(request, *args, **kwargs) - return response - class Purpose(ApplicationWizard): template_name = "application_purpose.html" diff --git a/src/registrar/views/index.py b/src/registrar/views/index.py index f9a658942..3c0f7c723 100644 --- a/src/registrar/views/index.py +++ b/src/registrar/views/index.py @@ -1,6 +1,8 @@ +from django.utils import timezone from django.shortcuts import render from registrar.models import DomainApplication, Domain, UserDomainRole +from registrar.models.draft_domain import DraftDomain def index(request): @@ -12,6 +14,22 @@ def index(request): # 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 context["domain_applications"] = applications @@ -22,17 +40,16 @@ def index(request): context["domains"] = domains # Determine if the user will see applications that they can delete - valid_statuses = [DomainApplication.ApplicationStatus.STARTED, DomainApplication.ApplicationStatus.WITHDRAWN] - has_deletable_applications = applications.filter(status__in=valid_statuses).exists() + has_deletable_applications = deletable_applications.exists() context["has_deletable_applications"] = has_deletable_applications - if has_deletable_applications: + + # Add the delete modal button to the context modal_button = ( '' ) - context["modal_button"] = modal_button return render(request, "home.html", context)