Commit 5720fd2f authored by GuiΩ's avatar GuiΩ
Browse files

fix(backend): correctly save 'validee' for Question

parent b40f5341
Pipeline #513669 failed with stages
in 3 minutes and 36 seconds
......@@ -2,7 +2,6 @@ import os
from django.db.models import Q
from rest_framework.fields import SerializerMethodField
from rest_framework.relations import PrimaryKeyRelatedField
from rest_framework.serializers import CharField, ModelSerializer, ValidationError
from am.models import Theme, Question, Feuille, Seance, QuestionPosee, Classe, QuestionOrder, LatexModel, LatexModelPart
......@@ -37,11 +36,13 @@ class LatexModelSerializer(ModelSerializer):
model = LatexModel
fields = ['id', 'label', 'description', 'file_name', 'position', 'type', 'parts']
class QuestionOrderSerializer(ModelSerializer):
class Meta:
model = QuestionOrder
fields = ['theme', 'position']
class QuestionSerializer(ModelSerializer):
editable = SerializerMethodField()
auteur = SerializerMethodField()
......@@ -68,16 +69,7 @@ class QuestionSerializer(ModelSerializer):
positions = {}
for theme in themes:
positions[theme['id']] = self.initial_data['positions'][theme['id']]
# positions[theme['id']] = theme['questionorder__position']
return positions
#
# def get_positions(self, question):
# themes = question.themes.values('id', 'questionorder__position')
# positions = {}
# for theme in themes:
# positions[theme['id']] = self.initial_data['positions'][theme['id']]
# # positions[theme['id']] = theme['questionorder__position']
# return positions
def get_auteur(self, question):
return question.auteur.username
......@@ -90,19 +82,17 @@ class QuestionSerializer(ModelSerializer):
return question
def update(self, instance, validated_data):
#fields = ['id', 'code', 'themes', 'thumb_name', 'editable', 'avalider', 'validee', 'auteur']
questionOrders = validated_data.pop('questionorder_set')
instance.code = validated_data.get('code', instance.code)
instance.thumb_name = validated_data.get('thumb_name', instance.thumb_name)
instance.avalider = validated_data.get('avalider', instance.avalider)
instance.validee = validated_data.get('editable', instance.validee)
instance.validee = validated_data.get('validee', instance.validee)
instance.save()
QuestionOrder.objects.filter(question=instance.id).delete();
QuestionOrder.objects.filter(question=instance.id).delete()
for qo in questionOrders:
QuestionOrder.objects.create(question=instance, theme=qo['theme'], position=qo['position']).save()
return instance
def validate(self, data):
question = self.instance
errors = {}
......@@ -202,7 +192,6 @@ class FeuilleSerializer(ModelSerializer):
read_only_fields = ['id']
class ThemeSerializer(ModelSerializer):
has_question = SerializerMethodField()
has_question_array = {}
......
......@@ -18,7 +18,7 @@ let config = {
.use(BundleTracker, [{filename: './webpack-stats.json'}])
config.output.filename("bundle.js");
if (process.env.NODE_ENV == 'production') {
if (process.env.NODE_ENV === 'production') {
} else {
config.devServer
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment