summaryrefslogtreecommitdiff
path: root/ishtar_common/models_common.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2026-04-01 12:37:31 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2026-04-01 16:10:17 +0200
commit136986832aee92b839c0628f7e5bbde22fe7d264 (patch)
treea31380e61e2c62282bda56fe9a205af3177407c6 /ishtar_common/models_common.py
parente8435aa231663776590d12b0517a08892dfd8f86 (diff)
downloadIshtar-136986832aee92b839c0628f7e5bbde22fe7d264.tar.bz2
Ishtar-136986832aee92b839c0628f7e5bbde22fe7d264.zip
✨ general management of filter on types - filter qualification types for actors
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r--ishtar_common/models_common.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index ba27b3bbc..117981e79 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -403,6 +403,7 @@ class GeneralType(Cached, models.Model):
initial=None,
force=False,
full_hierarchy=False,
+ limit=None
):
if not dct:
dct = {}
@@ -412,7 +413,8 @@ class GeneralType(Cached, models.Model):
if not instances and empty_first and not default:
types = [("", "--")]
types += cls._pre_get_types(
- dct, instances, exclude, default, force, get_full_hierarchy=full_hierarchy
+ dct, instances, exclude, default, force, get_full_hierarchy=full_hierarchy,
+ limit=limit
)
if not initial:
return types
@@ -421,6 +423,13 @@ class GeneralType(Cached, models.Model):
return types
@classmethod
+ def _set_limit(cls, dct, limit):
+ """
+ Translate limit set in forms to a query filter
+ """
+ raise NotImplementedError(f"_set_limit method must be set for {cls}")
+
+ @classmethod
def _pre_get_types(
cls,
dct=None,
@@ -429,6 +438,7 @@ class GeneralType(Cached, models.Model):
default=None,
force=False,
get_full_hierarchy=False,
+ limit=None
):
if not dct:
dct = {}
@@ -439,11 +449,15 @@ class GeneralType(Cached, models.Model):
if not instances:
keys = ["__get_types"]
keys += ["{}".format(ex) for ex in exclude] + ["{}".format(default)]
+ if limit:
+ keys.append("lim" + ";".join(limit))
keys += ["{}-{}".format(str(k), dct[k]) for k in dct]
cache_key, value = get_cache(cls, keys)
if value and not force:
return value
base_dct = dct.copy()
+ if limit:
+ cls._set_limit(base_dct, limit)
if hasattr(cls, "parent"):
if not cache_key:
return cls._get_parent_types(
@@ -467,7 +481,9 @@ class GeneralType(Cached, models.Model):
return vals
if not cache_key:
- return cls._get_types(base_dct, instances, exclude=exclude, default=default)
+ return cls._get_types(
+ base_dct, instances, exclude=exclude, default=default
+ )
vals = [
v
for v in cls._get_types(