Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Rex Dri
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
42
Issues
42
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rex Dri
Rex Dri
Commits
4a48c1ce
Commit
4a48c1ce
authored
Aug 20, 2018
by
Florent Chehab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation error changed from djago to REST framework to prevent crashs
Errors are returned as JSON when used with API
parent
7fc417da
Pipeline
#26331
passed with stages
in 1 minute and 23 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
8 deletions
+8
-8
rex/models/module/scholarship.py
rex/models/module/scholarship.py
+2
-2
rex/models/tools/usefullLinksField.py
rex/models/tools/usefullLinksField.py
+2
-3
rex/models/tools/validateWithRestFramework.py
rex/models/tools/validateWithRestFramework.py
+4
-3
No files found.
rex/models/module/scholarship.py
View file @
4a48c1ce
from
django.db
import
models
from
rex.models.module
import
BasicModule
from
rex.models.tools
import
Currency
from
django.core.exceptions
import
ValidationError
from
rest_framework
import
serializers
from
django.core.validators
import
MinValueValidator
...
...
@@ -24,7 +24,7 @@ class Scholarship(BasicModule):
# Need custom validation
def
clean
(
self
,
*
args
,
**
kwargs
):
if
self
.
amount_max
<
self
.
amount_min
:
raise
ValidationError
(
raise
serializers
.
ValidationError
(
"Amount_max should be greater or equal than amount_min"
)
super
(
Scholarship
,
self
)
.
clean
(
*
args
,
**
kwargs
)
...
...
rex/models/tools/usefullLinksField.py
View file @
4a48c1ce
from
django.contrib.postgres.fields
import
JSONField
from
django.core.exceptions
import
ValidationError
from
rest_framework
import
serializers
from
rex.models.tools.validateWithRestFramework
import
validate_with_rest_framework
...
...
@@ -21,7 +19,8 @@ def validate_usefull_links(value):
"""
if
type
(
value
)
is
not
list
:
raise
ValidationError
(
"Usefull links must be a JSON array !"
)
raise
serializers
.
ValidationError
(
"Usefull links must be a JSON array !"
)
for
obj
in
value
:
validate_with_rest_framework
(
UrlAndDescriptionSerializer
,
obj
)
...
...
rex/models/tools/validateWithRestFramework.py
View file @
4a48c1ce
from
django.core.exceptions
import
ValidationError
from
rest_framework
import
serializers
def
validate_with_rest_framework
(
serializer
,
value
):
...
...
@@ -10,11 +10,12 @@ def validate_with_rest_framework(serializer, value):
valid_ser
=
serializer
(
data
=
value
)
if
not
valid_ser
.
is_valid
():
raise
ValidationError
(
str
(
valid_ser
.
errors
))
raise
serializers
.
ValidationError
(
str
(
valid_ser
.
errors
))
# Also checks that no extra fields were added
if
type
(
value
)
is
not
list
:
allowed_keys
=
list
(
valid_ser
.
get_fields
())
for
key
in
value
.
keys
():
if
key
not
in
allowed_keys
:
raise
ValidationError
(
"Expected JSON schema not respected"
)
raise
serializers
.
ValidationError
(
"Expected JSON schema not respected"
)
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