Skip to content
Snippets Groups Projects
Commit c135975b authored by borzechof99's avatar borzechof99 :whale2:
Browse files

Fixed Handling of empty data in views.smallquestionlistview

parent 67ba0952
No related branches found
No related tags found
No related merge requests found
...@@ -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
......
...@@ -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"Criterion with name {new_question_data['criterion']} already exists" "message": f"Kriterium mit Namen {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"Criterion with name {new_question_data['criterion']} already exists" "message": f"Kriterium mit Namen {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"Criterion with name {new_question_data['criterion']} already exists" "message": f"Kriterium mit Namen {new_question_data['criterion']} existiert bereits!"
}, },
status=400, status=400,
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment