Podezřelé semináře (#1465) #65
|
@ -1,6 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from seminar.models import treenode as tm
|
from treenode import models as tm
|
||||||
from odevzdavatko.models import Reseni
|
from odevzdavatko.models import Reseni
|
||||||
|
|
||||||
class ReseniNode(tm.TreeNode):
|
class ReseniNode(tm.TreeNode):
|
||||||
|
|
|
@ -4,25 +4,26 @@ from django.forms import widgets
|
||||||
|
|
||||||
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter
|
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter
|
||||||
|
|
||||||
import seminar.models as m
|
from .models import TreeNode, RocnikNode, CisloNode, MezicisloNode, TemaVCisleNode, UlohaZadaniNode, PohadkaNode, UlohaVzorakNode, TextNode, CastNode, OrgTextNode
|
||||||
|
from .models.pomocne import Text, Obrazek
|
||||||
|
|
||||||
# Polymorfismus pro stromy
|
# Polymorfismus pro stromy
|
||||||
# TODO: Inlines podle https://django-polymorphic.readthedocs.io/en/stable/admin.html
|
# TODO: Inlines podle https://django-polymorphic.readthedocs.io/en/stable/admin.html
|
||||||
|
|
||||||
@admin.register(m.TreeNode)
|
@admin.register(TreeNode)
|
||||||
class TreeNodeAdmin(PolymorphicParentModelAdmin):
|
class TreeNodeAdmin(PolymorphicParentModelAdmin):
|
||||||
base_model = m.TreeNode
|
base_model = TreeNode
|
||||||
child_models = [
|
child_models = [
|
||||||
m.RocnikNode,
|
RocnikNode,
|
||||||
m.CisloNode,
|
CisloNode,
|
||||||
m.MezicisloNode,
|
MezicisloNode,
|
||||||
m.TemaVCisleNode,
|
TemaVCisleNode,
|
||||||
m.UlohaZadaniNode,
|
UlohaZadaniNode,
|
||||||
m.PohadkaNode,
|
PohadkaNode,
|
||||||
m.UlohaVzorakNode,
|
UlohaVzorakNode,
|
||||||
m.TextNode,
|
TextNode,
|
||||||
m.CastNode,
|
CastNode,
|
||||||
m.OrgTextNode,
|
OrgTextNode,
|
||||||
zelvuska marked this conversation as resolved
|
|||||||
]
|
]
|
||||||
|
|
||||||
actions = ['aktualizuj_nazvy']
|
actions = ['aktualizuj_nazvy']
|
||||||
|
@ -36,64 +37,64 @@ class TreeNodeAdmin(PolymorphicParentModelAdmin):
|
||||||
self.message_user(request, "Názvy aktualizovány.")
|
self.message_user(request, "Názvy aktualizovány.")
|
||||||
aktualizuj_nazvy.short_description = "Aktualizuj vybraným TreeNodům názvy"
|
aktualizuj_nazvy.short_description = "Aktualizuj vybraným TreeNodům názvy"
|
||||||
|
|
||||||
@admin.register(m.RocnikNode)
|
@admin.register(RocnikNode)
|
||||||
class RocnikNodeAdmin(PolymorphicChildModelAdmin):
|
class RocnikNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.RocnikNode
|
base_model = RocnikNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
@admin.register(m.CisloNode)
|
@admin.register(CisloNode)
|
||||||
class CisloNodeAdmin(PolymorphicChildModelAdmin):
|
class CisloNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.CisloNode
|
base_model = CisloNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
@admin.register(m.MezicisloNode)
|
@admin.register(MezicisloNode)
|
||||||
class MezicisloNodeAdmin(PolymorphicChildModelAdmin):
|
class MezicisloNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.MezicisloNode
|
base_model = MezicisloNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
@admin.register(m.TemaVCisleNode)
|
@admin.register(TemaVCisleNode)
|
||||||
class TemaVCisleNodeAdmin(PolymorphicChildModelAdmin):
|
class TemaVCisleNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.TemaVCisleNode
|
base_model = TemaVCisleNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
@admin.register(m.UlohaZadaniNode)
|
@admin.register(UlohaZadaniNode)
|
||||||
class UlohaZadaniNodeAdmin(PolymorphicChildModelAdmin):
|
class UlohaZadaniNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.UlohaZadaniNode
|
base_model = UlohaZadaniNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
@admin.register(m.PohadkaNode)
|
@admin.register(PohadkaNode)
|
||||||
class PohadkaNodeAdmin(PolymorphicChildModelAdmin):
|
class PohadkaNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.PohadkaNode
|
base_model = PohadkaNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
@admin.register(m.UlohaVzorakNode)
|
@admin.register(UlohaVzorakNode)
|
||||||
class UlohaVzorakNodeAdmin(PolymorphicChildModelAdmin):
|
class UlohaVzorakNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.UlohaVzorakNode
|
base_model = UlohaVzorakNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
@admin.register(m.TextNode)
|
@admin.register(TextNode)
|
||||||
class TextNodeAdmin(PolymorphicChildModelAdmin):
|
class TextNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.TextNode
|
base_model = TextNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
@admin.register(m.CastNode)
|
@admin.register(CastNode)
|
||||||
class TextNodeAdmin(PolymorphicChildModelAdmin):
|
class TextNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.CastNode
|
base_model = CastNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
fields = ('nadpis',)
|
fields = ('nadpis',)
|
||||||
|
|
||||||
@admin.register(m.OrgTextNode)
|
@admin.register(OrgTextNode)
|
||||||
class TextNodeAdmin(PolymorphicChildModelAdmin):
|
class TextNodeAdmin(PolymorphicChildModelAdmin):
|
||||||
base_model = m.OrgTextNode
|
base_model = OrgTextNode
|
||||||
show_in_index = True
|
show_in_index = True
|
||||||
|
|
||||||
|
|
||||||
class TextAdminInline(admin.TabularInline):
|
class TextAdminInline(admin.TabularInline):
|
||||||
model = m.Text
|
model = Text
|
||||||
formfield_overrides = {
|
formfield_overrides = {
|
||||||
models.TextField: {'widget': widgets.TextInput}
|
models.TextField: {'widget': widgets.TextInput}
|
||||||
}
|
}
|
||||||
exclude = ['text_zkraceny_set', 'text_zkraceny']
|
exclude = ['text_zkraceny_set', 'text_zkraceny']
|
||||||
|
|
||||||
admin.site.register(m.Text)
|
admin.site.register(Text)
|
||||||
admin.site.register(m.Obrazek)
|
admin.site.register(Obrazek)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
import seminar.models as m
|
from .models.pomocne import Obrazek
|
||||||
|
|
||||||
# pro přidání políčka do formuláře je potřeba
|
# pro přidání políčka do formuláře je potřeba
|
||||||
# - mít v modelu tu položku, kterou chci upravovat
|
# - mít v modelu tu položku, kterou chci upravovat
|
||||||
|
@ -10,5 +10,5 @@ import seminar.models as m
|
||||||
|
|
||||||
class NahrajObrazekKTreeNoduForm(forms.ModelForm):
|
class NahrajObrazekKTreeNoduForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.Obrazek
|
model = Obrazek
|
||||||
fields = ('na_web',)
|
fields = ('na_web',)
|
||||||
|
|
2
treenode/models/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
from seminar.models.odevzdavatko import *
|
||||||
|
from seminar.models.treenode import *
|
1
treenode/models/pomocne.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from seminar.models.pomocne import *
|
|
@ -1,7 +1,11 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_polymorphic.serializers import PolymorphicSerializer
|
from rest_polymorphic.serializers import PolymorphicSerializer
|
||||||
|
|
||||||
import seminar.models as m
|
from odevzdavatko.models import Reseni
|
||||||
|
from tvorba.models import Problem, Uloha
|
||||||
|
|
||||||
|
from .models import RocnikNode, CisloNode, MezicisloNode, TemaVCisleNode, OrgTextNode, PohadkaNode, TextNode, TreeNode, CastNode, UlohaZadaniNode, UlohaVzorakNode, ReseniNode
|
||||||
|
from .models.pomocne import Text
|
||||||
from treenode import treelib
|
from treenode import treelib
|
||||||
|
|
||||||
DEFAULT_NODE_DEPTH = 2
|
DEFAULT_NODE_DEPTH = 2
|
||||||
|
@ -9,57 +13,57 @@ DEFAULT_NODE_DEPTH = 2
|
||||||
|
|
||||||
class TextSerializer(serializers.ModelSerializer):
|
class TextSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.Text
|
model = Text
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
class ProblemSerializer(serializers.ModelSerializer):
|
class ProblemSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.Problem
|
model = Problem
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
class UlohaSerializer(serializers.ModelSerializer):
|
class UlohaSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.Uloha
|
model = Uloha
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
class ReseniSerializer(serializers.ModelSerializer):
|
class ReseniSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.Reseni
|
model = Reseni
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
class RocnikNodeSerializer(serializers.ModelSerializer):
|
class RocnikNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.RocnikNode
|
model = RocnikNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class CisloNodeSerializer(serializers.ModelSerializer):
|
class CisloNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.CisloNode
|
model = CisloNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class MezicisloNodeSerializer(serializers.ModelSerializer):
|
class MezicisloNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.MezicisloNode
|
model = MezicisloNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class TemaVCisleNodeSerializer(serializers.ModelSerializer):
|
class TemaVCisleNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.TemaVCisleNode
|
model = TemaVCisleNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class OrgTextNodeSerializer(serializers.ModelSerializer):
|
class OrgTextNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.OrgTextNode
|
model = OrgTextNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class PohadkaNodeSerializer(serializers.ModelSerializer):
|
class PohadkaNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.PohadkaNode
|
model = PohadkaNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -67,7 +71,7 @@ class TextNodeSerializer(serializers.ModelSerializer):
|
||||||
text = TextSerializer()
|
text = TextSerializer()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.TextNode
|
model = TextNode
|
||||||
fields = ('id','text','polymorphic_ctype')
|
fields = ('id','text','polymorphic_ctype')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -80,7 +84,7 @@ class TextNodeWriteSerializer(serializers.ModelSerializer):
|
||||||
return node
|
return node
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.TextNode
|
model = TextNode
|
||||||
fields = ('id','text')
|
fields = ('id','text')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -93,26 +97,26 @@ class TextNodeCreateSerializer(serializers.ModelSerializer):
|
||||||
temp_text = validated_data.pop('text')
|
temp_text = validated_data.pop('text')
|
||||||
where = validated_data.pop('where')
|
where = validated_data.pop('where')
|
||||||
refnode_id = validated_data.pop('refnode')
|
refnode_id = validated_data.pop('refnode')
|
||||||
refnode = m.TreeNode.objects.get(pk=refnode_id)
|
refnode = TreeNode.objects.get(pk=refnode_id)
|
||||||
text = m.Text.objects.create(**temp_text)
|
text = Text.objects.create(**temp_text)
|
||||||
if where == 'syn':
|
if where == 'syn':
|
||||||
node = treelib.create_child(refnode,m.TextNode,text=text)
|
node = treelib.create_child(refnode,TextNode,text=text)
|
||||||
elif where == 'za':
|
elif where == 'za':
|
||||||
node = treelib.create_node_after(refnode,m.TextNode,text=text)
|
node = treelib.create_node_after(refnode,TextNode,text=text)
|
||||||
elif where == 'pred':
|
elif where == 'pred':
|
||||||
node = treelib.create_node_before(refnode,m.TextNode,text=text)
|
node = treelib.create_node_before(refnode,TextNode,text=text)
|
||||||
node.where = None
|
node.where = None
|
||||||
node.refnode = None
|
node.refnode = None
|
||||||
return node
|
return node
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.TextNode
|
model = TextNode
|
||||||
fields = ('text','where','refnode')
|
fields = ('text','where','refnode')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class CastNodeSerializer(serializers.ModelSerializer):
|
class CastNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.CastNode
|
model = CastNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -124,25 +128,25 @@ class CastNodeCreateSerializer(serializers.ModelSerializer):
|
||||||
temp_nadpis = validated_data.pop('nadpis')
|
temp_nadpis = validated_data.pop('nadpis')
|
||||||
where = validated_data.pop('where')
|
where = validated_data.pop('where')
|
||||||
refnode_id = validated_data.pop('refnode')
|
refnode_id = validated_data.pop('refnode')
|
||||||
refnode = m.TreeNode.objects.get(pk=refnode_id)
|
refnode = TreeNode.objects.get(pk=refnode_id)
|
||||||
if where == 'syn':
|
if where == 'syn':
|
||||||
node = treelib.create_child(refnode,m.CastNode,nadpis=temp_nadpis)
|
node = treelib.create_child(refnode,CastNode,nadpis=temp_nadpis)
|
||||||
elif where == 'za':
|
elif where == 'za':
|
||||||
node = treelib.create_node_after(refnode,m.CastNode,nadpis=temp_nadpis)
|
node = treelib.create_node_after(refnode,CastNode,nadpis=temp_nadpis)
|
||||||
elif where == 'pred':
|
elif where == 'pred':
|
||||||
node = treelib.create_node_before(refnode,m.CastNode,nadpis=temp_nadpis)
|
node = treelib.create_node_before(refnode,CastNode,nadpis=temp_nadpis)
|
||||||
node.where = None
|
node.where = None
|
||||||
node.refnode = None
|
node.refnode = None
|
||||||
return node
|
return node
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.CastNode
|
model = CastNode
|
||||||
fields = ('nadpis','where','refnode')
|
fields = ('nadpis','where','refnode')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class UlohaZadaniNodeSerializer(serializers.ModelSerializer):
|
class UlohaZadaniNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.UlohaZadaniNode
|
model = UlohaZadaniNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -157,7 +161,7 @@ class UlohaZadaniNodeWriteSerializer(serializers.ModelSerializer):
|
||||||
return node
|
return node
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.TextNode
|
model = TextNode
|
||||||
fields = ('id','uloha')
|
fields = ('id','uloha')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -171,28 +175,28 @@ class UlohaZadaniNodeCreateSerializer(serializers.ModelSerializer):
|
||||||
temp_uloha = validated_data.pop('uloha')
|
temp_uloha = validated_data.pop('uloha')
|
||||||
where = validated_data.pop('where')
|
where = validated_data.pop('where')
|
||||||
refnode_id = validated_data.pop('refnode')
|
refnode_id = validated_data.pop('refnode')
|
||||||
refnode = m.TreeNode.objects.get(pk=refnode_id)
|
refnode = TreeNode.objects.get(pk=refnode_id)
|
||||||
|
|
||||||
# Z cesty ke koreni stromu zjistime, v jakem jsme tematu a v jakem cisle
|
# Z cesty ke koreni stromu zjistime, v jakem jsme tematu a v jakem cisle
|
||||||
cislo = None
|
cislo = None
|
||||||
tema = None
|
tema = None
|
||||||
travelnode = refnode
|
travelnode = refnode
|
||||||
while travelnode is not None:
|
while travelnode is not None:
|
||||||
if isinstance(travelnode, m.TemaVCisleNode):
|
if isinstance(travelnode, TemaVCisleNode):
|
||||||
tema = travelnode.tema
|
tema = travelnode.tema
|
||||||
if isinstance(travelnode, m.CisloNode):
|
if isinstance(travelnode, CisloNode):
|
||||||
cislo = travelnode.cislo
|
cislo = travelnode.cislo
|
||||||
travelnode = treelib.get_parent(travelnode)
|
travelnode = treelib.get_parent(travelnode)
|
||||||
# Vyrobime ulohu
|
# Vyrobime ulohu
|
||||||
uloha = m.Uloha.objects.create(cislo_zadani=cislo, nadproblem = tema, **temp_uloha)
|
uloha = Uloha.objects.create(cislo_zadani=cislo, nadproblem = tema, **temp_uloha)
|
||||||
|
|
||||||
# A vyrobime UlohaZadaniNode
|
# A vyrobime UlohaZadaniNode
|
||||||
if where == 'syn':
|
if where == 'syn':
|
||||||
node = treelib.create_child(refnode,m.UlohaZadaniNode,uloha = uloha)
|
node = treelib.create_child(refnode,UlohaZadaniNode,uloha = uloha)
|
||||||
elif where == 'za':
|
elif where == 'za':
|
||||||
node = treelib.create_node_after(refnode,m.UlohaZadaniNode,uloha = uloha)
|
node = treelib.create_node_after(refnode,UlohaZadaniNode,uloha = uloha)
|
||||||
elif where == 'pred':
|
elif where == 'pred':
|
||||||
node = treelib.create_node_before(refnode,m.UlohaZadaniNode,uloha = uloha)
|
node = treelib.create_node_before(refnode,UlohaZadaniNode,uloha = uloha)
|
||||||
node.where = None
|
node.where = None
|
||||||
node.refnode = None
|
node.refnode = None
|
||||||
node.max_body = None
|
node.max_body = None
|
||||||
|
@ -200,21 +204,21 @@ class UlohaZadaniNodeCreateSerializer(serializers.ModelSerializer):
|
||||||
return node
|
return node
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.UlohaZadaniNode
|
model = UlohaZadaniNode
|
||||||
fields = ('uloha','where','refnode')
|
fields = ('uloha','where','refnode')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class UlohaVzorakNodeSerializer(serializers.ModelSerializer):
|
class UlohaVzorakNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.UlohaVzorakNode
|
model = UlohaVzorakNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class UlohaVzorakNodeWriteSerializer(serializers.ModelSerializer):
|
class UlohaVzorakNodeWriteSerializer(serializers.ModelSerializer):
|
||||||
uloha = serializers.PrimaryKeyRelatedField(queryset=m.Uloha.objects.all(), many=False, read_only=False)
|
uloha = serializers.PrimaryKeyRelatedField(queryset=Uloha.objects.all(), many=False, read_only=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.UlohaVzorakNode
|
model = UlohaVzorakNode
|
||||||
fields = ('id','uloha')
|
fields = ('id','uloha')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -226,17 +230,17 @@ class UlohaVzorakNodeCreateSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
uloha_id = validated_data.pop('uloha_id')
|
uloha_id = validated_data.pop('uloha_id')
|
||||||
uloha = m.Uloha.objects.get(pk=uloha_id)
|
uloha = Uloha.objects.get(pk=uloha_id)
|
||||||
where = validated_data.pop('where')
|
where = validated_data.pop('where')
|
||||||
refnode_id = validated_data.pop('refnode')
|
refnode_id = validated_data.pop('refnode')
|
||||||
refnode = m.TreeNode.objects.get(pk=refnode_id)
|
refnode = TreeNode.objects.get(pk=refnode_id)
|
||||||
|
|
||||||
if where == 'syn':
|
if where == 'syn':
|
||||||
node = treelib.create_child(refnode,m.UlohaVzorakNode,uloha = uloha)
|
node = treelib.create_child(refnode,UlohaVzorakNode,uloha = uloha)
|
||||||
elif where == 'za':
|
elif where == 'za':
|
||||||
node = treelib.create_node_after(refnode,m.UlohaVzorakNode,uloha = uloha)
|
node = treelib.create_node_after(refnode,UlohaVzorakNode,uloha = uloha)
|
||||||
elif where == 'pred':
|
elif where == 'pred':
|
||||||
node = treelib.create_node_before(refnode,m.UlohaVzorakNode,uloha = uloha)
|
node = treelib.create_node_before(refnode,UlohaVzorakNode,uloha = uloha)
|
||||||
node.refnode = None
|
node.refnode = None
|
||||||
node.where = None
|
node.where = None
|
||||||
node.uloha_id = None
|
node.uloha_id = None
|
||||||
|
@ -244,7 +248,7 @@ class UlohaVzorakNodeCreateSerializer(serializers.ModelSerializer):
|
||||||
return node
|
return node
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.UlohaVzorakNode
|
model = UlohaVzorakNode
|
||||||
fields = ('refnode', 'uloha_id', 'where')
|
fields = ('refnode', 'uloha_id', 'where')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -253,15 +257,15 @@ class UlohaVzorakNodeCreateSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class ReseniNodeSerializer(serializers.ModelSerializer):
|
class ReseniNodeSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.ReseniNode
|
model = ReseniNode
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
class ReseniNodeWriteSerializer(serializers.ModelSerializer):
|
class ReseniNodeWriteSerializer(serializers.ModelSerializer):
|
||||||
reseni = serializers.PrimaryKeyRelatedField(queryset=m.Reseni.objects.all(), many=False, read_only=False)
|
reseni = serializers.PrimaryKeyRelatedField(queryset=Reseni.objects.all(), many=False, read_only=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.ReseniNode
|
model = ReseniNode
|
||||||
fields = ('id','reseni')
|
fields = ('id','reseni')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
@ -273,41 +277,41 @@ class ReseniNodeCreateSerializer(serializers.ModelSerializer):
|
||||||
def create(self,validated_data):
|
def create(self,validated_data):
|
||||||
# text_zadani = validated_data.pop('text_zadani')
|
# text_zadani = validated_data.pop('text_zadani')
|
||||||
reseni_id = validated_data.pop('reseni_id')
|
reseni_id = validated_data.pop('reseni_id')
|
||||||
reseni = m.Reseni.objects.get(pk=reseni_id)
|
reseni = Reseni.objects.get(pk=reseni_id)
|
||||||
where = validated_data.pop('where')
|
where = validated_data.pop('where')
|
||||||
refnode_id = validated_data.pop('refnode')
|
refnode_id = validated_data.pop('refnode')
|
||||||
refnode = m.TreeNode.objects.get(pk=refnode_id)
|
refnode = TreeNode.objects.get(pk=refnode_id)
|
||||||
|
|
||||||
# A vyrobime UlohaZadaniNode
|
# A vyrobime UlohaZadaniNode
|
||||||
if where == 'syn':
|
if where == 'syn':
|
||||||
node = treelib.create_child(refnode,m.ReseniNode,reseni = reseni)
|
node = treelib.create_child(refnode,ReseniNode,reseni = reseni)
|
||||||
elif where == 'za':
|
elif where == 'za':
|
||||||
node = treelib.create_node_after(refnode,m.ReseniNode,reseni = reseni)
|
node = treelib.create_node_after(refnode,ReseniNode,reseni = reseni)
|
||||||
elif where == 'pred':
|
elif where == 'pred':
|
||||||
node = treelib.create_node_before(refnode,m.ReseniNode,reseni = reseni)
|
node = treelib.create_node_before(refnode,ReseniNode,reseni = reseni)
|
||||||
node.where = None
|
node.where = None
|
||||||
node.refnode = None
|
node.refnode = None
|
||||||
node.reseni_id = None
|
node.reseni_id = None
|
||||||
return node
|
return node
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.ReseniNode
|
model = ReseniNode
|
||||||
fields = ('reseni_id','where','refnode')
|
fields = ('reseni_id','where','refnode')
|
||||||
depth = DEFAULT_NODE_DEPTH
|
depth = DEFAULT_NODE_DEPTH
|
||||||
|
|
||||||
|
|
||||||
class TreeNodeSerializer(PolymorphicSerializer):
|
class TreeNodeSerializer(PolymorphicSerializer):
|
||||||
model_serializer_mapping = {
|
model_serializer_mapping = {
|
||||||
m.RocnikNode: RocnikNodeSerializer,
|
RocnikNode: RocnikNodeSerializer,
|
||||||
m.CisloNode: CisloNodeSerializer,
|
CisloNode: CisloNodeSerializer,
|
||||||
m.MezicisloNode: MezicisloNodeSerializer,
|
MezicisloNode: MezicisloNodeSerializer,
|
||||||
m.TemaVCisleNode: TemaVCisleNodeSerializer,
|
TemaVCisleNode: TemaVCisleNodeSerializer,
|
||||||
m.OrgTextNode: OrgTextNodeSerializer,
|
OrgTextNode: OrgTextNodeSerializer,
|
||||||
m.UlohaZadaniNode: UlohaZadaniNodeSerializer,
|
UlohaZadaniNode: UlohaZadaniNodeSerializer,
|
||||||
m.UlohaVzorakNode: UlohaVzorakNodeSerializer,
|
UlohaVzorakNode: UlohaVzorakNodeSerializer,
|
||||||
m.PohadkaNode: PohadkaNodeSerializer,
|
PohadkaNode: PohadkaNodeSerializer,
|
||||||
m.TextNode: TextNodeSerializer,
|
TextNode: TextNodeSerializer,
|
||||||
m.CastNode: CastNodeSerializer,
|
CastNode: CastNodeSerializer,
|
||||||
m.ReseniNode: ReseniNodeSerializer,
|
ReseniNode: ReseniNodeSerializer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django import template
|
from django import template
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import seminar.models as m
|
from .models import RocnikNode, CisloNode, CastNode, TextNode, TemaVCisleNode, UlohaVzorakNode, UlohaZadaniNode, PohadkaNode
|
||||||
ledoian
commented
(Těchto TreeNodů je tu málo, ale nechce se mi teď zjišťovat, které tři chybí…) (Těchto TreeNodů je tu málo, ale nechce se mi teď zjišťovat, které tři chybí…)
|
|||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ def nodeType(value):
|
||||||
if isinstance(value,CastNode): return "Část"
|
if isinstance(value,CastNode): return "Část"
|
||||||
if isinstance(value,TextNode): return "Text"
|
if isinstance(value,TextNode): return "Text"
|
||||||
if isinstance(value,TemaVCisleNode): return "Téma v čísle"
|
if isinstance(value,TemaVCisleNode): return "Téma v čísle"
|
||||||
if isinstance(value,KonferaNode): return "Konfera"
|
# if isinstance(value,KonferaNode): return "Konfera" # FIXME neexistuje
|
||||||
if isinstance(value,ClanekNode): return "Článek"
|
# if isinstance(value,ClanekNode): return "Článek" # FIXME neexistuje
|
||||||
ledoian
commented
Tyhle komentáře způsobí tiché spadnutí. Byl by to Tyhle komentáře způsobí tiché spadnutí. Byl by to `NameError`, nejspíš i při validním volání, teď je to `return None`, díky čemuž se bude chyba špatně lovit. `NameError` je za mě fajn, ale klidně to jde vyřešit nějakým globálním `raise ValueError('tenhle typ TreeNode neexistuje')`.
zelvuska
commented
To je asi otázka spíš na to, proč KonferaNode a ClanekNode přestalo existovat a proč s tím nepřestal existovat i tento kód… To je asi otázka spíš na to, proč KonferaNode a ClanekNode přestalo existovat a proč s tím nepřestal existovat i tento kód…
|
|||||||
if isinstance(value,UlohaVzorakNode): return "Vzorák"
|
if isinstance(value,UlohaVzorakNode): return "Vzorák"
|
||||||
if isinstance(value,UlohaZadaniNode): return "Zadání úlohy"
|
if isinstance(value,UlohaZadaniNode): return "Zadání úlohy"
|
||||||
if isinstance(value,PohadkaNode): return "Pohádka"
|
if isinstance(value,PohadkaNode): return "Pohádka"
|
||||||
|
@ -22,53 +22,57 @@ def nodeType(value):
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isRocnik(value):
|
def isRocnik(value):
|
||||||
return isinstance(value, m.RocnikNode)
|
return isinstance(value, RocnikNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isCislo(value):
|
def isCislo(value):
|
||||||
return isinstance(value, m.CisloNode)
|
return isinstance(value, CisloNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isCast(value):
|
def isCast(value):
|
||||||
return isinstance(value, m.CastNode)
|
return isinstance(value, CastNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isText(value):
|
def isText(value):
|
||||||
return isinstance(value, m.TextNode)
|
return isinstance(value, TextNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isTemaVCisle(value):
|
def isTemaVCisle(value):
|
||||||
return isinstance(value, m.TemaVCisleNode)
|
return isinstance(value, TemaVCisleNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isKonfera(value):
|
def isKonfera(value):
|
||||||
return isinstance(value, m.KonferaNode)
|
# FIXME neexistuje
|
||||||
|
# return isinstance(value, KonferaNode)
|
||||||
ledoian
commented
Prosím aspoň zalogovat, neumřít tiše. Prosím aspoň zalogovat, neumřít tiše.
zelvuska
commented
Stejně jako výše. KonferaNode prostě neexistuje. (Přestala existovat v migraci 0080, které jsi autor…) Stejně jako výše. KonferaNode prostě neexistuje. (Přestala existovat v migraci 0080, které jsi autor…)
|
|||||||
|
return False
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isClanek(value):
|
def isClanek(value):
|
||||||
return isinstance(value, m.ClanekNode)
|
# FIXME neexistuje
|
||||||
|
# return isinstance(value, seminar.models.ClanekNode)
|
||||||
|
return False
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isUlohaVzorak(value):
|
def isUlohaVzorak(value):
|
||||||
return isinstance(value, m.UlohaVzorakNode)
|
return isinstance(value, UlohaVzorakNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isUlohaZadani(value):
|
def isUlohaZadani(value):
|
||||||
return isinstance(value, m.UlohaZadaniNode)
|
return isinstance(value, UlohaZadaniNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isPohadka(value):
|
def isPohadka(value):
|
||||||
return isinstance(value, m.PohadkaNode)
|
return isinstance(value, PohadkaNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isReseni(value):
|
def isReseni(value):
|
||||||
return False
|
return False
|
||||||
# return isinstance(value, m.OtisteneReseniNode)
|
# return isinstance(value, OtisteneReseniNode)
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def isOrgText(value):
|
def isOrgText(value):
|
||||||
return False
|
return False
|
||||||
# return isinstance(value, m.OrgTextNode)
|
# return isinstance(value, OrgTextNode)
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
import treenode.treelib as tl
|
import treenode.treelib as tl
|
||||||
import seminar.models as m
|
from .models import CastNode
|
||||||
ledoian
commented
V principu myslím, že tady je lepší řešení spíš V principu myslím, že tady je lepší řešení spíš `import treenode.models as tn`, ale až někdo někdy bude pokračovat ve psaní těchto testů, tak si to tam nejspíš dopíše, tak je to teď asi jedno…
zelvuska
commented
Proč si myslíš, že je lepší náhodná zkratka, než importování přímo věcí (když je to lokální věc). A celkově nad tímhle (jak má vypadat importování toho všeho, co předtím bylo Proč si myslíš, že je lepší náhodná zkratka, než importování přímo věcí (když je to lokální věc).
A celkově nad tímhle (jak má vypadat importování toho všeho, co předtím bylo `import seminar.models as m`) trochu dumám.
|
|||||||
|
|
||||||
class SimpleTreeLibTests(TestCase):
|
class SimpleTreeLibTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Vyrobíme pár nějakých Nodů
|
# Vyrobíme pár nějakých Nodů
|
||||||
self.root = m.CastNode(root=None, first_child=None, succ=None, nadpis="Root")
|
self.root = CastNode(root=None, first_child=None, succ=None, nadpis="Root")
|
||||||
self.root.save()
|
self.root.save()
|
||||||
self.some_node = m.CastNode(root=self.root, first_child=None, succ=None, nadpis="Přetržené")
|
self.some_node = CastNode(root=self.root, first_child=None, succ=None, nadpis="Přetržené")
|
||||||
self.other_node = m.CastNode(root=self.root, first_child=None, succ=None, nadpis="Dítě")
|
self.other_node = CastNode(root=self.root, first_child=None, succ=None, nadpis="Dítě")
|
||||||
self.some_orphan = m.CastNode(root=None, first_child=None, succ=None, nadpis="Ošklivé")
|
self.some_orphan = CastNode(root=None, first_child=None, succ=None, nadpis="Ošklivé")
|
||||||
self.other_orphan = m.CastNode(root=None, first_child=None, succ=None, nadpis="Káčátko")
|
self.other_orphan = CastNode(root=None, first_child=None, succ=None, nadpis="Káčátko")
|
||||||
|
|
||||||
# Trochu je pospojujeme
|
# Trochu je pospojujeme
|
||||||
self.root.first_child = self.some_node
|
self.root.first_child = self.some_node
|
||||||
|
|
|
@ -238,7 +238,7 @@ class TreeLibError(RuntimeError):
|
||||||
|
|
||||||
# Editace stromu:
|
# Editace stromu:
|
||||||
def create_node_after(predecessor, type, **kwargs):
|
def create_node_after(predecessor, type, **kwargs):
|
||||||
from seminar.models import TreeNode
|
from .models import TreeNode
|
||||||
if predecessor is None:
|
if predecessor is None:
|
||||||
raise TreeLibError("Nelze vyrábět sirotky! (predecessor=None)")
|
raise TreeLibError("Nelze vyrábět sirotky! (predecessor=None)")
|
||||||
if not issubclass(type, TreeNode):
|
if not issubclass(type, TreeNode):
|
||||||
|
@ -255,7 +255,7 @@ def create_node_after(predecessor, type, **kwargs):
|
||||||
|
|
||||||
# Vyrábí prvního syna, ostatní nalepí za (existují-li)
|
# Vyrábí prvního syna, ostatní nalepí za (existují-li)
|
||||||
def create_child(parent, type, **kwargs):
|
def create_child(parent, type, **kwargs):
|
||||||
from seminar.models import TreeNode
|
from .models import TreeNode
|
||||||
if parent is None:
|
if parent is None:
|
||||||
raise TreeLibError("Nelze vyrábět sirotky! (parent=None)")
|
raise TreeLibError("Nelze vyrábět sirotky! (parent=None)")
|
||||||
if not issubclass(type, TreeNode):
|
if not issubclass(type, TreeNode):
|
||||||
|
@ -293,7 +293,7 @@ def insert_last_child(parent, node):
|
||||||
last.save()
|
last.save()
|
||||||
|
|
||||||
def create_node_before(successor, type, **kwargs):
|
def create_node_before(successor, type, **kwargs):
|
||||||
from seminar.models import TreeNode
|
from .models import TreeNode
|
||||||
if successor is None:
|
if successor is None:
|
||||||
raise TreeLibError("Nelze vyrábět sirotky! (successor=None)")
|
raise TreeLibError("Nelze vyrábět sirotky! (successor=None)")
|
||||||
if not issubclass(type, TreeNode):
|
if not issubclass(type, TreeNode):
|
||||||
|
|
|
@ -6,8 +6,8 @@ from django.views.generic.edit import CreateView
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
|
||||||
import seminar.models as s
|
from .models import TemaVCisleNode, RocnikNode, CisloNode, UlohaVzorakNode, UlohaZadaniNode, TreeNode, CastNode, TextNode, ReseniNode, PohadkaNode, OrgTextNode
|
||||||
ledoian
commented
(Tu chybí (Tu chybí `MeziCisloNode`, to je vcelku podezřelé…)
zelvuska
commented
Asi nejsem schopen opravit (aniž bych se snažil pochopit treenode). Asi nejsem schopen opravit (aniž bych se snažil pochopit treenode).
|
|||||||
import seminar.models as m
|
from .models.pomocne import Text, Obrazek
|
||||||
from treenode import treelib
|
from treenode import treelib
|
||||||
import treenode.forms as f
|
import treenode.forms as f
|
||||||
import treenode.templatetags as tnltt
|
import treenode.templatetags as tnltt
|
||||||
|
@ -29,7 +29,7 @@ class TNLData(object):
|
||||||
|
|
||||||
if parent:
|
if parent:
|
||||||
self.tema_in_path = parent.tema_in_path
|
self.tema_in_path = parent.tema_in_path
|
||||||
if isinstance(anode, m.TemaVCisleNode):
|
if isinstance(anode, TemaVCisleNode):
|
||||||
self.tema_in_path = True
|
self.tema_in_path = True
|
||||||
|
|
||||||
def add_edit_options(self):
|
def add_edit_options(self):
|
||||||
|
@ -51,11 +51,11 @@ class TNLData(object):
|
||||||
(All of them have method verejne.)"""
|
(All of them have method verejne.)"""
|
||||||
parent = anode # chceme začít už od konkrétního node včetně
|
parent = anode # chceme začít už od konkrétního node včetně
|
||||||
while True:
|
while True:
|
||||||
rocnik = isinstance(parent, s.RocnikNode)
|
rocnik = isinstance(parent, RocnikNode)
|
||||||
cislo = isinstance(parent, s.CisloNode)
|
cislo = isinstance(parent, CisloNode)
|
||||||
uloha = (isinstance(parent, s.UlohaVzorakNode) or
|
uloha = (isinstance(parent, UlohaVzorakNode) or
|
||||||
isinstance(parent, s.UlohaZadaniNode))
|
isinstance(parent, UlohaZadaniNode))
|
||||||
tema = isinstance(parent, s.TemaVCisleNode)
|
tema = isinstance(parent, TemaVCisleNode)
|
||||||
|
|
||||||
if (rocnik or cislo or uloha or tema) or parent==None:
|
if (rocnik or cislo or uloha or tema) or parent==None:
|
||||||
break
|
break
|
||||||
|
@ -158,7 +158,7 @@ class TNLData(object):
|
||||||
|
|
||||||
|
|
||||||
class TreeNodeView(generic.DetailView):
|
class TreeNodeView(generic.DetailView):
|
||||||
model = s.TreeNode
|
model = TreeNode
|
||||||
template_name = 'treenode/treenode.html'
|
template_name = 'treenode/treenode.html'
|
||||||
|
|
||||||
def get_context_data(self,**kwargs):
|
def get_context_data(self,**kwargs):
|
||||||
|
@ -168,7 +168,7 @@ class TreeNodeView(generic.DetailView):
|
||||||
|
|
||||||
|
|
||||||
class TreeNodeJSONView(generic.DetailView):
|
class TreeNodeJSONView(generic.DetailView):
|
||||||
model = s.TreeNode
|
model = TreeNode
|
||||||
|
|
||||||
def get(self,request,*args, **kwargs):
|
def get(self,request,*args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
@ -178,21 +178,21 @@ class TreeNodeJSONView(generic.DetailView):
|
||||||
|
|
||||||
class TreeNodePridatView(generic.View):
|
class TreeNodePridatView(generic.View):
|
||||||
type_from_str = {
|
type_from_str = {
|
||||||
'rocnikNode': m.RocnikNode,
|
'rocnikNode': RocnikNode,
|
||||||
'cisloNode': m.CisloNode,
|
'cisloNode': CisloNode,
|
||||||
'castNode': m.CastNode,
|
'castNode': CastNode,
|
||||||
'textNode': m.TextNode,
|
'textNode': TextNode,
|
||||||
'temaVCisleNode': m.TemaVCisleNode,
|
'temaVCisleNode': TemaVCisleNode,
|
||||||
'reseniNode': m.ReseniNode,
|
'reseniNode': ReseniNode,
|
||||||
'ulohaZadaniNode': m.UlohaZadaniNode,
|
'ulohaZadaniNode': UlohaZadaniNode,
|
||||||
'ulohaVzorakNode': m.UlohaVzorakNode,
|
'ulohaVzorakNode': UlohaVzorakNode,
|
||||||
'pohadkaNode': m.PohadkaNode,
|
'pohadkaNode': PohadkaNode,
|
||||||
'orgText': m.OrgTextNode,
|
'orgText': OrgTextNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
######## FIXME: ROZEPSANE, NEFUNGUJE, DOPSAT !!!!!! ###########
|
######## FIXME: ROZEPSANE, NEFUNGUJE, DOPSAT !!!!!! ###########
|
||||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
node = TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||||
kam = self.kwargs['kam']
|
kam = self.kwargs['kam']
|
||||||
co = self.kwargs['co']
|
co = self.kwargs['co']
|
||||||
typ = self.type_from_str[co]
|
typ = self.type_from_str[co]
|
||||||
|
@ -202,19 +202,19 @@ class TreeNodePridatView(generic.View):
|
||||||
if kam not in ('pred','syn','za'):
|
if kam not in ('pred','syn','za'):
|
||||||
raise ValidationError('Přidat lze pouze před nebo za node nebo jako syna')
|
raise ValidationError('Přidat lze pouze před nebo za node nebo jako syna')
|
||||||
|
|
||||||
if co == m.TextNode:
|
if co == TextNode:
|
||||||
new_obj = m.Text()
|
new_obj = Text()
|
||||||
new_obj.save()
|
new_obj.save()
|
||||||
elif co == m.CastNode:
|
elif co == CastNode:
|
||||||
new_obj = m.CastNode()
|
new_obj = CastNode()
|
||||||
new_obj.nadpis = request.POST.get('pridat-castNode-{}-{}'.format(node.id,kam))
|
new_obj.nadpis = request.POST.get('pridat-castNode-{}-{}'.format(node.id,kam))
|
||||||
new_obj.save()
|
new_obj.save()
|
||||||
elif co == m.ReseniNode:
|
elif co == ReseniNode:
|
||||||
new_obj = m
|
new_obj = m
|
||||||
pass
|
pass
|
||||||
elif co == m.UlohaZadaniNode:
|
elif co == UlohaZadaniNode:
|
||||||
pass
|
pass
|
||||||
elif co == m.UlohaReseniNode:
|
elif co == UlohaReseniNode:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
new_obj = None
|
new_obj = None
|
||||||
|
@ -225,15 +225,15 @@ class TreeNodePridatView(generic.View):
|
||||||
|
|
||||||
|
|
||||||
if kam == 'syn':
|
if kam == 'syn':
|
||||||
if typ == m.TextNode:
|
if typ == TextNode:
|
||||||
text_obj = m.Text()
|
text_obj = Text()
|
||||||
text_obj.save()
|
text_obj.save()
|
||||||
node = treelib.create_child(node, typ, text=text_obj)
|
node = treelib.create_child(node, typ, text=text_obj)
|
||||||
else:
|
else:
|
||||||
node = treelib.create_child(node, typ)
|
node = treelib.create_child(node, typ)
|
||||||
if kam == 'za':
|
if kam == 'za':
|
||||||
if typ == m.TextNode:
|
if typ == TextNode:
|
||||||
text_obj = m.Text()
|
text_obj = Text()
|
||||||
text_obj.save()
|
text_obj.save()
|
||||||
node = treelib.create_node_after(node, typ, text=text_obj)
|
node = treelib.create_node_after(node, typ, text=text_obj)
|
||||||
else:
|
else:
|
||||||
|
@ -244,7 +244,7 @@ class TreeNodePridatView(generic.View):
|
||||||
|
|
||||||
class TreeNodeSmazatView(generic.base.View):
|
class TreeNodeSmazatView(generic.base.View):
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
node = TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||||
if node.first_child:
|
if node.first_child:
|
||||||
raise NotImplementedError('Mazání TreeNode se syny není zatím podporováno!')
|
raise NotImplementedError('Mazání TreeNode se syny není zatím podporováno!')
|
||||||
treelib.disconnect_node(node)
|
treelib.disconnect_node(node)
|
||||||
|
@ -254,7 +254,7 @@ class TreeNodeSmazatView(generic.base.View):
|
||||||
|
|
||||||
class TreeNodeOdvesitPrycView(generic.base.View):
|
class TreeNodeOdvesitPrycView(generic.base.View):
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
node = TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||||
treelib.disconnect_node(node)
|
treelib.disconnect_node(node)
|
||||||
node.root = None
|
node.root = None
|
||||||
node.save()
|
node.save()
|
||||||
|
@ -263,7 +263,7 @@ class TreeNodeOdvesitPrycView(generic.base.View):
|
||||||
|
|
||||||
class TreeNodePodvesitView(generic.base.View):
|
class TreeNodePodvesitView(generic.base.View):
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
node = TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||||
kam = self.kwargs['kam']
|
kam = self.kwargs['kam']
|
||||||
if kam == 'pred':
|
if kam == 'pred':
|
||||||
treelib.lower_node(node)
|
treelib.lower_node(node)
|
||||||
|
@ -274,21 +274,21 @@ class TreeNodePodvesitView(generic.base.View):
|
||||||
|
|
||||||
class TreeNodeProhoditView(generic.base.View):
|
class TreeNodeProhoditView(generic.base.View):
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
node = TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||||
treelib.swap_succ(node)
|
treelib.swap_succ(node)
|
||||||
return redirect(request.headers.get('referer'))
|
return redirect(request.headers.get('referer'))
|
||||||
#FIXME ve formulari predat puvodni url a vratit redirect na ni
|
#FIXME ve formulari predat puvodni url a vratit redirect na ni
|
||||||
|
|
||||||
class SirotcinecView(generic.ListView):
|
class SirotcinecView(generic.ListView):
|
||||||
model = s.TreeNode
|
model = TreeNode
|
||||||
template_name = 'treenode/orphanage.html'
|
template_name = 'treenode/orphanage.html'
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return s.TreeNode.objects.not_instance_of(s.RocnikNode).filter(root=None,prev=None,succ=None,father_of_first=None)
|
return TreeNode.objects.not_instance_of(RocnikNode).filter(root=None,prev=None,succ=None,father_of_first=None)
|
||||||
|
|
||||||
# FIXME pouzit Django REST Framework
|
# FIXME pouzit Django REST Framework
|
||||||
class TextWebView(generic.DetailView):
|
class TextWebView(generic.DetailView):
|
||||||
model = s.Text
|
model = Text
|
||||||
|
|
||||||
def get(self,request,*args, **kwargs):
|
def get(self,request,*args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
@ -300,7 +300,7 @@ class VueTestView(generic.TemplateView):
|
||||||
|
|
||||||
|
|
||||||
class NahrajObrazekKTreeNoduView(LoginRequiredMixin, CreateView):
|
class NahrajObrazekKTreeNoduView(LoginRequiredMixin, CreateView):
|
||||||
model = s.Obrazek
|
model = Obrazek
|
||||||
form_class = f.NahrajObrazekKTreeNoduForm
|
form_class = f.NahrajObrazekKTreeNoduForm
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
|
@ -316,7 +316,7 @@ class NahrajObrazekKTreeNoduView(LoginRequiredMixin, CreateView):
|
||||||
print(form)
|
print(form)
|
||||||
self.object = form.save(commit=False)
|
self.object = form.save(commit=False)
|
||||||
print(self.object.na_web)
|
print(self.object.na_web)
|
||||||
self.object.text = m.Text.objects.get(pk=int(self.request.headers['Textid']))
|
self.object.text = Text.objects.get(pk=int(self.request.headers['Textid']))
|
||||||
self.object.save()
|
self.object.save()
|
||||||
|
|
||||||
return JsonResponse({"url":self.object.na_web.url})
|
return JsonResponse({"url":self.object.na_web.url})
|
||||||
|
|
|
@ -3,7 +3,12 @@ from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from rest_framework.permissions import BasePermission, AllowAny
|
from rest_framework.permissions import BasePermission, AllowAny
|
||||||
from seminar import models as m
|
|
||||||
|
from odevzdavatko.models import Reseni
|
||||||
|
from tvorba.models import Problem, Uloha
|
||||||
|
|
||||||
|
from .models import TextNode, CastNode, UlohaVzorakNode, UlohaZadaniNode, ReseniNode
|
||||||
|
from .models.pomocne import Text
|
||||||
import treenode.serializers as views
|
import treenode.serializers as views
|
||||||
|
|
||||||
from treenode.permissions import AllowWrite
|
from treenode.permissions import AllowWrite
|
||||||
|
@ -66,17 +71,17 @@ class ReadWriteSerializerMixin(object):
|
||||||
return self.create_serializer_class
|
return self.create_serializer_class
|
||||||
|
|
||||||
class TextViewSet(PermissionMixin, viewsets.ModelViewSet):
|
class TextViewSet(PermissionMixin, viewsets.ModelViewSet):
|
||||||
queryset = m.Text.objects.all()
|
queryset = Text.objects.all()
|
||||||
serializer_class = views.TextSerializer
|
serializer_class = views.TextSerializer
|
||||||
|
|
||||||
class TextNodeViewSet(PermissionMixin, ReadWriteSerializerMixin,viewsets.ModelViewSet):
|
class TextNodeViewSet(PermissionMixin, ReadWriteSerializerMixin,viewsets.ModelViewSet):
|
||||||
queryset = m.TextNode.objects.all()
|
queryset = TextNode.objects.all()
|
||||||
read_serializer_class = views.TextNodeSerializer
|
read_serializer_class = views.TextNodeSerializer
|
||||||
write_serializer_class = views.TextNodeWriteSerializer
|
write_serializer_class = views.TextNodeWriteSerializer
|
||||||
create_serializer_class = views.TextNodeCreateSerializer
|
create_serializer_class = views.TextNodeCreateSerializer
|
||||||
|
|
||||||
class CastNodeViewSet(PermissionMixin, ReadWriteSerializerMixin,viewsets.ModelViewSet):
|
class CastNodeViewSet(PermissionMixin, ReadWriteSerializerMixin,viewsets.ModelViewSet):
|
||||||
queryset = m.CastNode.objects.all()
|
queryset = CastNode.objects.all()
|
||||||
read_serializer_class = views.CastNodeSerializer
|
read_serializer_class = views.CastNodeSerializer
|
||||||
write_serializer_class = views.CastNodeSerializer
|
write_serializer_class = views.CastNodeSerializer
|
||||||
create_serializer_class = views.CastNodeCreateSerializer
|
create_serializer_class = views.CastNodeCreateSerializer
|
||||||
|
@ -95,7 +100,7 @@ class UlohaVzorakNodeViewSet(PermissionMixin, ReadWriteSerializerMixin, viewsets
|
||||||
create_serializer_class = views.UlohaVzorakNodeCreateSerializer
|
create_serializer_class = views.UlohaVzorakNodeCreateSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = m.UlohaVzorakNode.objects.all()
|
queryset = UlohaVzorakNode.objects.all()
|
||||||
nazev = self.request.query_params.get('nazev',None)
|
nazev = self.request.query_params.get('nazev',None)
|
||||||
if nazev is not None:
|
if nazev is not None:
|
||||||
queryset = queryset.filter(nazev__contains=nazev)
|
queryset = queryset.filter(nazev__contains=nazev)
|
||||||
|
@ -114,7 +119,7 @@ class ReseniViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = views.ReseniSerializer
|
serializer_class = views.ReseniSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = m.Reseni.objects.all()
|
queryset = Reseni.objects.all()
|
||||||
#FIXME upravit nazvy dle skutecnych polozek reseni
|
#FIXME upravit nazvy dle skutecnych polozek reseni
|
||||||
nazev = self.request.query_params.get('nazev',None)
|
nazev = self.request.query_params.get('nazev',None)
|
||||||
if nazev is not None:
|
if nazev is not None:
|
||||||
|
@ -128,7 +133,7 @@ class UlohaViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = views.UlohaSerializer
|
serializer_class = views.UlohaSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = m.Uloha.objects.all()
|
queryset = Uloha.objects.all()
|
||||||
nazev = self.request.query_params.get('nazev',None)
|
nazev = self.request.query_params.get('nazev',None)
|
||||||
if nazev is not None:
|
if nazev is not None:
|
||||||
queryset = queryset.filter(nazev__contains=nazev)
|
queryset = queryset.filter(nazev__contains=nazev)
|
||||||
|
@ -138,13 +143,13 @@ class UlohaViewSet(viewsets.ModelViewSet):
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
class UlohaZadaniNodeViewSet(ReadWriteSerializerMixin, viewsets.ModelViewSet):
|
class UlohaZadaniNodeViewSet(ReadWriteSerializerMixin, viewsets.ModelViewSet):
|
||||||
queryset = m.UlohaZadaniNode.objects.all()
|
queryset = UlohaZadaniNode.objects.all()
|
||||||
read_serializer_class = views.UlohaZadaniNodeSerializer
|
read_serializer_class = views.UlohaZadaniNodeSerializer
|
||||||
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):
|
class ReseniNodeViewSet(ReadWriteSerializerMixin, viewsets.ModelViewSet):
|
||||||
queryset = m.ReseniNode.objects.all()
|
queryset = ReseniNode.objects.all()
|
||||||
read_serializer_class = views.ReseniNodeSerializer
|
read_serializer_class = views.ReseniNodeSerializer
|
||||||
write_serializer_class = views.ReseniNodeWriteSerializer
|
write_serializer_class = views.ReseniNodeWriteSerializer
|
||||||
create_serializer_class = views.ReseniNodeCreateSerializer
|
create_serializer_class = views.ReseniNodeCreateSerializer
|
||||||
|
@ -155,7 +160,7 @@ class ProblemViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = views.ProblemSerializer
|
serializer_class = views.ProblemSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = m.Problem.objects.all()
|
queryset = Problem.objects.all()
|
||||||
ucel = self.request.query_params.get('ucel',None)
|
ucel = self.request.query_params.get('ucel',None)
|
||||||
rocnik = self.request.query_params.get('rocnik',None)
|
rocnik = self.request.query_params.get('rocnik',None)
|
||||||
tema = self.request.query_params.get('tema',None)
|
tema = self.request.query_params.get('tema',None)
|
||||||
|
|
|
@ -297,7 +297,7 @@ class Cislo(SeminarModelBase):
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
# Neexistující *Node nemá smysl aktualizovat, ale je potřeba ho naopak vyrobit
|
# Neexistující *Node nemá smysl aktualizovat, ale je potřeba ho naopak vyrobit
|
||||||
logger.warning(f'Číslo {self} nemělo ČísloNode, vyrábím…')
|
logger.warning(f'Číslo {self} nemělo ČísloNode, vyrábím…')
|
||||||
from seminar.models.treenode import CisloNode
|
from treenode.models import CisloNode
|
||||||
CisloNode.objects.create(cislo=self)
|
CisloNode.objects.create(cislo=self)
|
||||||
|
|
||||||
def zlomovy_deadline_pro_papirove_cislo(self):
|
def zlomovy_deadline_pro_papirove_cislo(self):
|
||||||
|
@ -572,7 +572,7 @@ class Tema(Problem):
|
||||||
def cislo_node(self):
|
def cislo_node(self):
|
||||||
tema_node_set = self.temavcislenode_set.all()
|
tema_node_set = self.temavcislenode_set.all()
|
||||||
tema_cisla_vyskyt = []
|
tema_cisla_vyskyt = []
|
||||||
from seminar.models.treenode import CisloNode
|
from treenode.models import CisloNode
|
||||||
for tn in tema_node_set:
|
for tn in tema_node_set:
|
||||||
tema_cisla_vyskyt.append(
|
tema_cisla_vyskyt.append(
|
||||||
treelib.get_upper_node_of_type(tn, CisloNode).cislo)
|
treelib.get_upper_node_of_type(tn, CisloNode).cislo)
|
||||||
|
@ -648,7 +648,7 @@ class Uloha(Problem):
|
||||||
|
|
||||||
def cislo_node(self):
|
def cislo_node(self):
|
||||||
zadani_node = self.ulohazadaninode
|
zadani_node = self.ulohazadaninode
|
||||||
from seminar.models.treenode import CisloNode
|
from treenode.models import CisloNode
|
||||||
return treelib.get_upper_node_of_type(zadani_node, CisloNode)
|
return treelib.get_upper_node_of_type(zadani_node, CisloNode)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,12 @@ import lorem
|
||||||
import django.contrib.auth
|
import django.contrib.auth
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .models import Rocnik, Cislo, Deadline, Problem, Tema, Uloha
|
from .models import Rocnik, Cislo, Deadline, Problem, Tema, Uloha, Clanek
|
||||||
|
|
||||||
from odevzdavatko.models import Reseni, Hodnoceni
|
from odevzdavatko.models import Reseni, Hodnoceni
|
||||||
import seminar.models as m
|
# TODO zbavit se treenodů do treenode.testutils (ty pak klidně volat odtud)
|
||||||
|
from treenode.models import TextNode, UlohaZadaniNode, UlohaVzorakNode, RocnikNode, CisloNode, TemaVCisleNode, CastNode, MezicisloNode, ReseniNode
|
||||||
|
from treenode.models.pomocne import Text
|
||||||
|
|
||||||
from treenode.treelib import all_children, insert_last_child, all_children_of_type, create_node_after
|
from treenode.treelib import all_children, insert_last_child, all_children_of_type, create_node_after
|
||||||
|
|
||||||
|
@ -56,12 +58,12 @@ def gen_zadani_ulohy(rnd, cisla, organizatori, pocet_oboru, poradi_cisla, poradi
|
||||||
rnd.choice(jmeno),
|
rnd.choice(jmeno),
|
||||||
rnd.choice(kde)]
|
rnd.choice(kde)]
|
||||||
)
|
)
|
||||||
text_zadani = m.Text.objects.create(
|
text_zadani = Text.objects.create(
|
||||||
na_web = text,
|
na_web = text,
|
||||||
do_cisla = text,
|
do_cisla = text,
|
||||||
)
|
)
|
||||||
zad = m.TextNode.objects.create(text = text_zadani, root = p.cislo_zadani.rocnik.rocniknode)
|
zad = TextNode.objects.create(text = text_zadani, root = p.cislo_zadani.rocnik.rocniknode)
|
||||||
uloha_zadani = m.UlohaZadaniNode.objects.create(uloha = p, first_child = zad, root = p.cislo_zadani.rocnik.rocniknode)
|
uloha_zadani = UlohaZadaniNode.objects.create(uloha = p, first_child = zad, root = p.cislo_zadani.rocnik.rocniknode)
|
||||||
p.ulohazadaninode = uloha_zadani
|
p.ulohazadaninode = uloha_zadani
|
||||||
otec_syn(cisla[poradi_cisla-2-1].cislonode, uloha_zadani)
|
otec_syn(cisla[poradi_cisla-2-1].cislonode, uloha_zadani)
|
||||||
|
|
||||||
|
@ -78,12 +80,12 @@ def gen_vzoroveho_reseni_ulohy(rnd, organizatori, uloha, pocet_opravovatelu):
|
||||||
|
|
||||||
# Generování vzorového řešení.
|
# Generování vzorového řešení.
|
||||||
obsah = rnd.choice(reseni)
|
obsah = rnd.choice(reseni)
|
||||||
text_vzoraku = m.Text.objects.create(
|
text_vzoraku = Text.objects.create(
|
||||||
na_web = obsah,
|
na_web = obsah,
|
||||||
do_cisla = obsah
|
do_cisla = obsah
|
||||||
)
|
)
|
||||||
vzorak = m.TextNode.objects.create(text = text_vzoraku, root = uloha.cislo_zadani.rocnik.rocniknode)
|
vzorak = TextNode.objects.create(text = text_vzoraku, root = uloha.cislo_zadani.rocnik.rocniknode)
|
||||||
uloha_vzorak = m.UlohaVzorakNode.objects.create(uloha = uloha, first_child = vzorak, root = uloha.cislo_zadani.rocnik.rocniknode)
|
uloha_vzorak = UlohaVzorakNode.objects.create(uloha = uloha, first_child = vzorak, root = uloha.cislo_zadani.rocnik.rocniknode)
|
||||||
uloha.ulohavzoraknode = uloha_vzorak
|
uloha.ulohavzoraknode = uloha_vzorak
|
||||||
|
|
||||||
uloha.opravovatele.set(rnd.sample(organizatori, pocet_opravovatelu))
|
uloha.opravovatele.set(rnd.sample(organizatori, pocet_opravovatelu))
|
||||||
|
@ -134,7 +136,7 @@ def gen_rocniky(last_rocnik, size):
|
||||||
node = None
|
node = None
|
||||||
for ri in range(min(last_rocnik - size, 1), last_rocnik + 1):
|
for ri in range(min(last_rocnik - size, 1), last_rocnik + 1):
|
||||||
rocnik = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri)
|
rocnik = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri)
|
||||||
node2 = m.RocnikNode.objects.create(rocnik = rocnik, succ = node)
|
node2 = RocnikNode.objects.create(rocnik = rocnik, succ = node)
|
||||||
rocnik.save()
|
rocnik.save()
|
||||||
node = node2
|
node = node2
|
||||||
rocniky.append(rocnik)
|
rocniky.append(rocnik)
|
||||||
|
@ -169,7 +171,7 @@ def gen_cisla(rnd, rocniky):
|
||||||
datum_vydani=vydano,
|
datum_vydani=vydano,
|
||||||
verejne_db=True,
|
verejne_db=True,
|
||||||
)
|
)
|
||||||
node2 = m.CisloNode.objects.get(cislo = cislo)
|
node2 = CisloNode.objects.get(cislo = cislo)
|
||||||
node2.succ = node
|
node2.succ = node
|
||||||
node2.root = rocnik.rocniknode
|
node2.root = rocnik.rocniknode
|
||||||
cislo.save()
|
cislo.save()
|
||||||
|
@ -197,7 +199,7 @@ def add_first_child(node, child):
|
||||||
|
|
||||||
def get_text():
|
def get_text():
|
||||||
odstavec = lorem.paragraph()
|
odstavec = lorem.paragraph()
|
||||||
return m.Text.objects.create(na_web = odstavec, do_cisla = odstavec)
|
return Text.objects.create(na_web = odstavec, do_cisla = odstavec)
|
||||||
|
|
||||||
def gen_dlouhe_tema(rnd, organizatori, rocnik, nazev, obor, kod):
|
def gen_dlouhe_tema(rnd, organizatori, rocnik, nazev, obor, kod):
|
||||||
tema = Tema.objects.create(
|
tema = Tema.objects.create(
|
||||||
|
@ -217,54 +219,54 @@ def gen_dlouhe_tema(rnd, organizatori, rocnik, nazev, obor, kod):
|
||||||
for cislo in cisla:
|
for cislo in cisla:
|
||||||
# Přidáme TemaVCisleNode do daného čísla
|
# Přidáme TemaVCisleNode do daného čísla
|
||||||
cislo_node = cislo.cislonode
|
cislo_node = cislo.cislonode
|
||||||
tema_cislo_node = m.TemaVCisleNode.objects.create(tema = tema, root = cislo_node.root)
|
tema_cislo_node = TemaVCisleNode.objects.create(tema = tema, root = cislo_node.root)
|
||||||
insert_last_child(cislo_node, tema_cislo_node)
|
insert_last_child(cislo_node, tema_cislo_node)
|
||||||
|
|
||||||
# Přidávání obsahu do čísla
|
# Přidávání obsahu do čísla
|
||||||
cast_node = m.CastNode.objects.create(nadpis = "Příspěvek k číslu {}".format(cislo.kod), root=cislo_node.root)
|
cast_node = CastNode.objects.create(nadpis = "Příspěvek k číslu {}".format(cislo.kod), root=cislo_node.root)
|
||||||
add_first_child(tema_cislo_node, cast_node)
|
add_first_child(tema_cislo_node, cast_node)
|
||||||
|
|
||||||
text_node = m.TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
text_node = TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
||||||
add_first_child(cast_node, text_node)
|
add_first_child(cast_node, text_node)
|
||||||
|
|
||||||
cast_node2 = m.CastNode.objects.create(nadpis = "První podproblém", root=cislo_node.root)
|
cast_node2 = CastNode.objects.create(nadpis = "První podproblém", root=cislo_node.root)
|
||||||
add_first_child(text_node, cast_node2)
|
add_first_child(text_node, cast_node2)
|
||||||
|
|
||||||
text_node2 = m.TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
text_node2 = TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
||||||
add_first_child(cast_node2, text_node2)
|
add_first_child(cast_node2, text_node2)
|
||||||
|
|
||||||
cast_node3 = m.CastNode.objects.create(nadpis = "Druhý podproblém", root=cislo_node.root)
|
cast_node3 = CastNode.objects.create(nadpis = "Druhý podproblém", root=cislo_node.root)
|
||||||
add_first_child(text_node2, cast_node3)
|
add_first_child(text_node2, cast_node3)
|
||||||
|
|
||||||
text_node3 = m.TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
text_node3 = TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
||||||
add_first_child(cast_node3, text_node3)
|
add_first_child(cast_node3, text_node3)
|
||||||
|
|
||||||
cast_node4 = m.CastNode.objects.create(nadpis = "Třetí podproblém", root=cislo_node.root)
|
cast_node4 = CastNode.objects.create(nadpis = "Třetí podproblém", root=cislo_node.root)
|
||||||
add_first_child(text_node3, cast_node4)
|
add_first_child(text_node3, cast_node4)
|
||||||
|
|
||||||
text_node4 = m.TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
text_node4 = TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
||||||
add_first_child(cast_node3, text_node4)
|
add_first_child(cast_node3, text_node4)
|
||||||
|
|
||||||
cast_node3a = m.CastNode.objects.create(nadpis = "Podproblém paralelní s "
|
cast_node3a = CastNode.objects.create(nadpis = "Podproblém paralelní s "
|
||||||
"druhým podproblémem", root=cislo_node.root)
|
"druhým podproblémem", root=cislo_node.root)
|
||||||
cast_node3.succ = cast_node3a
|
cast_node3.succ = cast_node3a
|
||||||
cast_node3.save()
|
cast_node3.save()
|
||||||
|
|
||||||
text_node3a = m.TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
text_node3a = TextNode.objects.create(text = get_text(), root=cislo_node.root)
|
||||||
add_first_child(cast_node3a, text_node3a)
|
add_first_child(cast_node3a, text_node3a)
|
||||||
|
|
||||||
# Občas přidáme mezičíslo
|
# Občas přidáme mezičíslo
|
||||||
if rnd.randint(1, 3) == 1:
|
if rnd.randint(1, 3) == 1:
|
||||||
create_node_after(cislo_node, m.MezicisloNode, root=cislo_node.root)
|
create_node_after(cislo_node, MezicisloNode, root=cislo_node.root)
|
||||||
mezicislo_node = cislo_node.succ
|
mezicislo_node = cislo_node.succ
|
||||||
|
|
||||||
cast_node_mezicislo = m.CastNode.objects.create(
|
cast_node_mezicislo = CastNode.objects.create(
|
||||||
nadpis = "Příspěvek k mezičíslu".format(cislo.kod), root=cislo_node.root)
|
nadpis = "Příspěvek k mezičíslu".format(cislo.kod), root=cislo_node.root)
|
||||||
add_first_child(mezicislo_node, cast_node_mezicislo)
|
add_first_child(mezicislo_node, cast_node_mezicislo)
|
||||||
|
|
||||||
odstavec = lorem.paragraph()
|
odstavec = lorem.paragraph()
|
||||||
text_mezicislo = m.Text.objects.create(na_web = odstavec, do_cisla = odstavec)
|
text_mezicislo = Text.objects.create(na_web = odstavec, do_cisla = odstavec)
|
||||||
text_node_mezicislo = m.TextNode.objects.create(text = text_mezicislo, root=cislo_node.root)
|
text_node_mezicislo = TextNode.objects.create(text = text_mezicislo, root=cislo_node.root)
|
||||||
add_first_child(cast_node_mezicislo, text_node_mezicislo)
|
add_first_child(cast_node_mezicislo, text_node_mezicislo)
|
||||||
|
|
||||||
return tema
|
return tema
|
||||||
|
@ -308,7 +310,7 @@ def gen_temata(rnd, rocniky, rocnik_cisla, organizatori):
|
||||||
|
|
||||||
# Vyrobíme TemaVCisleNody pro obsah
|
# Vyrobíme TemaVCisleNody pro obsah
|
||||||
for i in range(zacatek_tematu, konec_tematu+1):
|
for i in range(zacatek_tematu, konec_tematu+1):
|
||||||
node = m.TemaVCisleNode.objects.create(tema = t,root=rocnik.rocniknode)
|
node = TemaVCisleNode.objects.create(tema = t,root=rocnik.rocniknode)
|
||||||
# FIXME: Není to off-by-one?
|
# FIXME: Není to off-by-one?
|
||||||
otec = cisla[i-1].cislonode
|
otec = cisla[i-1].cislonode
|
||||||
otec_syn(otec, node)
|
otec_syn(otec, node)
|
||||||
|
@ -361,12 +363,12 @@ def gen_ulohy_tematu(rnd, organizatori, resitele, tema, kod, cislo, cislo_se_vzo
|
||||||
rnd.choice(jmeno),
|
rnd.choice(jmeno),
|
||||||
rnd.choice(kde)]
|
rnd.choice(kde)]
|
||||||
)
|
)
|
||||||
text_zadani = m.Text.objects.create(
|
text_zadani = Text.objects.create(
|
||||||
na_web = obsah,
|
na_web = obsah,
|
||||||
do_cisla = obsah,
|
do_cisla = obsah,
|
||||||
)
|
)
|
||||||
zad = m.TextNode.objects.create(text = text_zadani, root=tema.temavcislenode_set.first().root)
|
zad = TextNode.objects.create(text = text_zadani, root=tema.temavcislenode_set.first().root)
|
||||||
uloha_zadani = m.UlohaZadaniNode.objects.create(uloha=uloha, first_child = zad, root=tema.temavcislenode_set.first().root)
|
uloha_zadani = UlohaZadaniNode.objects.create(uloha=uloha, first_child = zad, root=tema.temavcislenode_set.first().root)
|
||||||
uloha.ulohazadaninode = uloha_zadani
|
uloha.ulohazadaninode = uloha_zadani
|
||||||
|
|
||||||
# Generování řešení a hodnocení k úloze
|
# Generování řešení a hodnocení k úloze
|
||||||
|
@ -398,7 +400,7 @@ def gen_ulohy_k_tematum(rnd, rocniky, rocnik_cisla, rocnik_temata, organizatori,
|
||||||
else:
|
else:
|
||||||
cislo_se_vzorakem = cislo_se_vzorakem.first()
|
cislo_se_vzorakem = cislo_se_vzorakem.first()
|
||||||
|
|
||||||
for tema_node in all_children_of_type(cislo.cislonode, m.TemaVCisleNode):
|
for tema_node in all_children_of_type(cislo.cislonode, TemaVCisleNode):
|
||||||
tema = tema_node.tema
|
tema = tema_node.tema
|
||||||
|
|
||||||
# Pokud už témátko skončilo, žádné úložky negenerujeme
|
# Pokud už témátko skončilo, žádné úložky negenerujeme
|
||||||
|
@ -421,7 +423,7 @@ def gen_ulohy_k_tematum(rnd, rocniky, rocnik_cisla, rocnik_temata, organizatori,
|
||||||
# Najdeme správný TemaVCisleNode pro vložení vzoráku
|
# Najdeme správný TemaVCisleNode pro vložení vzoráku
|
||||||
res_tema_node = None;
|
res_tema_node = None;
|
||||||
for node in all_children(cislo_se_vzorakem.cislonode):
|
for node in all_children(cislo_se_vzorakem.cislonode):
|
||||||
if isinstance(node, m.TemaVCisleNode):
|
if isinstance(node, TemaVCisleNode):
|
||||||
if node.tema == tema:
|
if node.tema == tema:
|
||||||
res_tema_node = node
|
res_tema_node = node
|
||||||
if res_tema_node is None:
|
if res_tema_node is None:
|
||||||
|
@ -440,7 +442,7 @@ def otec_syn(otec, syn):
|
||||||
|
|
||||||
def gen_clanek(rnd, organizatori, resitele):
|
def gen_clanek(rnd, organizatori, resitele):
|
||||||
logger.info("Generuji článek do čísla 22.2")
|
logger.info("Generuji článek do čísla 22.2")
|
||||||
clanek = m.Clanek.objects.create(
|
clanek = Clanek.objects.create(
|
||||||
nazev="Článek o Lorem ipsum",
|
nazev="Článek o Lorem ipsum",
|
||||||
nadproblem=None,
|
nadproblem=None,
|
||||||
stav='vyreseny',
|
stav='vyreseny',
|
||||||
|
@ -467,7 +469,7 @@ def gen_clanek(rnd, organizatori, resitele):
|
||||||
)
|
)
|
||||||
hodnoceni.save()
|
hodnoceni.save()
|
||||||
|
|
||||||
reseninode = m.ReseniNode.objects.create(
|
reseninode = ReseniNode.objects.create(
|
||||||
reseni=reseni
|
reseni=reseni
|
||||||
)
|
)
|
||||||
reseninode.save()
|
reseninode.save()
|
||||||
|
@ -483,26 +485,26 @@ def gen_clanek(rnd, organizatori, resitele):
|
||||||
# FIXME: Ten, kdo vymyslel TreeLib (mj. týž, kdo psal tenhle kód),
|
# FIXME: Ten, kdo vymyslel TreeLib (mj. týž, kdo psal tenhle kód),
|
||||||
# nevyrobil vhodnou funkci, takže to postavíme pozpátku pomocí create_child
|
# nevyrobil vhodnou funkci, takže to postavíme pozpátku pomocí create_child
|
||||||
# (které vyrábí _prvního_ syna)
|
# (které vyrábí _prvního_ syna)
|
||||||
create_child(reseninode, m.CastNode, nadpis="Lorem ipsum")
|
create_child(reseninode, CastNode, nadpis="Lorem ipsum")
|
||||||
# Taky ten člověk nevyrobil vracení nových věcí...
|
# Taky ten člověk nevyrobil vracení nových věcí...
|
||||||
castnode = reseninode.first_child
|
castnode = reseninode.first_child
|
||||||
|
|
||||||
# Úvodní odstaveček
|
# Úvodní odstaveček
|
||||||
obsah = "Tohle je zamyšlení o textu lorem ipsum. Začneme a skončíme ukázkou."
|
obsah = "Tohle je zamyšlení o textu lorem ipsum. Začneme a skončíme ukázkou."
|
||||||
text = m.Text.objects.create(
|
text = Text.objects.create(
|
||||||
na_web=obsah,
|
na_web=obsah,
|
||||||
do_cisla=obsah,
|
do_cisla=obsah,
|
||||||
)
|
)
|
||||||
text.save()
|
text.save()
|
||||||
create_child(reseninode, m.TextNode, text=text)
|
create_child(reseninode, TextNode, text=text)
|
||||||
|
|
||||||
# Několik odstavců lorem ipsum
|
# Několik odstavců lorem ipsum
|
||||||
for _ in range(rnd.randint(3, 7)):
|
for _ in range(rnd.randint(3, 7)):
|
||||||
lipsum = lorem.paragraph()
|
lipsum = lorem.paragraph()
|
||||||
text = m.Text.objects.create(
|
text = Text.objects.create(
|
||||||
na_web=lipsum,
|
na_web=lipsum,
|
||||||
do_cisla=lipsum,
|
do_cisla=lipsum,
|
||||||
)
|
)
|
||||||
text.save()
|
text.save()
|
||||||
create_child(castnode, m.TextNode, text=text)
|
create_child(castnode, TextNode, text=text)
|
||||||
logger.info(f"Článek vygenerován (reseni={reseni.id}, treenode={reseninode.id})")
|
logger.info(f"Článek vygenerován (reseni={reseni.id}, treenode={reseninode.id})")
|
||||||
|
|
|
@ -14,10 +14,10 @@ from django.db.models import Q, Sum, Count
|
||||||
from django.views.generic.base import RedirectView
|
from django.views.generic.base import RedirectView
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
|
||||||
import seminar.models as m
|
|
||||||
from personalni.models import Resitel
|
from personalni.models import Resitel
|
||||||
from soustredeni.models import Konfera
|
from soustredeni.models import Konfera
|
||||||
from tvorba.models import Problem, Cislo, Rocnik, Tema, Clanek, Deadline, Uloha
|
from tvorba.models import Problem, Cislo, Rocnik, Tema, Clanek, Deadline, Uloha
|
||||||
|
from treenode.models import TemaVCisleNode, PohadkaNode
|
||||||
from various.models import Nastaveni
|
from various.models import Nastaveni
|
||||||
from treenode import treelib
|
from treenode import treelib
|
||||||
import treenode.templatetags as tnltt
|
import treenode.templatetags as tnltt
|
||||||
|
@ -79,7 +79,7 @@ def get_problemy_k_tematu(tema):
|
||||||
# context['tnldata'] = TNLData.from_tnldata_list([tnl_zadani, tnl_vzorak])
|
# context['tnldata'] = TNLData.from_tnldata_list([tnl_zadani, tnl_vzorak])
|
||||||
# elif isinstance(self.object, Tema):
|
# elif isinstance(self.object, Tema):
|
||||||
# rocniknode = self.object.rocnik.rocniknode
|
# rocniknode = self.object.rocnik.rocniknode
|
||||||
# context['tnldata'] = TNLData.filter_treenode(rocniknode, lambda x: isinstance(x, m.TemaVCisleNode))
|
# context['tnldata'] = TNLData.filter_treenode(rocniknode, lambda x: isinstance(x, TemaVCisleNode))
|
||||||
# else:
|
# else:
|
||||||
# raise ValueError("Obecný problém nejde zobrazit.")
|
# raise ValueError("Obecný problém nejde zobrazit.")
|
||||||
# return context
|
# return context
|
||||||
|
@ -144,9 +144,9 @@ def ZadaniTemataView(request):
|
||||||
# tematko_object = Tema.objects.filter(rocnik=rocnik_object[0], kod=tematko)
|
# tematko_object = Tema.objects.filter(rocnik=rocnik_object[0], kod=tematko)
|
||||||
# seznam = vytahniZLesaSeznam(tematko_object[0], nastaveni.aktualni_rocnik().rocniknode)
|
# seznam = vytahniZLesaSeznam(tematko_object[0], nastaveni.aktualni_rocnik().rocniknode)
|
||||||
# for node, depth in seznam:
|
# for node, depth in seznam:
|
||||||
# if node.isinstance(node, m.KonferaNode):
|
# if node.isinstance(node, KonferaNode): # FIXME neexistuje
|
||||||
# raise Exception("Not implemented yet")
|
# raise Exception("Not implemented yet")
|
||||||
# if node.isinstance(node, m.PohadkaNode): # Mohu ignorovat, má pod sebou
|
# if node.isinstance(node, PohadkaNode): # Mohu ignorovat, má pod sebou
|
||||||
# pass
|
# pass
|
||||||
#
|
#
|
||||||
# return render(request, 'tvorba/tematka/toaletak.html', {})
|
# return render(request, 'tvorba/tematka/toaletak.html', {})
|
||||||
|
|
|
@ -14,7 +14,8 @@ from django.views import generic
|
||||||
import novinky.views
|
import novinky.views
|
||||||
import treenode.treelib as t
|
import treenode.treelib as t
|
||||||
import tvorba.views
|
import tvorba.views
|
||||||
import seminar.models as m
|
|
||||||
|
from treenode.models import CisloNode
|
||||||
from personalni.models import Resitel, Osoba
|
from personalni.models import Resitel, Osoba
|
||||||
from tvorba.models import Clanek, Deadline
|
from tvorba.models import Clanek, Deadline
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ def seznam_problemu():
|
||||||
# content type je věc pomáhající rozeznávat různé typy objektů v django-polymorphic
|
# content type je věc pomáhající rozeznávat různé typy objektů v django-polymorphic
|
||||||
# protože isinstance vrátí vždy jen TreeNode
|
# protože isinstance vrátí vždy jen TreeNode
|
||||||
# https://django-polymorphic.readthedocs.io/en/stable/migrating.html
|
# https://django-polymorphic.readthedocs.io/en/stable/migrating.html
|
||||||
cislonode_ct = ContentType.objects.get_for_model(m.CisloNode)
|
cislonode_ct = ContentType.objects.get_for_model(CisloNode)
|
||||||
node = clanek_node
|
node = clanek_node
|
||||||
while node is not None:
|
while node is not None:
|
||||||
node_ct = node.polymorphic_ctype
|
node_ct = node.polymorphic_ctype
|
||||||
|
|
Já vím, že chybělo už předtím, ale chybí tu
ReseniNode
. (i později v deklaracích jednotlivých adminů)