mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-03 09:43:33 +02:00
Remove numbering
This commit is contained in:
parent
9899b5ae3e
commit
9fe1bbaac5
8 changed files with 57 additions and 145 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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"),
|
||||
),
|
||||
]
|
17
src/registrar/migrations/0063_draftdomain_is_complete.py
Normal file
17
src/registrar/migrations/0063_draftdomain_is_complete.py
Normal file
|
@ -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"),
|
||||
),
|
||||
]
|
|
@ -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(
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -124,7 +124,13 @@
|
|||
{% for application in domain_applications %}
|
||||
<tr>
|
||||
<th th scope="row" role="rowheader" data-label="Domain name">
|
||||
{{ application.requested_domain.name|default:"New domain request" }}
|
||||
{% if application.requested_domain is None or not application.requested_domain.is_complete %}
|
||||
New domain request
|
||||
<br>
|
||||
<span class="text-base">({{ application.created_at }})</span>
|
||||
{% else %}
|
||||
{{ application.requested_domain.name }}
|
||||
{% endif %}
|
||||
</th>
|
||||
<td data-sort-value="{{ application.submission_date|date:"U" }}" data-label="Date submitted">
|
||||
{% if application.submission_date %}
|
||||
|
@ -140,13 +146,13 @@
|
|||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24">
|
||||
<use xlink:href="{%static 'img/sprite.svg'%}#edit"></use>
|
||||
</svg>
|
||||
Edit <span class="usa-sr-only">{{ application.requested_domain.name|default:"New domain request" }}</span>
|
||||
Edit <span class="usa-sr-only">{{ application.requested_domain.name|default:"New domain request ("|add:application.created_at|add:")" }}</span>
|
||||
{% else %}
|
||||
<a href="{% url 'application-status' application.pk %}">
|
||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24">
|
||||
<use xlink:href="{%static 'img/sprite.svg'%}#settings"></use>
|
||||
</svg>
|
||||
Manage <span class="usa-sr-only">{{ application.requested_domain.name|default:"New domain request" }}</span>
|
||||
Manage <span class="usa-sr-only">{{ application.requested_domain.name|default:"New domain request ("|add:application.created_at|add:")" }}</span>
|
||||
{% endif %}
|
||||
</a>
|
||||
</td>
|
||||
|
@ -164,7 +170,7 @@
|
|||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24">
|
||||
<use xlink:href="{%static 'img/sprite.svg'%}#delete"></use>
|
||||
</svg>
|
||||
Delete <span class="usa-sr-only">{{ application.requested_domain.name|default:"New domain request" }}</span>
|
||||
Delete <span class="usa-sr-only">{{ application.requested_domain.name|default:"New domain request ("|add:application.created_at|add:")" }}</span>
|
||||
</a>
|
||||
|
||||
<div
|
||||
|
@ -175,11 +181,7 @@
|
|||
data-force-action
|
||||
>
|
||||
<form method="POST" action="{% url "application-delete" pk=application.id %}">
|
||||
{% 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 %}
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -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 = '<button type="submit" ' 'class="usa-button" ' ">Submit request</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"
|
||||
|
|
|
@ -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 = (
|
||||
'<button type="submit" '
|
||||
'class="usa-button usa-button--secondary" '
|
||||
'name="delete-application">Yes, delete request</button>'
|
||||
)
|
||||
|
||||
context["modal_button"] = modal_button
|
||||
|
||||
return render(request, "home.html", context)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue