diff options
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):      """  | 
