Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
a0adb9d0
Commit
a0adb9d0
authored
Aug 30, 2018
by
Florent Chehab
Browse files
Validation of list operationnal
parent
8792340e
Pipeline
#26800
passed with stages
in 2 minutes and 7 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/models/tag/checks.py
View file @
a0adb9d0
...
...
@@ -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
))
backend/models/tag/taggedItem.py
View file @
a0adb9d0
...
...
@@ -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
):
...
...
backend/models/tag/tagged_item_validation.py
View file @
a0adb9d0
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": {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment