Remove is_complete and do the test and string concat in template instead

This commit is contained in:
Rachid Mrad 2024-01-17 16:32:02 -05:00
parent 1edd9c97e2
commit 2ee9a8f32d
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
4 changed files with 22 additions and 28 deletions

View file

@ -1,17 +0,0 @@
# 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"),
),
]

View file

@ -20,5 +20,3 @@ class DraftDomain(TimeStampedModel, DomainHelper):
default=None, # prevent saving without a value
help_text="Fully qualified domain name",
)
is_complete = models.BooleanField(default=True, help_text="Determines if this Draft is complete or not")

View file

@ -124,7 +124,7 @@
{% for application in domain_applications %}
<tr>
<th th scope="row" role="rowheader" data-label="Domain name">
{% if application.requested_domain is None or not application.requested_domain.is_complete %}
{% if application.requested_domain is None %}
New domain request
<br>
<span class="text-base">({{ application.created_at }})</span>
@ -181,7 +181,26 @@
data-force-action
>
<form method="POST" action="{% url "application-delete" pk=application.id %}">
{% 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 %}
{% if application.requested_domain is None %}
{% with prefix="Are you sure you want to delete New domain request " %}
{% if application.created_at %}
{% with formatted_date=application.created_at|date:"DATETIME_FORMAT" %}
{% with modal_heading=prefix|add:formatted_date %}
{% include 'includes/modal.html' with modal_heading=modal_heading modal_description="This will remove the domain request from the .gov registrar. This action cannot be undone." modal_button=modal_button|safe %}
{% endwith %}
{% endwith %}
{% else %}
{# Handle the case when application.created_at is not available or empty #}
{% with modal_heading=prefix %}
{% include 'includes/modal.html' with modal_heading=modal_heading modal_description="This will remove the domain request from the .gov registrar. This action cannot be undone." modal_button=modal_button|safe %}
{% endwith %}
{% endif %}
{% endwith %}
{% else %}
{% with modal_heading="Are you sure you want to delete "|add:application.requested_domain.name|add:"?" %}
{% include 'includes/modal.html' with modal_heading=modal_heading modal_description="This will remove the domain request from the .gov registrar. This action cannot be undone." modal_button=modal_button|safe %}
{% endwith %}
{% endif %}
</form>
</div>
{% endif %}

View file

@ -48,13 +48,7 @@ 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)
for application in 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)
application.requested_domain = default_draft_domain
return (applications, deletable_applications)