mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 19:20:47 +02:00
Logging
This commit is contained in:
parent
ee41a8ac73
commit
f55d5ef934
1 changed files with 34 additions and 32 deletions
|
@ -56,44 +56,46 @@ class MultiFieldSortableChangeList(admin.views.main.ChangeList):
|
||||||
Mostly identical to the base implementation, except that now it can return
|
Mostly identical to the base implementation, except that now it can return
|
||||||
a list of order_field objects rather than just one.
|
a list of order_field objects rather than just one.
|
||||||
"""
|
"""
|
||||||
params = self.params
|
logger.info("timing get_ordering")
|
||||||
ordering = list(self.model_admin.get_ordering(request) or self._get_default_ordering())
|
with Timer() as t:
|
||||||
|
params = self.params
|
||||||
|
ordering = list(self.model_admin.get_ordering(request) or self._get_default_ordering())
|
||||||
|
|
||||||
if ORDER_VAR in params:
|
if ORDER_VAR in params:
|
||||||
# Clear ordering and used params
|
# Clear ordering and used params
|
||||||
ordering = []
|
ordering = []
|
||||||
|
|
||||||
order_params = params[ORDER_VAR].split(".")
|
order_params = params[ORDER_VAR].split(".")
|
||||||
for p in order_params:
|
for p in order_params:
|
||||||
try:
|
try:
|
||||||
none, pfx, idx = p.rpartition("-")
|
none, pfx, idx = p.rpartition("-")
|
||||||
field_name = self.list_display[int(idx)]
|
field_name = self.list_display[int(idx)]
|
||||||
|
|
||||||
order_fields = self.get_ordering_field(field_name)
|
order_fields = self.get_ordering_field(field_name)
|
||||||
|
|
||||||
if isinstance(order_fields, list):
|
if isinstance(order_fields, list):
|
||||||
for order_field in order_fields:
|
for order_field in order_fields:
|
||||||
if order_field:
|
if order_field:
|
||||||
ordering.append(pfx + order_field)
|
ordering.append(pfx + order_field)
|
||||||
else:
|
else:
|
||||||
ordering.append(pfx + order_fields)
|
ordering.append(pfx + order_fields)
|
||||||
|
|
||||||
except (IndexError, ValueError):
|
except (IndexError, ValueError):
|
||||||
continue # Invalid ordering specified, skip it.
|
continue # Invalid ordering specified, skip it.
|
||||||
|
|
||||||
# Add the given query's ordering fields, if any.
|
# Add the given query's ordering fields, if any.
|
||||||
ordering.extend(queryset.query.order_by)
|
ordering.extend(queryset.query.order_by)
|
||||||
|
|
||||||
# Ensure that the primary key is systematically present in the list of
|
# Ensure that the primary key is systematically present in the list of
|
||||||
# ordering fields so we can guarantee a deterministic order across all
|
# ordering fields so we can guarantee a deterministic order across all
|
||||||
# database backends.
|
# database backends.
|
||||||
pk_name = self.lookup_opts.pk.name
|
pk_name = self.lookup_opts.pk.name
|
||||||
if not (set(ordering) & set(["pk", "-pk", pk_name, "-" + pk_name])):
|
if not (set(ordering) & set(["pk", "-pk", pk_name, "-" + pk_name])):
|
||||||
# The two sets do not intersect, meaning the pk isn't present. So
|
# The two sets do not intersect, meaning the pk isn't present. So
|
||||||
# we add it.
|
# we add it.
|
||||||
ordering.append("-pk")
|
ordering.append("-pk")
|
||||||
|
|
||||||
return ordering
|
return ordering
|
||||||
|
|
||||||
|
|
||||||
class CustomLogEntryAdmin(LogEntryAdmin):
|
class CustomLogEntryAdmin(LogEntryAdmin):
|
||||||
|
@ -913,14 +915,14 @@ class DomainApplicationAdmin(ListHeaderAdmin):
|
||||||
# lists in filter_horizontal are not sorted properly, sort them
|
# lists in filter_horizontal are not sorted properly, sort them
|
||||||
# by website
|
# by website
|
||||||
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
||||||
logger.info("timing formfield_for_manytomany")
|
logger.info(f"timing formfield_for_manytomany -> {db_field.name}")
|
||||||
with Timer() as t:
|
with Timer() as t:
|
||||||
if db_field.name in {"current_websites", "alternative_domains"}:
|
if db_field.name in {"current_websites", "alternative_domains"}:
|
||||||
kwargs["queryset"] = models.Website.objects.all().order_by("website") # Sort websites
|
kwargs["queryset"] = models.Website.objects.all().order_by("website") # Sort websites
|
||||||
return super().formfield_for_manytomany(db_field, request, **kwargs)
|
return super().formfield_for_manytomany(db_field, request, **kwargs)
|
||||||
|
|
||||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
logger.info("timing formfield_for_foreignkey")
|
logger.info(f"timing formfield_for_foreignkey -> {db_field.name}")
|
||||||
with Timer() as t:
|
with Timer() as t:
|
||||||
# Removes invalid investigator options from the investigator dropdown
|
# Removes invalid investigator options from the investigator dropdown
|
||||||
if db_field.name == "investigator":
|
if db_field.name == "investigator":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue