diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 9 | ||||
-rw-r--r-- | ishtar_common/models_common.py | 1 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 33 |
3 files changed, 21 insertions, 22 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index b7d6004c3..cda01a048 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -5043,12 +5043,9 @@ class Document( # search parameters REVERSED_BOOL_FIELDS = ["image__isnull", "associated_file__isnull"] DATED_FIELDS = BaseHistorizedItem.DATED_FIELDS + [ - "receipt_date__lte", - "receipt_date__gte", - "receipt_date_in_documentation__lte", - "receipt_date_in_documentation__gte", - "creation_date__lte", - "creation_date__gte", + "receipt_date", + "receipt_date_in_documentation", + "creation_date", ] objects = ExternalIdManager() diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 7f7df4bfc..57c75d45d 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -1679,6 +1679,7 @@ class BaseHistorizedItem( "created", "last_modified", ] + DATETIME_FIELDS = ["created", "last_modified", "history_date"] BOOL_FIELDS = ["locked"] diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 444a157e4..cce6006af 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -1172,11 +1172,12 @@ for language_code, language_lbl in settings.LANGUAGES: deactivate() -def _manage_date(k, dct): +def _manage_date(k, dct, datetime_fields): """ Manage date from a search query :param k: date key :param dct: search dict + :param datetime_fields: list of known datetime fields to force conversion :return: None -> search dict is modified """ if not isinstance(dct[k], str): @@ -1235,23 +1236,21 @@ def _manage_date(k, dct): mins = [value for dt, value in results if dt == "gte"] maxs = [value for dt, value in results if dt == "lte"] eqs = [value for dt, value in results if dt == "eq"] - if eqs and not mins and not maxs: # TODO: min and max not available when using single dates - for datetime_field in BASE_DATETIME_FIELDS: - # manage exact date match on datetime field - if k.startswith(datetime_field): - dct.pop(k) - k = k + "__date" - break + dct.pop(k) + root_k = k.split("__")[-1] + if root_k in datetime_fields: + k += "__date" # force date conversion for datetime fields + if eqs and not mins and not maxs: + # TODO: min and max not available when using single dates dct[k] = ";".join(eqs) return - dct.pop(k) if mins: dct[k + "__gte"] = min(mins) if maxs: dct[k + "__lte"] = max(maxs) -def _manage_dated_fields(dated_fields, dct): +def _manage_dated_fields(dated_fields, datetime_fields, dct): keys = list(dct.keys()) for key in dated_fields: res = [j for j in keys if j.startswith(key)] @@ -1263,7 +1262,7 @@ def _manage_dated_fields(dated_fields, dct): if not dct[k]: dct.pop(k) continue - _manage_date(k, dct) + _manage_date(k, dct, datetime_fields) def _clean_type_val(val): @@ -2199,7 +2198,7 @@ def main_manager( request, model, query_own, full, dct, distinct_queries, query_parameters, my_relation_types_prefix, my_bool_fields, my_reversed_bool_fields, related_name_fields, many_counted_fields, reversed_many_counted_fields, - my_dated_fields, my_number_fields, and_reqs + my_dated_fields, datetime_fields, my_number_fields, and_reqs ): excluded_dct = {} or_reqs = [] @@ -2254,8 +2253,8 @@ def main_manager( filtered_dated_fields.append(field_name) my_dated_fields = filtered_dated_fields - _manage_dated_fields(my_dated_fields, dct) - _manage_dated_fields(my_dated_fields, excluded_dct) + _manage_dated_fields(my_dated_fields, datetime_fields, dct) + _manage_dated_fields(my_dated_fields, datetime_fields, excluded_dct) _manage_number_fields(my_number_fields, dct) _manage_number_fields(my_number_fields, excluded_dct) @@ -2328,7 +2327,7 @@ def manage_hierarchy_shorcut(model, request, query): DEFAULT_ROW_NUMBER = 10 # length is used by ajax DataTables requests EXCLUDED_FIELDS = ["length"] -BASE_DATETIME_FIELDS = ["created", "last_modified"] +BASE_DATED_FIELDS = ["created", "last_modified", "history_date"] def get_item( @@ -2477,7 +2476,8 @@ def get_item( my_dated_fields = model.DATED_FIELDS[:] else: my_dated_fields = dated_fields[:] if dated_fields else [] - my_dated_fields += BASE_DATETIME_FIELDS + my_dated_fields += BASE_DATED_FIELDS + datetime_fields = getattr(model, "DATETIME_FIELDS", []) if not associated_models and hasattr(model, "ASSOCIATED_MODELS"): my_associated_models = model.ASSOCIATED_MODELS[:] else: @@ -2773,6 +2773,7 @@ def get_item( many_counted_fields, reversed_many_counted_fields, my_dated_fields, + datetime_fields, my_number_fields, and_reqs[:] ) |