mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 19:09:22 +02:00
Code simplification
This commit is contained in:
parent
7e8f07439e
commit
ed36fc6e3b
7 changed files with 120 additions and 115 deletions
|
@ -913,6 +913,8 @@ class DomainInformationAdmin(ListHeaderAdmin):
|
||||||
# Table ordering
|
# Table ordering
|
||||||
ordering = ["domain__name"]
|
ordering = ["domain__name"]
|
||||||
|
|
||||||
|
change_form_template = "django/admin/domain_information_change_form.html"
|
||||||
|
|
||||||
def get_readonly_fields(self, request, obj=None):
|
def get_readonly_fields(self, request, obj=None):
|
||||||
"""Set the read-only state on form elements.
|
"""Set the read-only state on form elements.
|
||||||
We have 1 conditions that determine which fields are read-only:
|
We have 1 conditions that determine which fields are read-only:
|
||||||
|
|
|
@ -16,34 +16,49 @@ https://github.com/django/django/blob/main/django/contrib/admin/templates/admin/
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock fieldset_description %}
|
{% endblock fieldset_description %}
|
||||||
|
|
||||||
{% block fieldset_lines %}
|
{% for line in fieldset %}
|
||||||
{% for line in fieldset %}
|
<div class="form-row{% if line.fields|length == 1 and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
|
||||||
<div class="form-row{% if line.fields|length == 1 and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
|
{% if line.fields|length == 1 %}{{ line.errors }}{% else %}<div class="flex-container form-multiline">{% endif %}
|
||||||
{% if line.fields|length == 1 %}{{ line.errors }}{% else %}<div class="flex-container form-multiline">{% endif %}
|
{% for field in line %}
|
||||||
{% for field in line %}
|
<div>
|
||||||
<div>
|
{% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %}
|
||||||
{% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %}
|
<div class="flex-container{% if not line.fields|length == 1 %} fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}{% elif field.is_checkbox %} checkbox-row{% endif %}">
|
||||||
<div class="flex-container{% if not line.fields|length == 1 %} fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}{% elif field.is_checkbox %} checkbox-row{% endif %}">
|
{% if field.is_checkbox %}
|
||||||
{% if field.is_checkbox %}
|
{% block field_checkbox %}
|
||||||
{{ field.field }}{{ field.label_tag }}
|
{{ field.field }}{{ field.label_tag }}
|
||||||
|
{% endblock field_checkbox%}
|
||||||
|
{% else %}
|
||||||
|
{{ field.label_tag }}
|
||||||
|
{% if field.is_readonly %}
|
||||||
|
{% block field_readonly %}
|
||||||
|
<div class="readonly">{{ field.contents }}</div>
|
||||||
|
{% endblock field_readonly%}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ field.label_tag }}
|
{% block field_other %}
|
||||||
{% if field.is_readonly %}
|
{{ field.field }}
|
||||||
<div class="readonly">{{ field.contents }}</div>
|
{% endblock field_other%}
|
||||||
{% else %}
|
|
||||||
{{ field.field }}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
{% endif %}
|
||||||
{% if field.field.help_text %}
|
</div>
|
||||||
<div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
|
|
||||||
<div>{{ field.field.help_text|safe }}</div>
|
{% block before_help_text %}
|
||||||
</div>
|
{# For templating purposes #}
|
||||||
{% endif %}
|
{% endblock before_help_text %}
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% if field.field.help_text %}
|
||||||
{% if not line.fields|length == 1 %}</div>{% endif %}
|
{% block help_text %}
|
||||||
</div>
|
<div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
|
||||||
{% endfor %}
|
<div>{{ field.field.help_text|safe }}</div>
|
||||||
{% endblock fieldset_lines %}
|
</div>
|
||||||
|
{% endblock help_text %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% block after_help_text %}
|
||||||
|
{# For templating purposes #}
|
||||||
|
{% endblock after_help_text %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% if not line.fields|length == 1 %}</div>{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
{% extends 'admin/change_form.html' %}
|
||||||
|
{% load i18n static %}
|
||||||
|
|
||||||
|
{% block field_sets %}
|
||||||
|
{% for fieldset in adminform %}
|
||||||
|
{% include "django/admin/includes/domain_information_fieldset.html" %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,61 @@
|
||||||
|
{% extends "admin/fieldset.html" %}
|
||||||
|
{% load static url_helpers %}
|
||||||
|
|
||||||
|
{% comment %}
|
||||||
|
This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
||||||
|
{% endcomment %}
|
||||||
|
{% block field_readonly %}
|
||||||
|
{% if field.field.name == "other_contacts" %}
|
||||||
|
<div class="readonly">
|
||||||
|
{% for contact in field.contents|split:", " %}
|
||||||
|
<a href="#" class="other-contact__{{forloop.counter}}">{{ contact }}</a>{% if not forloop.last %}, {% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% elif field.field.name == "current_websites" %}
|
||||||
|
{% comment %}
|
||||||
|
The "website" model is essentially just a text field.
|
||||||
|
It is not useful to be redirected to the object definition,
|
||||||
|
rather it is more useful in this scenario to be redirected to the
|
||||||
|
actual website (as its just a plaintext string otherwise).
|
||||||
|
|
||||||
|
This ONLY applies to analysts. For superusers, its business as usual.
|
||||||
|
{% endcomment %}
|
||||||
|
{% for website in field.contents|split:", " %}
|
||||||
|
<a href="{{ website }}" class="padding-top-1 current-website__{{forloop.counter}}">{{ website }}</a>{% if not forloop.last %}, {% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<div class="readonly">{{ field.contents }}</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock field_readonly %}
|
||||||
|
|
||||||
|
{% block after_help_text %}
|
||||||
|
{% if field.field.name == "creator" %}
|
||||||
|
{% include "django/admin/includes/contact_detail_table.html" with user=original.creator field_name="creator" %}
|
||||||
|
{% elif field.field.name == "submitter" %}
|
||||||
|
{% include "django/admin/includes/contact_detail_table.html" with user=original.submitter field_name="submitter" %}
|
||||||
|
{% elif field.field.name == "authorizing_official" %}
|
||||||
|
{% include "django/admin/includes/contact_detail_table.html" with user=original.authorizing_official field_name="authorizing_official" %}
|
||||||
|
{% elif field.field.name == "other_contacts" and original.other_contacts.all %}
|
||||||
|
<details class="margin-top-1 dja-detail-table">
|
||||||
|
<summary class="padding-1 dja-details-summary">Details</summary>
|
||||||
|
<div class="grid-container padding-left-0 padding-right-0 dja-details-contents">
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
{% for contact in original.other_contacts.all %}
|
||||||
|
{% comment %}
|
||||||
|
Since we can't get the id from field, we can embed this information here.
|
||||||
|
Then we can link these two fields using javascript.
|
||||||
|
{% endcomment %}
|
||||||
|
<tr data-contact-id="{{ contact.id }}" data-contact-url="{% url 'admin:registrar_contact_change' contact.id %}">
|
||||||
|
<th scope="row">{{contact.first_name}} {{contact.last_name}}</th>
|
||||||
|
<td>{{ contact.title }}</td>
|
||||||
|
<td>{{ contact.email }}</td>
|
||||||
|
<td>{{ contact.phone }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock after_help_text %}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{% extends "django/admin/includes/detail_table_fieldset.html" %}
|
||||||
|
|
||||||
|
{% block after_help_text %}
|
||||||
|
<div>TESTING123</div>
|
||||||
|
{% endblock after_help_text %}
|
|
@ -1,87 +1 @@
|
||||||
{% extends "admin/fieldset.html" %}
|
{% extends "django/admin/includes/detail_table_fieldset.html" %}
|
||||||
{% load static url_helpers %}
|
|
||||||
{% comment %}
|
|
||||||
This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
|
||||||
{% endcomment %}
|
|
||||||
{% block fieldset_lines %}
|
|
||||||
{% for line in fieldset %}
|
|
||||||
<div class="form-row{% if line.fields|length == 1 and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
|
|
||||||
{% if line.fields|length == 1 %}{{ line.errors }}{% else %}<div class="flex-container form-multiline">{% endif %}
|
|
||||||
{% for field in line %}
|
|
||||||
<div>
|
|
||||||
{% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %}
|
|
||||||
<div class="flex-container{% if not line.fields|length == 1 %} fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}{% elif field.is_checkbox %} checkbox-row{% endif %}">
|
|
||||||
{% if field.is_checkbox %}
|
|
||||||
{{ field.field }}{{ field.label_tag }}
|
|
||||||
{% else %}
|
|
||||||
{{ field.label_tag }}
|
|
||||||
{% if field.is_readonly %}
|
|
||||||
{% if field.field.name == "other_contacts" %}
|
|
||||||
<div class="readonly">
|
|
||||||
{% for contact in field.contents|split:", " %}
|
|
||||||
<a href="#" class="other-contact__{{forloop.counter}}">{{ contact }}</a>{% if not forloop.last %}, {% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% elif field.field.name == "current_websites" %}
|
|
||||||
{% comment %}
|
|
||||||
The "website" model is essentially just a text field.
|
|
||||||
It is not useful to be redirected to the object definition,
|
|
||||||
rather it is more useful in this scenario to be redirected to the
|
|
||||||
actual website (as its just a plaintext string otherwise).
|
|
||||||
|
|
||||||
This ONLY applies to analysts. For superusers, its business as usual.
|
|
||||||
{% endcomment %}
|
|
||||||
{% for website in field.contents|split:", " %}
|
|
||||||
<a href="{{ website }}" class="padding-top-1 current-website__{{forloop.counter}}">{{ website }}</a>{% if not forloop.last %}, {% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% else %}
|
|
||||||
<div class="readonly">{{ field.contents }}</div>
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
|
||||||
{{ field.field }}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if field.field.help_text %}
|
|
||||||
<div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
|
|
||||||
<div>{{ field.field.help_text|safe }}</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if field.field.name == "creator" %}
|
|
||||||
{% include "django/admin/includes/domain_request_detail_table.html" with user=original.creator field_name="creator" %}
|
|
||||||
{% elif field.field.name == "submitter" %}
|
|
||||||
{% include "django/admin/includes/domain_request_detail_table.html" with user=original.submitter field_name="submitter" %}
|
|
||||||
{% elif field.field.name == "authorizing_official" %}
|
|
||||||
{% include "django/admin/includes/domain_request_detail_table.html" with user=original.authorizing_official field_name="authorizing_official" %}
|
|
||||||
{% elif field.field.name == "other_contacts" %}
|
|
||||||
<details class="margin-top-1 dja-detail-table">
|
|
||||||
<summary class="padding-1 dja-details-summary">Details</summary>
|
|
||||||
<div class="grid-container padding-left-0 padding-right-0 dja-details-contents">
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
{% for contact in original.other_contacts.all %}
|
|
||||||
{% comment %}
|
|
||||||
Since we can't get the id from field, we can embed this information here.
|
|
||||||
Then we can link these two fields using javascript.
|
|
||||||
{% endcomment %}
|
|
||||||
<tr data-contact-id="{{ contact.id }}" data-contact-url="{% url 'admin:registrar_contact_change' contact.id %}">
|
|
||||||
<th scope="row">{{contact.first_name}} {{contact.last_name}}</th>
|
|
||||||
<td>{{ contact.title }}</td>
|
|
||||||
<td>{{ contact.email }}</td>
|
|
||||||
<td>{{ contact.phone }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% if not line.fields|length == 1 %}</div>{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% endblock fieldset_lines %}
|
|
Loading…
Add table
Add a link
Reference in a new issue