mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-13 06:28:24 +02:00
Return ul rather than a list, fix bug
This commit is contained in:
parent
273cf91f76
commit
1b2b6e784e
4 changed files with 28 additions and 20 deletions
|
@ -2947,29 +2947,26 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
portfolio_type.short_description = "Portfolio type" # type: ignore
|
portfolio_type.short_description = "Portfolio type" # type: ignore
|
||||||
|
|
||||||
def suborganizations(self, obj: models.Portfolio):
|
def suborganizations(self, obj: models.Portfolio):
|
||||||
"""Returns a comma seperated list of links for each related suborg"""
|
"""Returns a list of links for each related suborg"""
|
||||||
queryset = obj.get_suborganizations()
|
queryset = obj.get_suborganizations()
|
||||||
sep = '<div class="display-block margin-top-1"></div>'
|
return self.get_field_links_as_list(queryset, "suborganization")
|
||||||
return self.get_field_links_as_csv(queryset, "suborganization", seperator=sep)
|
|
||||||
|
|
||||||
suborganizations.short_description = "Suborganizations" # type: ignore
|
suborganizations.short_description = "Suborganizations" # type: ignore
|
||||||
|
|
||||||
def domains(self, obj: models.Portfolio):
|
def domains(self, obj: models.Portfolio):
|
||||||
"""Returns a comma seperated list of links for each related domain"""
|
"""Returns a list of links for each related domain"""
|
||||||
queryset = obj.get_domains()
|
queryset = obj.get_domains()
|
||||||
sep = '<div class="display-block margin-top-1"></div>'
|
return self.get_field_links_as_list(
|
||||||
return self.get_field_links_as_csv(
|
queryset, "domaininformation", link_info_attribute="get_state_display_of_domain"
|
||||||
queryset, "domaininformation", link_info_attribute="get_state_display_of_domain", seperator=sep
|
|
||||||
)
|
)
|
||||||
|
|
||||||
domains.short_description = "Domains" # type: ignore
|
domains.short_description = "Domains" # type: ignore
|
||||||
|
|
||||||
def domain_requests(self, obj: models.Portfolio):
|
def domain_requests(self, obj: models.Portfolio):
|
||||||
"""Returns a comma seperated list of links for each related domain request"""
|
"""Returns a list of links for each related domain request"""
|
||||||
queryset = obj.get_domain_requests()
|
queryset = obj.get_domain_requests()
|
||||||
sep = '<div class="display-block margin-top-1"></div>'
|
return self.get_field_links_as_list(
|
||||||
return self.get_field_links_as_csv(
|
queryset, "domainrequest", link_info_attribute="get_status_display"
|
||||||
queryset, "domainrequest", link_info_attribute="get_status_display", seperator=sep
|
|
||||||
)
|
)
|
||||||
|
|
||||||
domain_requests.short_description = "Domain requests" # type: ignore
|
domain_requests.short_description = "Domain requests" # type: ignore
|
||||||
|
@ -2981,9 +2978,8 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
"senior_official",
|
"senior_official",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Q for reviewers: What should this be called?
|
def get_field_links_as_list(
|
||||||
def get_field_links_as_csv(
|
self, queryset, model_name, attribute_name=None, link_info_attribute=None, seperator=None
|
||||||
self, queryset, model_name, attribute_name=None, link_info_attribute=None, seperator=", "
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Generate HTML links for items in a queryset, using a specified attribute for link text.
|
Generate HTML links for items in a queryset, using a specified attribute for link text.
|
||||||
|
@ -2994,6 +2990,7 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
attribute_name: The attribute or method name to use for link text. If None, the item itself is used.
|
attribute_name: The attribute or method name to use for link text. If None, the item itself is used.
|
||||||
link_info_attribute: Appends f"({value_of_attribute})" to the end of the link.
|
link_info_attribute: Appends f"({value_of_attribute})" to the end of the link.
|
||||||
separator: The separator to use between links in the resulting HTML.
|
separator: The separator to use between links in the resulting HTML.
|
||||||
|
If none, an unordered list is returned.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A formatted HTML string with links to the admin change pages for each item.
|
A formatted HTML string with links to the admin change pages for each item.
|
||||||
|
@ -3014,8 +3011,17 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
if link_info_attribute:
|
if link_info_attribute:
|
||||||
link += f" ({self.value_of_attribute(item, link_info_attribute)})"
|
link += f" ({self.value_of_attribute(item, link_info_attribute)})"
|
||||||
|
|
||||||
links.append(link)
|
if seperator:
|
||||||
return format_html(seperator.join(links)) if links else "-"
|
links.append(link)
|
||||||
|
else:
|
||||||
|
links.append(f'<li>{link}</li>')
|
||||||
|
|
||||||
|
# If no seperator is specified, just return an unordered list.
|
||||||
|
if seperator:
|
||||||
|
return format_html(seperator.join(links)) if links else "-"
|
||||||
|
else:
|
||||||
|
links = "".join(links)
|
||||||
|
return format_html(f'<ul class="unstyled-list-elements">{links}</ul>') if links else "-"
|
||||||
|
|
||||||
def value_of_attribute(self, obj, attribute_name: str):
|
def value_of_attribute(self, obj, attribute_name: str):
|
||||||
"""Returns the value of getattr if the attribute isn't callable.
|
"""Returns the value of getattr if the attribute isn't callable.
|
||||||
|
|
|
@ -776,9 +776,6 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
let $federalAgency = django.jQuery("#id_federal_agency");
|
let $federalAgency = django.jQuery("#id_federal_agency");
|
||||||
let organizationType = document.getElementById("id_organization_type");
|
let organizationType = document.getElementById("id_organization_type");
|
||||||
if ($federalAgency && organizationType) {
|
if ($federalAgency && organizationType) {
|
||||||
// Execute this function once on load
|
|
||||||
handleFederalAgencyChange($federalAgency, organizationType);
|
|
||||||
|
|
||||||
// Attach the change event listener
|
// Attach the change event listener
|
||||||
$federalAgency.on("change", function() {
|
$federalAgency.on("change", function() {
|
||||||
handleFederalAgencyChange($federalAgency, organizationType);
|
handleFederalAgencyChange($federalAgency, organizationType);
|
||||||
|
|
|
@ -847,3 +847,9 @@ div.dja__model-description{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul.unstyled-list-elements {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ class Portfolio(TimeStampedModel):
|
||||||
unique=False,
|
unique=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Q for reviewers: shouldn't this be a required field?
|
|
||||||
organization_name = models.CharField(
|
organization_name = models.CharField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue