mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-28 13:36:30 +02:00
add warning to domain requests when status cannot be changed
This commit is contained in:
parent
6f6beef6e4
commit
36f3d3e8a9
1 changed files with 25 additions and 0 deletions
|
@ -2543,6 +2543,31 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
# Further filter the queryset by the portfolio
|
||||
qs = qs.filter(portfolio=portfolio_id)
|
||||
return qs
|
||||
|
||||
def change_view(self, request, object_id, form_url="", extra_context=None):
|
||||
"""Extend the change_view for DomainRequest objects in django admin.
|
||||
Customize to display notification that statu cannot be changed from 'Approved'."""
|
||||
|
||||
# Fetch the Contact instance
|
||||
domain_request: models.DomainRequest = models.DomainRequest.objects.get(pk=object_id)
|
||||
if domain_request.approved_domain and domain_request.approved_domain.state == models.Domain.State.READY:
|
||||
domain = domain_request.approved_domain
|
||||
# get change url for domain
|
||||
app_label = domain_request.approved_domain._meta.app_label
|
||||
model_name = domain._meta.model_name
|
||||
obj_id = domain.id
|
||||
change_url = reverse("admin:%s_%s_change" % (app_label, model_name), args=[obj_id])
|
||||
|
||||
message += f"<p>The status of this domain request cannot be changed because it has been joined to a domain in Ready status: " # noqa
|
||||
message += f"<a href='{change_url}'>{domain}</a></p>"
|
||||
|
||||
message_html = mark_safe(message) # nosec
|
||||
messages.warning(
|
||||
request,
|
||||
message_html,
|
||||
)
|
||||
|
||||
return super().change_view(request, object_id, form_url, extra_context=extra_context)
|
||||
|
||||
|
||||
class TransitionDomainAdmin(ListHeaderAdmin):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue