Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Backend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
swp-unisport
team-warumkeinrust
Backend
Commits
c135975b
Commit
c135975b
authored
3 years ago
by
borzechof99
Browse files
Options
Downloads
Patches
Plain Diff
Fixed Handling of empty data in views.smallquestionlistview
parent
67ba0952
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
unisportomat/quiz/serializers.py
+3
-3
3 additions, 3 deletions
unisportomat/quiz/serializers.py
unisportomat/quiz/views.py
+30
-5
30 additions, 5 deletions
unisportomat/quiz/views.py
with
33 additions
and
8 deletions
unisportomat/quiz/serializers.py
+
3
−
3
View file @
c135975b
...
@@ -236,13 +236,13 @@ class SingleQuestionSerializer(serializers.BaseSerializer):
...
@@ -236,13 +236,13 @@ class SingleQuestionSerializer(serializers.BaseSerializer):
# Test if Values exist
# Test if Values exist
if
"
text_de
"
in
data
.
keys
():
if
"
text_de
"
in
data
.
keys
():
validated_data
[
"
text_de
"
]
=
data
[
"
text_de
"
]
validated_data
[
"
text_de
"
]
=
data
[
"
text_de
"
]
or
""
if
"
text_en
"
in
data
.
keys
():
if
"
text_en
"
in
data
.
keys
():
validated_data
[
"
text_en
"
]
=
data
[
"
text_en
"
]
validated_data
[
"
text_en
"
]
=
data
[
"
text_en
"
]
or
""
if
"
criterion
"
in
data
.
keys
():
if
"
criterion
"
in
data
.
keys
():
validated_data
[
"
criterion
"
]
=
data
[
"
criterion
"
]
validated_data
[
"
criterion
"
]
=
data
[
"
criterion
"
]
or
""
return
validated_data
return
validated_data
...
...
This diff is collapsed.
Click to expand it.
unisportomat/quiz/views.py
+
30
−
5
View file @
c135975b
...
@@ -331,14 +331,19 @@ class SmallQuestionListView(viewsets.ViewSet):
...
@@ -331,14 +331,19 @@ class SmallQuestionListView(viewsets.ViewSet):
"
text_de
"
in
new_question_data
.
keys
()
"
text_de
"
in
new_question_data
.
keys
()
and
"
criterion
"
in
new_question_data
.
keys
()
and
"
criterion
"
in
new_question_data
.
keys
()
):
):
return
Response
(
status
=
400
)
return
Response
(
status
=
400
,
data
=
{
"
message
"
:
"
Deutsche Übersetzung und Kriterienname müssen ausgefüllt sein!
"
},
)
# Test if the Criterion already exists
# Test if the Criterion already exists
queryset
=
Criterion
.
objects
.
filter
(
name
=
new_question_data
[
"
criterion
"
])
queryset
=
Criterion
.
objects
.
filter
(
name
=
new_question_data
[
"
criterion
"
])
if
queryset
.
count
()
>
0
:
if
queryset
.
count
()
>
0
:
return
Response
(
return
Response
(
data
=
{
data
=
{
"
message
"
:
f
"
C
riteri
on with n
ame
{
new_question_data
[
'
criterion
'
]
}
already exists
"
"
message
"
:
f
"
K
riteri
um mit N
ame
n
{
new_question_data
[
'
criterion
'
]
}
existiert bereits!
"
},
},
status
=
400
,
status
=
400
,
)
)
...
@@ -385,6 +390,7 @@ class SmallQuestionListView(viewsets.ViewSet):
...
@@ -385,6 +390,7 @@ class SmallQuestionListView(viewsets.ViewSet):
and
"
text_en
"
in
new_question_data
.
keys
()
and
"
text_en
"
in
new_question_data
.
keys
()
and
"
criterion
"
in
new_question_data
.
keys
()
and
"
criterion
"
in
new_question_data
.
keys
()
):
):
# Check if another Criterion with the wanted name already exists
# Check if another Criterion with the wanted name already exists
queryset
=
Criterion
.
objects
.
filter
(
queryset
=
Criterion
.
objects
.
filter
(
name
=
new_question_data
[
"
criterion
"
]
name
=
new_question_data
[
"
criterion
"
]
...
@@ -393,17 +399,23 @@ class SmallQuestionListView(viewsets.ViewSet):
...
@@ -393,17 +399,23 @@ class SmallQuestionListView(viewsets.ViewSet):
if
queryset
.
count
()
>
0
:
if
queryset
.
count
()
>
0
:
return
Response
(
return
Response
(
data
=
{
data
=
{
"
message
"
:
f
"
C
riteri
on with n
ame
{
new_question_data
[
'
criterion
'
]
}
already exists
"
"
message
"
:
f
"
K
riteri
um mit N
ame
n
{
new_question_data
[
'
criterion
'
]
}
existiert bereits!
"
},
},
status
=
400
,
status
=
400
,
)
)
if
new_question_data
[
"
text_de
"
]
==
""
:
return
Response
(
status
=
400
,
data
=
{
"
message
"
:
"
Es muss eine deutsche Übersetzung geben!
"
},
)
question
.
criterion
.
name
=
new_question_data
[
"
criterion
"
]
question
.
criterion
.
name
=
new_question_data
[
"
criterion
"
]
question
.
text_de
=
new_question_data
[
"
text_de
"
]
question
.
text_de
=
new_question_data
[
"
text_de
"
]
question
.
text_en
=
new_question_data
[
"
text_en
"
]
question
.
text_en
=
new_question_data
[
"
text_en
"
]
else
:
else
:
return
Response
(
status
=
400
)
return
Response
(
status
=
400
,
data
=
{
"
message
"
:
"
Invalide Daten!
"
}
)
question
.
save
()
question
.
save
()
question
.
criterion
.
save
()
question
.
criterion
.
save
()
...
@@ -420,8 +432,21 @@ class SmallQuestionListView(viewsets.ViewSet):
...
@@ -420,8 +432,21 @@ class SmallQuestionListView(viewsets.ViewSet):
question
=
get_object_or_404
(
Question
,
pk
=
pk
)
question
=
get_object_or_404
(
Question
,
pk
=
pk
)
if
"
text_de
"
in
new_question_data
.
keys
():
if
new_question_data
[
"
text_de
"
]
==
""
:
return
Response
(
status
=
400
,
data
=
{
"
message
"
:
"
Es muss eine deutsche Übersetzung geben!
"
},
)
if
"
criterion
"
in
new_question_data
.
keys
():
if
"
criterion
"
in
new_question_data
.
keys
():
if
new_question_data
[
"
criterion
"
]
==
""
:
return
Response
(
status
=
400
,
data
=
{
"
message
"
:
"
Der Kriterienname darf nicht leer sein!
"
},
)
# Check if another Criterion with the wanted name already exists
# Check if another Criterion with the wanted name already exists
queryset
=
Criterion
.
objects
.
filter
(
queryset
=
Criterion
.
objects
.
filter
(
name
=
new_question_data
[
"
criterion
"
]
name
=
new_question_data
[
"
criterion
"
]
...
@@ -430,7 +455,7 @@ class SmallQuestionListView(viewsets.ViewSet):
...
@@ -430,7 +455,7 @@ class SmallQuestionListView(viewsets.ViewSet):
if
queryset
.
count
()
>
0
:
if
queryset
.
count
()
>
0
:
return
Response
(
return
Response
(
data
=
{
data
=
{
"
message
"
:
f
"
C
riteri
on with n
ame
{
new_question_data
[
'
criterion
'
]
}
already exists
"
"
message
"
:
f
"
K
riteri
um mit N
ame
n
{
new_question_data
[
'
criterion
'
]
}
existiert bereits!
"
},
},
status
=
400
,
status
=
400
,
)
)
...
...
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