Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
steering
Commits
6b04d154
Verified
Commit
6b04d154
authored
9 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
refactor: extract validate_value to avoid repetition
parent
c41322a6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/models.py
+12
-12
12 additions, 12 deletions
program/models.py
with
12 additions
and
12 deletions
program/models.py
+
12
−
12
View file @
6b04d154
...
@@ -577,16 +577,22 @@ class ImageShapeField(models.CharField):
...
@@ -577,16 +577,22 @@ class ImageShapeField(models.CharField):
super
().
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
def
validate_value
(
value
:
list
|
dict
,
schema
:
dict
)
->
None
:
"""
Validates value against the schema. Raises a `DjangoValidationError` if it is invalid.
"""
try
:
jsonschema
.
validate
(
instance
=
value
,
schema
=
schema
)
except
jsonschema
.
exceptions
.
ValidationError
as
e
:
raise
DjangoValidationError
(
e
.
args
[
0
])
def
validate_cba_domains
(
value
):
def
validate_cba_domains
(
value
):
schema
=
{
schema
=
{
"
type
"
:
"
array
"
,
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
string
"
},
"
items
"
:
{
"
type
"
:
"
string
"
},
}
}
try
:
validate_value
(
value
,
schema
)
jsonschema
.
validate
(
value
,
schema
)
except
jsonschema
.
exceptions
.
ValidationError
as
e
:
raise
DjangoValidationError
(
e
.
args
[
0
])
def
validate_line_in_channels
(
value
):
def
validate_line_in_channels
(
value
):
...
@@ -597,10 +603,7 @@ def validate_line_in_channels(value):
...
@@ -597,10 +603,7 @@ def validate_line_in_channels(value):
},
},
}
}
try
:
validate_value
(
value
,
schema
)
jsonschema
.
validate
(
value
,
schema
)
except
jsonschema
.
exceptions
.
ValidationError
as
e
:
raise
DjangoValidationError
(
e
.
args
[
0
])
def
validate_fallback_pools
(
value
):
def
validate_fallback_pools
(
value
):
...
@@ -611,10 +614,7 @@ def validate_fallback_pools(value):
...
@@ -611,10 +614,7 @@ def validate_fallback_pools(value):
},
},
}
}
try
:
validate_value
(
value
,
schema
)
jsonschema
.
validate
(
value
,
schema
)
except
jsonschema
.
exceptions
.
ValidationError
as
e
:
raise
DjangoValidationError
(
e
.
args
[
0
])
class
RadioSettings
(
models
.
Model
):
class
RadioSettings
(
models
.
Model
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment