mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 17:17:02 +02:00
Additional bug fixes
This commit is contained in:
parent
a8836d35aa
commit
18f7ac7f90
5 changed files with 94 additions and 13 deletions
|
@ -1690,21 +1690,27 @@ class DomainAdmin(ListHeaderAdmin):
|
|||
# Pass in what the an extended expiration date would be for the expiration date modal
|
||||
if object_id is not None:
|
||||
domain = Domain.objects.get(pk=object_id)
|
||||
years_to_extend_by = self._get_calculated_years_for_exp_date(domain)
|
||||
|
||||
try:
|
||||
curr_exp_date = domain.registry_expiration_date
|
||||
except KeyError:
|
||||
# No expiration date was found. Return none.
|
||||
extra_context["extended_expiration_date"] = None
|
||||
return super().changeform_view(request, object_id, form_url, extra_context)
|
||||
new_date = curr_exp_date + relativedelta(years=years_to_extend_by)
|
||||
extra_context["extended_expiration_date"] = new_date
|
||||
else:
|
||||
extra_context["extended_expiration_date"] = None
|
||||
extra_context = self._set_expiration_date_context(domain, extra_context)
|
||||
extra_context["state_help_message"] = Domain.State.get_admin_help_text(domain.state)
|
||||
|
||||
return super().changeform_view(request, object_id, form_url, extra_context)
|
||||
|
||||
def _set_expiration_date_context(self, domain, extra_context):
|
||||
"""Given a domain, calculate the an extended expiration date
|
||||
from the current registry expiration date."""
|
||||
years_to_extend_by = self._get_calculated_years_for_exp_date(domain)
|
||||
|
||||
try:
|
||||
curr_exp_date = domain.registry_expiration_date
|
||||
except KeyError:
|
||||
# No expiration date was found. Return none.
|
||||
extra_context["extended_expiration_date"] = None
|
||||
else:
|
||||
new_date = curr_exp_date + relativedelta(years=years_to_extend_by)
|
||||
extra_context["extended_expiration_date"] = new_date
|
||||
|
||||
return extra_context
|
||||
|
||||
def response_change(self, request, obj):
|
||||
# Create dictionary of action functions
|
||||
ACTION_FUNCTIONS = {
|
||||
|
|
31
src/registrar/migrations/0086_alter_domain_state.py
Normal file
31
src/registrar/migrations/0086_alter_domain_state.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Generated by Django 4.2.10 on 2024-04-15 19:26
|
||||
|
||||
from django.db import migrations
|
||||
import django_fsm
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("registrar", "0085_alter_domain_deleted_alter_domain_expiration_date_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="domain",
|
||||
name="state",
|
||||
field=django_fsm.FSMField(
|
||||
choices=[
|
||||
("unknown", "Unknown"),
|
||||
("dns needed", "Dns needed"),
|
||||
("ready", "Ready"),
|
||||
("on hold", "On hold"),
|
||||
("deleted", "Deleted"),
|
||||
],
|
||||
default="unknown",
|
||||
help_text=" ",
|
||||
max_length=21,
|
||||
protected=True,
|
||||
),
|
||||
),
|
||||
]
|
|
@ -159,6 +159,32 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
|
||||
return help_texts.get(state, "")
|
||||
|
||||
@classmethod
|
||||
def get_admin_help_text(cls, state) -> str:
|
||||
"""Returns a help message for a desired state for /admin. If none is found, an empty string is returned"""
|
||||
admin_help_texts = {
|
||||
# For now, unknown has the same message as DNS_NEEDED
|
||||
cls.UNKNOWN: (
|
||||
"The creator of the associated domain request has not logged in to "
|
||||
"manage the domain since it was approved. "
|
||||
'The state will switch to "DNS needed" after they access the domain in the registrar.'
|
||||
),
|
||||
cls.DNS_NEEDED: (
|
||||
"Before this domain can be used, name server addresses need to be added within the registrar."
|
||||
),
|
||||
cls.READY: "This domain has name servers and is ready for use.",
|
||||
cls.ON_HOLD: (
|
||||
"While on hold, this domain won't resolve in DNS and "
|
||||
"any infrastructure (like websites) will be offline.",
|
||||
),
|
||||
cls.DELETED: (
|
||||
"This domain was permanently removed from the registry. "
|
||||
"The domain no longer resolves in DNS and any infrastructure (like websites) is offline.",
|
||||
),
|
||||
}
|
||||
|
||||
return admin_help_texts.get(state, "")
|
||||
|
||||
class Cache(property):
|
||||
"""
|
||||
Python descriptor to turn class methods into properties.
|
||||
|
@ -1000,6 +1026,9 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
default=State.UNKNOWN,
|
||||
# cannot change state directly, particularly in Django admin
|
||||
protected=True,
|
||||
# This must be defined for custom state help messages,
|
||||
# as otherwise the view will purge the help field as it does not exist.
|
||||
help_text=" ",
|
||||
)
|
||||
|
||||
expiration_date = DateField(
|
||||
|
|
|
@ -33,7 +33,10 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{{ block.super }}
|
||||
|
||||
{% for fieldset in adminform %}
|
||||
{% include "django/admin/includes/domain_fieldset.html" with state_help_message=state_help_message %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block submit_buttons_bottom %}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{% extends "admin/fieldset.html" %}
|
||||
{% load static url_helpers %}
|
||||
|
||||
|
||||
{# .gov override #}
|
||||
{% block help_text %}
|
||||
{% if field.field.name == "state" %}
|
||||
<div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
|
||||
<div>{{ state_help_message }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock help_text %}
|
Loading…
Add table
Add a link
Reference in a new issue