diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-19 20:08:16 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-19 20:08:16 +0100 | 
| commit | a9d9b977778068d2609342d2749123618108e9d7 (patch) | |
| tree | 35a98f2c25a922d1e24c9e29c4b0fe76c9a81593 /ishtar_common/forms.py | |
| parent | 986725aacb88131471ffe61a3a2e32c57408a05b (diff) | |
| download | Ishtar-a9d9b977778068d2609342d2749123618108e9d7.tar.bz2 Ishtar-a9d9b977778068d2609342d2749123618108e9d7.zip  | |
Custom forms: admin forms
Diffstat (limited to 'ishtar_common/forms.py')
| -rw-r--r-- | ishtar_common/forms.py | 27 | 
1 files changed, 27 insertions, 0 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index d0c2bb035..0f1fa20f8 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -302,6 +302,33 @@ class CustomForm(object):      form_admin_name = ""      form_slug = "" +    def __init__(self, *args, **kwargs): +        super(CustomForm, self).__init__(*args, **kwargs) +        # todo: filter by user / group... +        q = models.CustomForm.objects.filter(form=self.form_slug, +                                             available=True, apply_to_all=True) +        if not q.count(): +            return +        # todo: prevent multiple result in database +        form = q.all()[0] +        for excluded in form.excluded_fields.all(): +            # could have be filtered previously +            if excluded.field in self.fields: +                self.fields.pop(excluded.field) + +    @classmethod +    def get_custom_fields(cls): +        fields = cls.base_fields +        customs = [] +        for key in fields: +            field = fields[key] +            # cannot customize display of required and hidden field +            # field with no label are also rejected +            if field.required or field.widget.is_hidden or not field.label: +                continue +            customs.append((key, field.label)) +        return sorted(customs, key=lambda x: x[1]) +  class DocumentGenerationForm(forms.Form):      """  | 
