Commit a0adb9d0 authored by Florent Chehab's avatar Florent Chehab

Validation of list operationnal

parent 8792340e
Pipeline #26800 passed with stages
in 2 minutes and 7 seconds
......@@ -17,10 +17,3 @@ def check_required(config, content):
raise missing_field(field)
except KeyError:
raise missing_field(field)
def check_coherence(config, content):
for field in content:
if field not in config:
raise ValidationError(
"{} : this field is not supposed to be there".format(field))
......@@ -14,7 +14,8 @@ class TaggedItem(BasicModule):
class TaggedItemSerializer(BasicModuleSerializer):
def validate(self, attrs):
return tagged_item_validation(attrs)
tagged_item_validation(attrs)
return attrs
class TaggedItemViewSet(BasicModuleViewSet):
......
from .checks import check_required, check_coherence
from .checks import check_required
from .validators import validate_url, validate_text
from rest_framework.validators import ValidationError
def tagged_item_validation(attrs):
tag_config = attrs["tag"].config
sumbitted_content = attrs["custom_content"]
check_coherence(tag_config, sumbitted_content)
check_required(tag_config, sumbitted_content)
validate_content_against_config(tag_config, sumbitted_content)
# Then, field validation
for field in sumbitted_content:
field_submitted = sumbitted_content[field]
field_config = tag_config[field]
def validate_content_against_config(config, content):
check_required(config, content)
for field in content:
if field not in config:
raise ValidationError(
"{} : this field is not supposed to be there".format(field))
field_submitted = content[field]
field_config = config[field]
field_type = field_config['type']
if field_type == 'url':
validate_url(field_config, field_submitted)
elif field_type == 'text':
validate_text(field_config, field_submitted)
elif field_type == 'list':
if type(field_submitted) is not list:
raise ValidationError("A list is required here !")
for item in field_submitted:
validate_content_against_config(field_config['content'], item)
else:
raise Exception("Dev, you have implement something here...")
return attrs
# my_tag_config = {
# "url": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment