mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 03:06:01 +02:00
Update admin_form_order_helper.py
This commit is contained in:
parent
b389c9f831
commit
1371837103
1 changed files with 15 additions and 6 deletions
|
@ -10,9 +10,20 @@ class SortingDictInterface:
|
||||||
_sort_list: list[type] = []
|
_sort_list: list[type] = []
|
||||||
sorting_dict: Dict[type, type] = {}
|
sorting_dict: Dict[type, type] = {}
|
||||||
|
|
||||||
|
# _model_list and _sort_list can be
|
||||||
|
# any length, and will be called multiple times.
|
||||||
|
# We want the perf advantage of a dictionary,
|
||||||
|
# while making creating new SortingDictInterface
|
||||||
|
# items pretty straight forward and easy (aka as a list)
|
||||||
|
def convert_list_to_dict(self, value_list):
|
||||||
|
dictionary: Dict[type, type] = {}
|
||||||
|
for item in value_list:
|
||||||
|
dictionary[item] = item
|
||||||
|
return dictionary
|
||||||
|
|
||||||
def __init__(self, model_list, sort_list):
|
def __init__(self, model_list, sort_list):
|
||||||
self.sorting_dict = {
|
self.sorting_dict = {
|
||||||
"dropDownSelected": model_list,
|
"dropDownSelected": self.convert_list_to_dict(model_list),
|
||||||
"sortBy": sort_list
|
"sortBy": sort_list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,11 +44,9 @@ class AdminFormOrderHelper():
|
||||||
_order_by_list = []
|
_order_by_list = []
|
||||||
|
|
||||||
for item in self._sorting_dict:
|
for item in self._sorting_dict:
|
||||||
# Used to disable black as this is a false positive
|
drop_down_selected = item["dropDownSelected"]
|
||||||
# fmt: off
|
sort_by = item["sortBy"]
|
||||||
drop_down_selected = item.get("dropDownSelected")
|
|
||||||
# fmt: on
|
|
||||||
sort_by = item.get("sortBy")
|
|
||||||
if db_field.name in drop_down_selected:
|
if db_field.name in drop_down_selected:
|
||||||
_order_by_list = sort_by
|
_order_by_list = sort_by
|
||||||
break
|
break
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue