-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Missing presets fields
In ContextFormSerializer presets are not represented. But it's needed in order to validate form from the schema or for UI representation.
https://github.com/novafloss/django-formidable/blob/master/formidable/serializers/forms.py#L64
For Information, Formidable provides different access based on the role of the current user about accessing some fields. The "ContextFormSerializer" provides the final representation of the form based on specific role
For example, let's imagine a form , which actually provides two fields.
=> full name , required for a padawan
=> weapons , hidden for padawan, required for a jedi
>>> Formidable = Formidable.objects.get(pk{id})
>>> schema = ContextFormSerializer(instance=formidable, context={'role': 'padawan'})
>>> 'weapons' in [field['slug'] for field in schema['fields']]
False
>>> print filter(lambda x: x['slug'] == 'fullname', schema['fields'])[0].required
True
>>> schema = ContextFormSerializer(instance=formidable, context={'role': 'jedi'})
>>> 'weapons' in [field['slug'] for field in schema['fields']]
True
>>> print filter(lambda x: x['slug'] == 'fullname', schema['fields'])[0].required
False
The serializer actually does not serialize a presentation of its presets.
What are presets ?
Presets are bunch of action pre-programmed inside the formidable projects. For the moment, presets are purely global validations on the built forms. For example, in order to compare two fields, etc.
Presets have already their own representation with the
https://github.com/novafloss/django-formidable/blob/master/formidable/serializers/presets.py#L104
Ensure to retrieve the presets associated to the formidable objects (tests it !)
You can inspire yourself from the FormidableSerializer
https://github.com/novafloss/django-formidable/blob/master/formidable/serializers/forms.py#L15
Tips: The FormidaleSerializer is a write/read serializer ContextFormSerializer in just a read-only serializer.