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
56b0c00d
Verified
Commit
56b0c00d
authored
9 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: add validation of cba_domains & line_in_channels
parent
a51c52d6
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
+39
-3
39 additions, 3 deletions
program/models.py
with
39 additions
and
3 deletions
program/models.py
+
39
−
3
View file @
56b0c00d
...
@@ -17,11 +17,12 @@
...
@@ -17,11 +17,12 @@
# You should have received a copy of the GNU Affero General Public License
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
import
jsonschema
from
rest_framework.exceptions
import
ValidationError
from
rest_framework.exceptions
import
ValidationError
from
versatileimagefield.fields
import
PPOIField
,
VersatileImageField
from
versatileimagefield.fields
import
PPOIField
,
VersatileImageField
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
as
DjangoValidationError
from
django.db
import
models
from
django.db
import
models
from
django.db.models
import
Max
,
Q
from
django.db.models
import
Max
,
Q
from
django.utils
import
timezone
from
django.utils
import
timezone
...
@@ -548,10 +549,40 @@ class ImageShapeField(models.CharField):
...
@@ -548,10 +549,40 @@ class ImageShapeField(models.CharField):
super
().
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
def
validate_cba_domains
(
value
):
schema
=
{
"
type
"
:
"
array
"
,
"
items
"
:
{
"
type
"
:
"
string
"
},
}
try
:
jsonschema
.
validate
(
value
,
schema
)
except
jsonschema
.
exceptions
.
ValidationError
as
e
:
raise
DjangoValidationError
(
e
.
args
[
0
])
def
validate_line_in_channels
(
value
):
schema
=
{
"
type
"
:
"
object
"
,
"
patternProperties
"
:
{
"
^.*$
"
:
{
"
type
"
:
"
string
"
},
},
}
try
:
jsonschema
.
validate
(
value
,
schema
)
except
jsonschema
.
exceptions
.
ValidationError
as
e
:
raise
DjangoValidationError
(
e
.
args
[
0
])
class
RadioSettings
(
models
.
Model
):
class
RadioSettings
(
models
.
Model
):
cba_api_key
=
models
.
CharField
(
blank
=
True
,
max_length
=
64
,
verbose_name
=
"
CBA API key
"
)
cba_api_key
=
models
.
CharField
(
blank
=
True
,
max_length
=
64
,
verbose_name
=
"
CBA API key
"
)
cba_domains
=
models
.
JSONField
(
cba_domains
=
models
.
JSONField
(
blank
=
True
,
default
=
list
,
help_text
=
"
JSON array of strings
"
,
verbose_name
=
"
CBA domains
"
blank
=
True
,
default
=
list
,
help_text
=
"
JSON array of strings
"
,
validators
=
[
validate_cba_domains
],
verbose_name
=
"
CBA domains
"
,
)
)
fallback_default_pool
=
models
.
CharField
(
blank
=
True
,
max_length
=
32
)
fallback_default_pool
=
models
.
CharField
(
blank
=
True
,
max_length
=
32
)
fallback_show
=
models
.
ForeignKey
(
fallback_show
=
models
.
ForeignKey
(
...
@@ -559,7 +590,12 @@ class RadioSettings(models.Model):
...
@@ -559,7 +590,12 @@ class RadioSettings(models.Model):
)
)
host_image_aspect_ratio
=
ImageAspectRadioField
(
default
=
"
1:1
"
)
host_image_aspect_ratio
=
ImageAspectRadioField
(
default
=
"
1:1
"
)
host_image_shape
=
ImageShapeField
(
default
=
"
round
"
)
host_image_shape
=
ImageShapeField
(
default
=
"
round
"
)
line_in_channels
=
models
.
JSONField
(
blank
=
True
,
default
=
dict
,
help_text
=
"
JSON key/value pairs
"
)
line_in_channels
=
models
.
JSONField
(
blank
=
True
,
default
=
dict
,
help_text
=
"
JSON key/value pairs
"
,
validators
=
[
validate_line_in_channels
],
)
micro_show
=
models
.
ForeignKey
(
micro_show
=
models
.
ForeignKey
(
Show
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
,
related_name
=
"
+
"
Show
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
,
related_name
=
"
+
"
)
)
...
...
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