|
@ -2,9 +2,17 @@ from rest_framework import serializers |
|
|
from rest_polymorphic.serializers import PolymorphicSerializer |
|
|
from rest_polymorphic.serializers import PolymorphicSerializer |
|
|
|
|
|
|
|
|
import seminar.models as m |
|
|
import seminar.models as m |
|
|
|
|
|
from seminar import treelib |
|
|
|
|
|
|
|
|
DEFAULT_NODE_DEPTH = 2 |
|
|
DEFAULT_NODE_DEPTH = 2 |
|
|
|
|
|
|
|
|
|
|
|
class TextSerializer(serializers.ModelSerializer): |
|
|
|
|
|
class Meta: |
|
|
|
|
|
model = m.Text |
|
|
|
|
|
fields = '__all__' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UlohaVzorakNodeSerializer(serializers.ModelSerializer): |
|
|
class UlohaVzorakNodeSerializer(serializers.ModelSerializer): |
|
|
class Meta: |
|
|
class Meta: |
|
|
model = m.UlohaVzorakNode |
|
|
model = m.UlohaVzorakNode |
|
@ -54,9 +62,44 @@ class PohadkaNodeSerializer(serializers.ModelSerializer): |
|
|
depth = DEFAULT_NODE_DEPTH |
|
|
depth = DEFAULT_NODE_DEPTH |
|
|
|
|
|
|
|
|
class TextNodeSerializer(serializers.ModelSerializer): |
|
|
class TextNodeSerializer(serializers.ModelSerializer): |
|
|
|
|
|
text = TextSerializer() |
|
|
|
|
|
|
|
|
class Meta: |
|
|
class Meta: |
|
|
model = m.TextNode |
|
|
model = m.TextNode |
|
|
fields = '__all__' |
|
|
fields = ('id','text','polymorphic_ctype') |
|
|
|
|
|
depth = DEFAULT_NODE_DEPTH |
|
|
|
|
|
|
|
|
|
|
|
class TextNodeWriteSerializer(serializers.ModelSerializer): |
|
|
|
|
|
text = TextSerializer() |
|
|
|
|
|
|
|
|
|
|
|
def update(self,node,validated_data): |
|
|
|
|
|
node.text.na_web = validated_data.get('text').get('na_web') |
|
|
|
|
|
return node |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
model = m.TextNode |
|
|
|
|
|
fields = ('id','text') |
|
|
|
|
|
depth = DEFAULT_NODE_DEPTH |
|
|
|
|
|
|
|
|
|
|
|
class TextNodeCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
|
text = TextSerializer() |
|
|
|
|
|
refnode = serializers.CharField() |
|
|
|
|
|
where = serializers.CharField() |
|
|
|
|
|
|
|
|
|
|
|
def create(self,validated_data): |
|
|
|
|
|
temp_text = validated_data.pop('text') |
|
|
|
|
|
where = validated_data.pop('where') |
|
|
|
|
|
refnode_id = validated_data.pop('refnode') |
|
|
|
|
|
refnode = m.TreeNode.objects.get(pk=refnode_id) |
|
|
|
|
|
text = m.Text.objects.create(**temp_text) |
|
|
|
|
|
node = treelib.create_child(refnode,m.TextNode,text=text) |
|
|
|
|
|
node.where = None |
|
|
|
|
|
node.refnode = None |
|
|
|
|
|
return node |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
model = m.TextNode |
|
|
|
|
|
fields = ('text','where','refnode') |
|
|
depth = DEFAULT_NODE_DEPTH |
|
|
depth = DEFAULT_NODE_DEPTH |
|
|
|
|
|
|
|
|
class CastNodeSerializer(serializers.ModelSerializer): |
|
|
class CastNodeSerializer(serializers.ModelSerializer): |
|
@ -85,5 +128,5 @@ class TreeNodeSerializer(PolymorphicSerializer): |
|
|
m.TextNode: TextNodeSerializer, |
|
|
m.TextNode: TextNodeSerializer, |
|
|
m.CastNode: CastNodeSerializer, |
|
|
m.CastNode: CastNodeSerializer, |
|
|
m.ReseniNode: ReseniNodeSerializer, |
|
|
m.ReseniNode: ReseniNodeSerializer, |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|