diff --git a/mamweb/routers.py b/mamweb/routers.py index f2a172cb..5a75d39d 100644 --- a/mamweb/routers.py +++ b/mamweb/routers.py @@ -7,4 +7,5 @@ router.register(r'ulohavzoraknode', vs.UlohaVzorakNodeViewSet,basename='ulohavzo router.register(r'text', vs.TextViewSet) router.register(r'textnode', vs.TextNodeViewSet) router.register(r'castnode', vs.CastNodeViewSet) +router.register(r'problem', vs.ProblemViewSet, basename='problem') diff --git a/seminar/migrations/0090_auto_20201110_1958.py b/seminar/migrations/0090_auto_20201110_1958.py new file mode 100644 index 00000000..97949f58 --- /dev/null +++ b/seminar/migrations/0090_auto_20201110_1958.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.12 on 2020-11-10 18:58 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0089_cislo_datum_preddeadline'), + ] + + operations = [ + migrations.AlterField( + model_name='textnode', + name='text', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='seminar.Text', verbose_name='text'), + ), + ] diff --git a/seminar/models.py b/seminar/models.py index cf8cd6a9..db9f67f9 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -1475,7 +1475,7 @@ class TextNode(TreeNode): verbose_name = 'Text (Node)' verbose_name_plural = 'Text (Node)' text = models.ForeignKey(Text, - on_delete=models.PROTECT, + on_delete=models.CASCADE, verbose_name = 'text') def aktualizuj_nazev(self): diff --git a/seminar/views/views_rest.py b/seminar/views/views_rest.py index aa3fca55..739c57c9 100644 --- a/seminar/views/views_rest.py +++ b/seminar/views/views_rest.py @@ -11,7 +11,10 @@ class TextSerializer(serializers.ModelSerializer): model = m.Text fields = '__all__' - +class ProblemSerializer(serializers.ModelSerializer): + class Meta: + model = m.Problem + fields = '__all__' class UlohaVzorakNodeSerializer(serializers.ModelSerializer): class Meta: diff --git a/seminar/viewsets.py b/seminar/viewsets.py index 8c83c067..67b13b3d 100644 --- a/seminar/viewsets.py +++ b/seminar/viewsets.py @@ -1,4 +1,8 @@ from rest_framework import viewsets,filters +from rest_framework import status +from rest_framework.response import Response +from django.core.exceptions import PermissionDenied + from . import models as m from . import views @@ -66,6 +70,14 @@ class CastNodeViewSet(ReadWriteSerializerMixin,viewsets.ModelViewSet): write_serializer_class = views.CastNodeSerializer create_serializer_class = views.CastNodeCreateSerializer + def destroy(self, request, *args, **kwargs): + obj = self.get_object() + print(obj) + if obj.first_child is None: + return super().destroy(request,*args,**kwargs) + raise PermissionDenied('Nelze smazat CastNode, který má děti!') + + class UlohaVzorakNodeViewSet(viewsets.ModelViewSet): serializer_class = views.UlohaVzorakNodeSerializer @@ -75,3 +87,10 @@ class UlohaVzorakNodeViewSet(viewsets.ModelViewSet): if nazev is not None: queryset = queryset.filter(nazev__contains=nazev) return queryset + +class ProblemViewSet(viewsets.ModelViewSet): + serializer_class = views.ProblemSerializer + + def get_queryset(self): + queryset = m.Problem.objects.all() + return queryset diff --git a/vue_frontend/src/components/CastNode.vue b/vue_frontend/src/components/CastNode.vue index 146bf5de..35390136 100644 --- a/vue_frontend/src/components/CastNode.vue +++ b/vue_frontend/src/components/CastNode.vue @@ -7,7 +7,9 @@