mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 09:37:03 +02:00
Minor code cleanup
This commit is contained in:
parent
10e8317e3c
commit
d989d9581a
2 changed files with 71 additions and 69 deletions
|
@ -2,19 +2,17 @@ from datetime import date
|
||||||
import logging
|
import logging
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.db.models.functions import Concat
|
from django.db.models.functions import Concat
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django_fsm import get_available_FIELD_transitions
|
from django_fsm import get_available_FIELD_transitions
|
||||||
from django.contrib import admin, messages
|
from django.contrib import admin, messages
|
||||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.http.response import HttpResponseRedirect
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from dateutil.relativedelta import relativedelta # type: ignore
|
||||||
from epplibwrapper.errors import ErrorCode, RegistryError
|
from epplibwrapper.errors import ErrorCode, RegistryError
|
||||||
from registrar.models.domain import Domain
|
from registrar.models import Domain, User
|
||||||
from registrar.models.user import User
|
|
||||||
from registrar.utility import csv_export
|
from registrar.utility import csv_export
|
||||||
from registrar.views.utility.mixins import OrderableFieldsMixin
|
from registrar.views.utility.mixins import OrderableFieldsMixin
|
||||||
from django.contrib.admin.views.main import ORDER_VAR
|
from django.contrib.admin.views.main import ORDER_VAR
|
||||||
|
@ -1170,15 +1168,14 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
# "catch up" to the current year, so we add the difference.
|
# "catch up" to the current year, so we add the difference.
|
||||||
# If both years match, then lets just proceed as normal.
|
# If both years match, then lets just proceed as normal.
|
||||||
calculated_exp_date = exp_date + relativedelta(years=1)
|
calculated_exp_date = exp_date + relativedelta(years=1)
|
||||||
years = 1
|
|
||||||
if desired_date > calculated_exp_date:
|
year_difference = desired_date.year - exp_date.year
|
||||||
year_difference = desired_date.year - exp_date.year
|
# Max probably isn't needed here (no code flow), but it guards against negative and 0.
|
||||||
years = year_difference
|
years = max(1, year_difference) if desired_date > calculated_exp_date else 1
|
||||||
|
|
||||||
# Renew the domain.
|
# Renew the domain.
|
||||||
try:
|
try:
|
||||||
obj.renew_domain(length=years)
|
obj.renew_domain(length=years)
|
||||||
|
|
||||||
self.message_user(
|
self.message_user(
|
||||||
request,
|
request,
|
||||||
"Successfully extended the expiration date.",
|
"Successfully extended the expiration date.",
|
||||||
|
@ -1188,7 +1185,6 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
error_message = "Error connecting to the registry."
|
error_message = "Error connecting to the registry."
|
||||||
else:
|
else:
|
||||||
error_message = f"Error extending this domain: {err}."
|
error_message = f"Error extending this domain: {err}."
|
||||||
|
|
||||||
self.message_user(request, error_message, messages.ERROR)
|
self.message_user(request, error_message, messages.ERROR)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# In normal code flow, a keyerror can only occur when
|
# In normal code flow, a keyerror can only occur when
|
||||||
|
@ -1362,13 +1358,6 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
return True
|
return True
|
||||||
return super().has_change_permission(request, obj)
|
return super().has_change_permission(request, obj)
|
||||||
|
|
||||||
def changelist_view(self, request, extra_context=None):
|
|
||||||
extra_context = extra_context or {}
|
|
||||||
# Create HTML for the modal button
|
|
||||||
modal_button = '<button type="submit" ' 'class="usa-button" ' 'name="_extend_expiration_date">Confirm</button>'
|
|
||||||
extra_context["modal_button"] = modal_button
|
|
||||||
return super().changelist_view(request, extra_context=extra_context)
|
|
||||||
|
|
||||||
|
|
||||||
class DraftDomainAdmin(ListHeaderAdmin):
|
class DraftDomainAdmin(ListHeaderAdmin):
|
||||||
"""Custom draft domain admin class."""
|
"""Custom draft domain admin class."""
|
||||||
|
|
|
@ -44,58 +44,71 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block submit_buttons_bottom %}
|
{% block submit_buttons_bottom %}
|
||||||
<div
|
{% comment %}
|
||||||
class="usa-modal"
|
Modals behave very weirdly in django admin.
|
||||||
id="toggle-extend-expiration-alert"
|
They tend to "strip out" any injected form elements, leaving only the main form.
|
||||||
aria-labelledby="Are you sure you want to extend this expiration date?"
|
In addition, USWDS handles modals by first destroying the element, then repopulating it toward the end of the page.
|
||||||
aria-describedby="This expiration date will be extended."
|
In effect, this means that the modal is not, and cannot, be surrounded by any form element at compile time.
|
||||||
>
|
|
||||||
<div class="usa-modal__content">
|
|
||||||
<div class="usa-modal__main">
|
|
||||||
<h2 class="usa-modal__heading" id="modal-1-heading">
|
|
||||||
Are you sure you want to extend this expiration date?
|
|
||||||
</h2>
|
|
||||||
<div class="usa-prose">
|
|
||||||
<p id="modal-1-description">
|
|
||||||
This action will extend the expiration date by a year.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="usa-modal__footer">
|
The current workaround for this is to use javascript to inject a hidden input, and bind submit of that
|
||||||
<ul class="usa-button-group">
|
element to the click of the confirmation button within this modal.
|
||||||
<li class="usa-button-group__item">
|
|
||||||
<button
|
This is controlled by the class `dja-form-placeholder` on the button.
|
||||||
id="extend_expiration_date_button"
|
|
||||||
type="submit"
|
In addition, the modal element MUST be placed low in the DOM. The script loads slower on DJA than on other portions
|
||||||
class="usa-button dja-form-placeholder"
|
of the application, so this means that it will briefly "populate", causing unintended visual effects.
|
||||||
name="_extend_expiration_date"
|
{% endcomment %}
|
||||||
>
|
<div
|
||||||
Confirm
|
class="usa-modal"
|
||||||
</button>
|
id="toggle-extend-expiration-alert"
|
||||||
</li>
|
aria-labelledby="Are you sure you want to extend this expiration date?"
|
||||||
<li class="usa-button-group__item">
|
aria-describedby="This expiration date will be extended."
|
||||||
<button
|
>
|
||||||
type="button"
|
<div class="usa-modal__content">
|
||||||
class="usa-button usa-button--unstyled padding-105 text-center"
|
<div class="usa-modal__main">
|
||||||
data-close-modal
|
<h2 class="usa-modal__heading" id="modal-1-heading">
|
||||||
>
|
Are you sure you want to extend this expiration date?
|
||||||
Cancel
|
</h2>
|
||||||
</button>
|
<div class="usa-prose">
|
||||||
</li>
|
<p id="modal-1-description">
|
||||||
</ul>
|
This action will extend the expiration date by a year.
|
||||||
</div>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
|
||||||
type="button"
|
<div class="usa-modal__footer">
|
||||||
class="usa-button usa-modal__close"
|
<ul class="usa-button-group">
|
||||||
aria-label="Close this window"
|
<li class="usa-button-group__item">
|
||||||
data-close-modal
|
<button
|
||||||
>
|
type="submit"
|
||||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
|
class="usa-button dja-form-placeholder"
|
||||||
<use xlink:href="{%static 'img/sprite.svg'%}#close"></use>
|
name="_extend_expiration_date"
|
||||||
</svg>
|
>
|
||||||
</button>
|
Confirm
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li class="usa-button-group__item">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="usa-button usa-button--unstyled padding-105 text-center"
|
||||||
|
data-close-modal
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="usa-button usa-modal__close"
|
||||||
|
aria-label="Close this window"
|
||||||
|
data-close-modal
|
||||||
|
>
|
||||||
|
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
|
||||||
|
<use xlink:href="{%static 'img/sprite.svg'%}#close"></use>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue