diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-04-01 12:37:31 +0200 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-04-02 13:30:50 +0200 |
| commit | 986d6c2c372df1bf1962533e4a24080da4d79c8a (patch) | |
| tree | a49f4ebe21c1c2aec1201fa70cb2b0825613f64e /ishtar_common/forms.py | |
| parent | b78f0d10fd202ed9a1c4d3e508390d4329032b29 (diff) | |
| download | Ishtar-986d6c2c372df1bf1962533e4a24080da4d79c8a.tar.bz2 Ishtar-986d6c2c372df1bf1962533e4a24080da4d79c8a.zip | |
✨ general management of filter on types - filter qualification types for actors
Diffstat (limited to 'ishtar_common/forms.py')
| -rw-r--r-- | ishtar_common/forms.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 4db6a138b..416a1a9ec 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -707,8 +707,8 @@ class FieldType: self.empty_first = empty_first self.help_text = help_text - def get_choices(self, initial=None): - args = {"empty_first": self.empty_first, "initial": initial} + def get_choices(self, initial=None, limit=None): + args = {"empty_first": self.empty_first, "initial": initial, "limit": limit} if self.extra_args: args.update(self.extra_args) return self.model.get_types(**args) @@ -848,10 +848,14 @@ class IshtarForm(BSForm, forms.Form): for field in type_lst: self._init_type(field) - def _init_type(self, field): + def _init_type(self, field, extra=None): if field.key not in self.fields: return - self.fields[field.key].choices = field.get_choices() + if not extra: + extra = {} + if hasattr(self, "limits") and field.key in self.limits: + extra["limit"] = self.limits[field.key] + self.fields[field.key].choices = field.get_choices(**extra) if not getattr(field, "help_text", True): return self.fields[field.key].help_text = field.get_help() @@ -1349,10 +1353,7 @@ class ManageOldType(IshtarForm): if field.key not in self.fields: return initial = self.init_data.getlist(field.key) - self.fields[field.key].choices = field.get_choices( - initial=initial - ) - self.fields[field.key].help_text = field.get_help() + super()._init_type(field, extra={"initial": initial}) class QAForm(CustomForm, ManageOldType): |
