mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 17:47:02 +02:00
Stub pt 2
This commit is contained in:
parent
4243d19293
commit
ceabc16c73
3 changed files with 52 additions and 55 deletions
|
@ -2846,7 +2846,7 @@ class PortfolioAdmin(ListHeaderAdmin):
|
|||
fieldsets = [
|
||||
# TODO - this will need to be reworked
|
||||
#(None, {"fields": ["organization_name", "federal_agency", "creator", "created_at", "notes"]}),
|
||||
(None, {"fields": ["organization_name", "creator", "created_at", "notes"]}),
|
||||
(None, {"fields": ["portfolio_type", "organization_name", "creator", "created_at", "notes"]}),
|
||||
("Portfolio members", {"fields": ["administrators", "members"]}),
|
||||
("Portfolio domains", {"fields": ["domains", "domain_requests"]}),
|
||||
("Type of organization", {"fields": ["organization_type", "federal_type"]}),
|
||||
|
@ -2862,28 +2862,41 @@ class PortfolioAdmin(ListHeaderAdmin):
|
|||
search_help_text = "Search by organization name."
|
||||
readonly_fields = [
|
||||
"created_at",
|
||||
|
||||
# Custom fields such as these must be defined as readonly, even if they are not.
|
||||
# Custom fields such as these must be defined as readonly.
|
||||
"administrators",
|
||||
"members",
|
||||
"domains",
|
||||
"domain_requests",
|
||||
"suborganizations"
|
||||
"suborganizations",
|
||||
"federal_type",
|
||||
"portfolio_type",
|
||||
]
|
||||
|
||||
def portfolio_type(self, obj: models.Portfolio):
|
||||
org_choices = DomainRequest.OrganizationChoices
|
||||
org_type = org_choices.get_org_label(obj.organization_type)
|
||||
if obj.organization_type == org_choices.FEDERAL and obj.federal_agency:
|
||||
return " - ".join([org_type, obj.federal_agency.agency])
|
||||
else:
|
||||
return org_type
|
||||
portfolio_type.short_description = "Portfolio type"
|
||||
|
||||
def suborganizations(self, obj: models.Portfolio):
|
||||
queryset = obj.get_suborganizations()
|
||||
return self.get_links_csv(queryset, "suborganization")
|
||||
sep = '<div class="display-block margin-top-1"></div>'
|
||||
return self.get_links_csv(queryset, "suborganization", seperator=sep)
|
||||
suborganizations.short_description = "Suborganizations"
|
||||
|
||||
def domains(self, obj: models.Portfolio):
|
||||
queryset = obj.get_domains()
|
||||
return self.get_links_csv(queryset, "domaininformation")
|
||||
sep = '<div class="display-block margin-top-1"></div>'
|
||||
return self.get_links_csv(queryset, "domaininformation", seperator=sep)
|
||||
domains.short_description = "Domains"
|
||||
|
||||
def domain_requests(self, obj: models.Portfolio):
|
||||
queryset = obj.get_domain_requests()
|
||||
return self.get_links_csv(queryset, "domainrequest")
|
||||
sep = '<div class="display-block margin-top-1"></div>'
|
||||
return self.get_links_csv(queryset, "domainrequest", seperator=sep)
|
||||
domain_requests.short_description = "Domain requests"
|
||||
|
||||
def administrators(self, obj: models.Portfolio):
|
||||
|
@ -2902,8 +2915,8 @@ class PortfolioAdmin(ListHeaderAdmin):
|
|||
"federal_agency",
|
||||
]
|
||||
|
||||
# TODO change these names
|
||||
def get_links_csv(self, queryset, model_name, link_text_attribute=None):
|
||||
# Q for reviewers: What should this be called?
|
||||
def get_links_csv(self, queryset, model_name, link_text_attribute=None, seperator=", "):
|
||||
links = []
|
||||
for item in queryset:
|
||||
if link_text_attribute:
|
||||
|
@ -2914,26 +2927,14 @@ class PortfolioAdmin(ListHeaderAdmin):
|
|||
item_display_value = item
|
||||
|
||||
if item_display_value:
|
||||
link = self.get_html_change_link(model_name=model_name, object_id=item.pk, text_content=item_display_value)
|
||||
links.append(link)
|
||||
return format_html(", ".join(links))
|
||||
|
||||
def get_html_change_link(self, model_name, object_id, text_content):
|
||||
change_url = reverse(f"admin:registrar_{model_name}_change", args=[object_id])
|
||||
return f'<a href="{change_url}">{escape(text_content)}</a>'
|
||||
|
||||
change_url = reverse(f"admin:registrar_{model_name}_change", args=[item.pk])
|
||||
links.append(f'<a href="{change_url}">{escape(item_display_value)}</a>')
|
||||
return format_html(seperator.join(links))
|
||||
|
||||
def change_view(self, request, object_id, form_url="", extra_context=None):
|
||||
"""Add related suborganizations and domain groups"""
|
||||
obj = self.get_object(request, object_id)
|
||||
|
||||
# ---- Domain Groups
|
||||
domain_groups = DomainGroup.objects.filter(portfolio=obj)
|
||||
|
||||
# ---- Suborganizations
|
||||
suborganizations = Suborganization.objects.filter(portfolio=obj)
|
||||
|
||||
extra_context = {"domain_groups": domain_groups, "suborganizations": suborganizations}
|
||||
extra_context = {"administrators": obj.get_administrators(), "members": obj.get_members()}
|
||||
return super().change_view(request, object_id, form_url, extra_context)
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "django/admin/includes/email_clipboard_fieldset.html" %}
|
||||
{% load custom_filters %}
|
||||
{% load static url_helpers %}
|
||||
|
||||
{% block field_readonly %}
|
||||
{% if field.field.name == "members" %}
|
||||
{% comment %} Do nothing - for now {% endcomment %}
|
||||
<div class="readonly">{{ field.contents }}</div>
|
||||
{% else %}
|
||||
<div class="readonly">{{ field.contents }}</div>
|
||||
{% endif %}
|
||||
{% endblock field_readonly %}
|
||||
|
|
@ -1,34 +1,17 @@
|
|||
{% extends 'django/admin/email_clipboard_change_form.html' %}
|
||||
{% load i18n static %}
|
||||
|
||||
{% block after_related_objects %}
|
||||
<div class="module aligned padding-3">
|
||||
<h2>Associated groups and suborganizations</h2>
|
||||
<div class="grid-row grid-gap mobile:padding-x-1 desktop:padding-x-4">
|
||||
<div class="mobile:grid-col-12 tablet:grid-col-6 desktop:grid-col-4">
|
||||
<h3>Domain groups</h3>
|
||||
<ul class="margin-0 padding-0">
|
||||
{% for domain_group in domain_groups %}
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_domaingroup_change' domain_group.pk %}">
|
||||
{{ domain_group.name }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="mobile:grid-col-12 tablet:grid-col-6 desktop:grid-col-4">
|
||||
<h3>Suborganizations</h3>
|
||||
<ul class="margin-0 padding-0">
|
||||
{% for suborg in suborganizations %}
|
||||
<li>
|
||||
<a href="{% url 'admin:registrar_suborganization_change' suborg.pk %}">
|
||||
{{ suborg.name }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% block field_sets %}
|
||||
{% for fieldset in adminform %}
|
||||
{% comment %}
|
||||
TODO: this will eventually need to be changed to something like this
|
||||
if we ever want to customize this file:
|
||||
{% include "django/admin/includes/domain_information_fieldset.html" %}
|
||||
|
||||
Use detail_table_fieldset as an example, or just extend it.
|
||||
|
||||
original_object is just a variable name for "DomainInformation" or "DomainRequest"
|
||||
{% endcomment %}
|
||||
{% include "django/admin/includes/portfolio_fieldset.html" with original_object=original %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue