|
|
@ -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 = { |
|
|
|