Browse Source

Merge branch 'data_migrations' of gimli.ms.mff.cuni.cz:/akce/mam/git/mamweb into data_migrations

export_seznamu_prednasek
Kateřina Č 4 years ago
parent
commit
f82ac3f5b1
  1. 2
      mamweb/routers.py
  2. 2
      seminar/models.py
  3. 42
      seminar/views/views_rest.py
  4. 21
      seminar/viewsets.py

2
mamweb/routers.py

@ -4,10 +4,12 @@ from seminar import viewsets as vs
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'ulohavzoraknode', vs.UlohaVzorakNodeViewSet,basename='ulohavzoraknode') router.register(r'ulohavzoraknode', vs.UlohaVzorakNodeViewSet,basename='ulohavzoraknode')
router.register(r'reseninode', vs.ReseniNodeViewSet,basename='reseninode')
router.register(r'text', vs.TextViewSet) router.register(r'text', vs.TextViewSet)
router.register(r'textnode', vs.TextNodeViewSet) router.register(r'textnode', vs.TextNodeViewSet)
router.register(r'castnode', vs.CastNodeViewSet) router.register(r'castnode', vs.CastNodeViewSet)
router.register(r'problem', vs.ProblemViewSet, basename='problem') router.register(r'problem', vs.ProblemViewSet, basename='problem')
router.register(r'uloha', vs.UlohaViewSet, basename='uloha') router.register(r'uloha', vs.UlohaViewSet, basename='uloha')
router.register(r'reseni', vs.ReseniViewSet, basename='reseni')
router.register(r'ulohazadaninode', vs.UlohaZadaniNodeViewSet) router.register(r'ulohazadaninode', vs.UlohaZadaniNodeViewSet)

2
seminar/models.py

@ -1523,7 +1523,7 @@ class ReseniNode(TreeNode):
verbose_name = 'reseni') verbose_name = 'reseni')
def aktualizuj_nazev(self): def aktualizuj_nazev(self):
self.nazev = "OtisteneReseniNode: "+str(self.reseni) self.nazev = "ReseniNode: "+str(self.reseni)
def getOdkazStr(self): def getOdkazStr(self):
return str(self.reseni) return str(self.reseni)

42
seminar/views/views_rest.py

@ -22,6 +22,10 @@ class UlohaSerializer(serializers.ModelSerializer):
model = m.Uloha model = m.Uloha
fields = '__all__' fields = '__all__'
class ReseniSerializer(serializers.ModelSerializer):
class Meta:
model = m.Reseni
fields = '__all__'
class RocnikNodeSerializer(serializers.ModelSerializer): class RocnikNodeSerializer(serializers.ModelSerializer):
class Meta: class Meta:
@ -253,6 +257,44 @@ class ReseniNodeSerializer(serializers.ModelSerializer):
fields = '__all__' fields = '__all__'
depth = DEFAULT_NODE_DEPTH depth = DEFAULT_NODE_DEPTH
class ReseniNodeWriteSerializer(serializers.ModelSerializer):
reseni = serializers.PrimaryKeyRelatedField(queryset=m.Reseni.objects.all(), many=False, read_only=False)
class Meta:
model = m.ReseniNode
fields = ('id','reseni')
depth = DEFAULT_NODE_DEPTH
class ReseniNodeCreateSerializer(serializers.ModelSerializer):
reseni_id = serializers.IntegerField()
refnode = serializers.IntegerField()
where = serializers.CharField()
def create(self,validated_data):
# text_zadani = validated_data.pop('text_zadani')
reseni_id = validated_data.pop('reseni_id')
reseni = m.Reseni.objects.get(pk=reseni_id)
where = validated_data.pop('where')
refnode_id = validated_data.pop('refnode')
refnode = m.TreeNode.objects.get(pk=refnode_id)
# A vyrobime UlohaZadaniNode
if where == 'syn':
node = treelib.create_child(refnode,m.ReseniNode,reseni = reseni)
elif where == 'za':
node = treelib.create_node_after(refnode,m.ReseniNode,reseni = reseni)
elif where == 'pred':
node = treelib.create_node_before(refnode,m.ReseniNode,reseni = reseni)
node.where = None
node.refnode = None
node.reseni_id = None
return node
class Meta:
model = m.ReseniNode
fields = ('reseni_id','where','refnode')
depth = DEFAULT_NODE_DEPTH
class TreeNodeSerializer(PolymorphicSerializer): class TreeNodeSerializer(PolymorphicSerializer):
model_serializer_mapping = { model_serializer_mapping = {

21
seminar/viewsets.py

@ -110,6 +110,20 @@ class UlohaVzorakNodeViewSet(PermissionMixin, ReadWriteSerializerMixin, viewsets
queryset = queryset.filter(nadproblem__pk = nadproblem) queryset = queryset.filter(nadproblem__pk = nadproblem)
return queryset return queryset
class ReseniViewSet(viewsets.ModelViewSet):
serializer_class = views.ReseniSerializer
def get_queryset(self):
queryset = m.Reseni.objects.all()
#FIXME upravit nazvy dle skutecnych polozek reseni
nazev = self.request.query_params.get('nazev',None)
if nazev is not None:
queryset = queryset.filter(nazev__contains=nazev)
nadproblem = self.request.query_params.get('nadproblem',None)
if nadproblem is not None:
queryset = queryset.filter(nadproblem__pk = nadproblem)
return queryset
class UlohaViewSet(viewsets.ModelViewSet): class UlohaViewSet(viewsets.ModelViewSet):
serializer_class = views.UlohaSerializer serializer_class = views.UlohaSerializer
@ -129,6 +143,13 @@ class UlohaZadaniNodeViewSet(ReadWriteSerializerMixin, viewsets.ModelViewSet):
write_serializer_class = views.UlohaZadaniNodeWriteSerializer write_serializer_class = views.UlohaZadaniNodeWriteSerializer
create_serializer_class = views.UlohaZadaniNodeCreateSerializer create_serializer_class = views.UlohaZadaniNodeCreateSerializer
class ReseniNodeViewSet(ReadWriteSerializerMixin, viewsets.ModelViewSet):
queryset = m.ReseniNode.objects.all()
read_serializer_class = views.ReseniNodeSerializer
write_serializer_class = views.ReseniNodeWriteSerializer
create_serializer_class = views.ReseniNodeCreateSerializer
class ProblemViewSet(viewsets.ModelViewSet): class ProblemViewSet(viewsets.ModelViewSet):
serializer_class = views.ProblemSerializer serializer_class = views.ProblemSerializer

Loading…
Cancel
Save