Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AKPlanning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KIF
AKPlanning
Commits
587838b8
Commit
587838b8
authored
4 months ago
by
Felix Blanke
Browse files
Options
Downloads
Patches
Plain Diff
Use schema to validate user JSON schedule
parent
3144bac3
No related branches found
No related tags found
1 merge request
!268
Merge fork for interoperability of KoMa solver
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
AKModel/forms.py
+20
-8
20 additions, 8 deletions
AKModel/forms.py
AKModel/locale/de_DE/LC_MESSAGES/django.po
+6
-2
6 additions, 2 deletions
AKModel/locale/de_DE/LC_MESSAGES/django.po
with
26 additions
and
10 deletions
AKModel/forms.py
+
20
−
8
View file @
587838b8
...
@@ -10,9 +10,11 @@ from django import forms
...
@@ -10,9 +10,11 @@ from django import forms
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.forms.utils
import
ErrorList
from
django.forms.utils
import
ErrorList
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
gettext_lazy
as
_
from
jsonschema.exceptions
import
best_match
from
AKModel.availability.forms
import
AvailabilitiesFormMixin
from
AKModel.availability.forms
import
AvailabilitiesFormMixin
from
AKModel.models
import
Event
,
AKCategory
,
AKRequirement
,
Room
,
AKType
from
AKModel.models
import
Event
,
AKCategory
,
AKRequirement
,
Room
,
AKType
from
AKModel.utils
import
construct_schema_validator
class
DateTimeInput
(
forms
.
DateInput
):
class
DateTimeInput
(
forms
.
DateInput
):
...
@@ -300,19 +302,29 @@ class JSONScheduleImportForm(AdminIntermediateForm):
...
@@ -300,19 +302,29 @@ class JSONScheduleImportForm(AdminIntermediateForm):
help_text
=
_
(
"
File with JSON data from the scheduling solver
"
),
help_text
=
_
(
"
File with JSON data from the scheduling solver
"
),
)
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
json_schema_validator
=
construct_schema_validator
(
schema
=
"
solver-output.schema.json
"
)
def
_check_json_data
(
self
,
data
:
str
):
def
_check_json_data
(
self
,
data
:
str
):
try
:
try
:
schedule
=
json
.
loads
(
data
)
schedule
=
json
.
loads
(
data
)
except
json
.
JSONDecodeError
as
ex
:
except
json
.
JSONDecodeError
as
ex
:
raise
ValidationError
(
_
(
"
Cannot decode as JSON
"
),
"
invalid
"
)
from
ex
raise
ValidationError
(
_
(
"
Cannot decode as JSON
"
),
"
invalid
"
)
from
ex
for
field
in
[
"
input
"
,
"
scheduled_aks
"
]:
if
not
field
in
schedule
:
error
=
best_match
(
self
.
json_schema_validator
.
iter_errors
(
schedule
))
if
error
:
raise
ValidationError
(
raise
ValidationError
(
_
(
"
Invalid JSON format:
field
'
%(field)s
'
is missing
"
),
_
(
"
Invalid JSON format:
%(msg)s at %(error_path)s
"
),
"
invalid
"
,
"
invalid
"
,
params
=
{
"
field
"
:
field
}
params
=
{
)
"
msg
"
:
error
.
message
,
# TODO: Add further checks on json input
"
error_path
"
:
error
.
json_path
}
)
from
error
return
schedule
return
schedule
def
clean
(
self
):
def
clean
(
self
):
...
...
This diff is collapsed.
Click to expand it.
AKModel/locale/de_DE/LC_MESSAGES/django.po
+
6
−
2
View file @
587838b8
...
@@ -303,8 +303,8 @@ msgstr "Dekodierung als JSON fehlgeschlagen"
...
@@ -303,8 +303,8 @@ msgstr "Dekodierung als JSON fehlgeschlagen"
#: AKModel/forms.py:311
#: AKModel/forms.py:311
#, python-format
#, python-format
msgid "Invalid JSON format:
field '%(field)s' is missing
"
msgid "Invalid JSON format:
%(msg)s at %(error_path)s
"
msgstr "Ungültige JSON-Eingabe:
das Feld '%(field)s' fehlt
"
msgstr "Ungültige JSON-Eingabe:
%(msg)s bei %(error_path)s
"
#: AKModel/forms.py:321
#: AKModel/forms.py:321
msgid "Please enter data as a file OR via text, not both."
msgid "Please enter data as a file OR via text, not both."
...
@@ -1495,6 +1495,10 @@ msgstr "Zu Anforderungen gehörige AKs anzeigen"
...
@@ -1495,6 +1495,10 @@ msgstr "Zu Anforderungen gehörige AKs anzeigen"
msgid "Event Status"
msgid "Event Status"
msgstr "Eventstatus"
msgstr "Eventstatus"
#, python-format
#~ msgid "Invalid JSON format: field '%(field)s' is missing"
#~ msgstr "Ungültige JSON-Eingabe: das Feld '%(field)s' fehlt"
#~ msgid "Opening time for expression of interest."
#~ msgid "Opening time for expression of interest."
#~ msgstr "Öffnungszeitpunkt für die Angabe von Interesse an AKs."
#~ msgstr "Öffnungszeitpunkt für die Angabe von Interesse an AKs."
...
...
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