TreeNode editor | API pro reseni
This commit is contained in:
parent
c11abf3c7a
commit
e54f61e04d
4 changed files with 66 additions and 1 deletions
|
@ -4,10 +4,12 @@ from seminar import viewsets as vs
|
|||
router = routers.DefaultRouter()
|
||||
|
||||
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'textnode', vs.TextNodeViewSet)
|
||||
router.register(r'castnode', vs.CastNodeViewSet)
|
||||
router.register(r'problem', vs.ProblemViewSet, basename='problem')
|
||||
router.register(r'uloha', vs.UlohaViewSet, basename='uloha')
|
||||
router.register(r'reseni', vs.ReseniViewSet, basename='reseni')
|
||||
router.register(r'ulohazadaninode', vs.UlohaZadaniNodeViewSet)
|
||||
|
||||
|
|
|
@ -1523,7 +1523,7 @@ class ReseniNode(TreeNode):
|
|||
verbose_name = 'reseni')
|
||||
|
||||
def aktualizuj_nazev(self):
|
||||
self.nazev = "OtisteneReseniNode: "+str(self.reseni)
|
||||
self.nazev = "ReseniNode: "+str(self.reseni)
|
||||
|
||||
def getOdkazStr(self):
|
||||
return str(self.reseni)
|
||||
|
|
|
@ -22,6 +22,10 @@ class UlohaSerializer(serializers.ModelSerializer):
|
|||
model = m.Uloha
|
||||
fields = '__all__'
|
||||
|
||||
class ReseniSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = m.Reseni
|
||||
fields = '__all__'
|
||||
|
||||
class RocnikNodeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
@ -253,6 +257,44 @@ class ReseniNodeSerializer(serializers.ModelSerializer):
|
|||
fields = '__all__'
|
||||
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):
|
||||
model_serializer_mapping = {
|
||||
|
|
|
@ -110,6 +110,20 @@ class UlohaVzorakNodeViewSet(PermissionMixin, ReadWriteSerializerMixin, viewsets
|
|||
queryset = queryset.filter(nadproblem__pk = nadproblem)
|
||||
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):
|
||||
serializer_class = views.UlohaSerializer
|
||||
|
||||
|
@ -129,6 +143,13 @@ class UlohaZadaniNodeViewSet(ReadWriteSerializerMixin, viewsets.ModelViewSet):
|
|||
write_serializer_class = views.UlohaZadaniNodeWriteSerializer
|
||||
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):
|
||||
serializer_class = views.ProblemSerializer
|
||||
|
|
Loading…
Reference in a new issue