Browse Source

Odstřel (importů) treenodů

pull/65/head
Jonas Havelka 2 weeks ago
parent
commit
07d1505e2a
  1. 2
      seminar/models/odevzdavatko.py
  2. 73
      treenode/admin.py
  3. 4
      treenode/forms.py
  4. 2
      treenode/models/__init__.py
  5. 1
      treenode/models/pomocne.py
  6. 132
      treenode/serializers.py
  7. 34
      treenode/templatetags.py
  8. 12
      treenode/tests.py
  9. 6
      treenode/treelib.py
  10. 82
      treenode/views.py
  11. 25
      treenode/viewsets.py
  12. 6
      tvorba/models.py
  13. 80
      tvorba/testutils.py
  14. 8
      tvorba/views/__init__.py
  15. 5
      various/views/final.py

2
seminar/models/odevzdavatko.py

@ -1,6 +1,6 @@
from django.db import models
from seminar.models import treenode as tm
from treenode import models as tm
from odevzdavatko.models import Reseni
class ReseniNode(tm.TreeNode):

73
treenode/admin.py

@ -4,25 +4,26 @@ from django.forms import widgets
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
# TODO: Inlines podle https://django-polymorphic.readthedocs.io/en/stable/admin.html
@admin.register(m.TreeNode)
@admin.register(TreeNode)
class TreeNodeAdmin(PolymorphicParentModelAdmin):
base_model = m.TreeNode
base_model = TreeNode
child_models = [
m.RocnikNode,
m.CisloNode,
m.MezicisloNode,
m.TemaVCisleNode,
m.UlohaZadaniNode,
m.PohadkaNode,
m.UlohaVzorakNode,
m.TextNode,
m.CastNode,
m.OrgTextNode,
RocnikNode,
CisloNode,
MezicisloNode,
TemaVCisleNode,
UlohaZadaniNode,
PohadkaNode,
UlohaVzorakNode,
TextNode,
CastNode,
OrgTextNode,
]
actions = ['aktualizuj_nazvy']
@ -36,64 +37,64 @@ class TreeNodeAdmin(PolymorphicParentModelAdmin):
self.message_user(request, "Názvy aktualizovány.")
aktualizuj_nazvy.short_description = "Aktualizuj vybraným TreeNodům názvy"
@admin.register(m.RocnikNode)
@admin.register(RocnikNode)
class RocnikNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.RocnikNode
base_model = RocnikNode
show_in_index = True
@admin.register(m.CisloNode)
@admin.register(CisloNode)
class CisloNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.CisloNode
base_model = CisloNode
show_in_index = True
@admin.register(m.MezicisloNode)
@admin.register(MezicisloNode)
class MezicisloNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.MezicisloNode
base_model = MezicisloNode
show_in_index = True
@admin.register(m.TemaVCisleNode)
@admin.register(TemaVCisleNode)
class TemaVCisleNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.TemaVCisleNode
base_model = TemaVCisleNode
show_in_index = True
@admin.register(m.UlohaZadaniNode)
@admin.register(UlohaZadaniNode)
class UlohaZadaniNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.UlohaZadaniNode
base_model = UlohaZadaniNode
show_in_index = True
@admin.register(m.PohadkaNode)
@admin.register(PohadkaNode)
class PohadkaNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.PohadkaNode
base_model = PohadkaNode
show_in_index = True
@admin.register(m.UlohaVzorakNode)
@admin.register(UlohaVzorakNode)
class UlohaVzorakNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.UlohaVzorakNode
base_model = UlohaVzorakNode
show_in_index = True
@admin.register(m.TextNode)
@admin.register(TextNode)
class TextNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.TextNode
base_model = TextNode
show_in_index = True
@admin.register(m.CastNode)
@admin.register(CastNode)
class TextNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.CastNode
base_model = CastNode
show_in_index = True
fields = ('nadpis',)
@admin.register(m.OrgTextNode)
@admin.register(OrgTextNode)
class TextNodeAdmin(PolymorphicChildModelAdmin):
base_model = m.OrgTextNode
base_model = OrgTextNode
show_in_index = True
class TextAdminInline(admin.TabularInline):
model = m.Text
model = Text
formfield_overrides = {
models.TextField: {'widget': widgets.TextInput}
}
exclude = ['text_zkraceny_set', 'text_zkraceny']
admin.site.register(m.Text)
admin.site.register(m.Obrazek)
admin.site.register(Text)
admin.site.register(Obrazek)

4
treenode/forms.py

@ -1,5 +1,5 @@
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
# - mít v modelu tu položku, kterou chci upravovat
@ -10,5 +10,5 @@ import seminar.models as m
class NahrajObrazekKTreeNoduForm(forms.ModelForm):
class Meta:
model = m.Obrazek
model = Obrazek
fields = ('na_web',)

2
treenode/models/__init__.py

@ -0,0 +1,2 @@
from seminar.models.odevzdavatko import *
from seminar.models.treenode import *

1
treenode/models/pomocne.py

@ -0,0 +1 @@
from seminar.models.pomocne import *

132
treenode/serializers.py

@ -1,7 +1,11 @@
from rest_framework import serializers
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
DEFAULT_NODE_DEPTH = 2
@ -9,57 +13,57 @@ DEFAULT_NODE_DEPTH = 2
class TextSerializer(serializers.ModelSerializer):
class Meta:
model = m.Text
model = Text
fields = '__all__'
class ProblemSerializer(serializers.ModelSerializer):
class Meta:
model = m.Problem
model = Problem
fields = '__all__'
class UlohaSerializer(serializers.ModelSerializer):
class Meta:
model = m.Uloha
model = Uloha
fields = '__all__'
class ReseniSerializer(serializers.ModelSerializer):
class Meta:
model = m.Reseni
model = Reseni
fields = '__all__'
class RocnikNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.RocnikNode
model = RocnikNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
class CisloNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.CisloNode
model = CisloNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
class MezicisloNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.MezicisloNode
model = MezicisloNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
class TemaVCisleNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.TemaVCisleNode
model = TemaVCisleNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
class OrgTextNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.OrgTextNode
model = OrgTextNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
class PohadkaNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.PohadkaNode
model = PohadkaNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
@ -67,7 +71,7 @@ class TextNodeSerializer(serializers.ModelSerializer):
text = TextSerializer()
class Meta:
model = m.TextNode
model = TextNode
fields = ('id','text','polymorphic_ctype')
depth = DEFAULT_NODE_DEPTH
@ -80,7 +84,7 @@ class TextNodeWriteSerializer(serializers.ModelSerializer):
return node
class Meta:
model = m.TextNode
model = TextNode
fields = ('id','text')
depth = DEFAULT_NODE_DEPTH
@ -93,26 +97,26 @@ class TextNodeCreateSerializer(serializers.ModelSerializer):
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)
refnode = TreeNode.objects.get(pk=refnode_id)
text = Text.objects.create(**temp_text)
if where == 'syn':
node = treelib.create_child(refnode,m.TextNode,text=text)
node = treelib.create_child(refnode,TextNode,text=text)
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':
node = treelib.create_node_before(refnode,m.TextNode,text=text)
node = treelib.create_node_before(refnode,TextNode,text=text)
node.where = None
node.refnode = None
return node
class Meta:
model = m.TextNode
model = TextNode
fields = ('text','where','refnode')
depth = DEFAULT_NODE_DEPTH
class CastNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.CastNode
model = CastNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
@ -124,25 +128,25 @@ class CastNodeCreateSerializer(serializers.ModelSerializer):
temp_nadpis = validated_data.pop('nadpis')
where = validated_data.pop('where')
refnode_id = validated_data.pop('refnode')
refnode = m.TreeNode.objects.get(pk=refnode_id)
refnode = TreeNode.objects.get(pk=refnode_id)
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':
node = treelib.create_node_after(refnode,m.CastNode,nadpis=temp_nadpis)
node = treelib.create_node_after(refnode,CastNode,nadpis=temp_nadpis)
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.refnode = None
return node
class Meta:
model = m.CastNode
model = CastNode
fields = ('nadpis','where','refnode')
depth = DEFAULT_NODE_DEPTH
class UlohaZadaniNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.UlohaZadaniNode
model = UlohaZadaniNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
@ -157,7 +161,7 @@ class UlohaZadaniNodeWriteSerializer(serializers.ModelSerializer):
return node
class Meta:
model = m.TextNode
model = TextNode
fields = ('id','uloha')
depth = DEFAULT_NODE_DEPTH
@ -171,28 +175,28 @@ class UlohaZadaniNodeCreateSerializer(serializers.ModelSerializer):
temp_uloha = validated_data.pop('uloha')
where = validated_data.pop('where')
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
cislo = None
tema = None
travelnode = refnode
while travelnode is not None:
if isinstance(travelnode, m.TemaVCisleNode):
if isinstance(travelnode, TemaVCisleNode):
tema = travelnode.tema
if isinstance(travelnode, m.CisloNode):
if isinstance(travelnode, CisloNode):
cislo = travelnode.cislo
travelnode = treelib.get_parent(travelnode)
# 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
if where == 'syn':
node = treelib.create_child(refnode,m.UlohaZadaniNode,uloha = uloha)
node = treelib.create_child(refnode,UlohaZadaniNode,uloha = uloha)
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':
node = treelib.create_node_before(refnode,m.UlohaZadaniNode,uloha = uloha)
node = treelib.create_node_before(refnode,UlohaZadaniNode,uloha = uloha)
node.where = None
node.refnode = None
node.max_body = None
@ -200,21 +204,21 @@ class UlohaZadaniNodeCreateSerializer(serializers.ModelSerializer):
return node
class Meta:
model = m.UlohaZadaniNode
model = UlohaZadaniNode
fields = ('uloha','where','refnode')
depth = DEFAULT_NODE_DEPTH
class UlohaVzorakNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.UlohaVzorakNode
model = UlohaVzorakNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
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:
model = m.UlohaVzorakNode
model = UlohaVzorakNode
fields = ('id','uloha')
depth = DEFAULT_NODE_DEPTH
@ -226,17 +230,17 @@ class UlohaVzorakNodeCreateSerializer(serializers.ModelSerializer):
def create(self, validated_data):
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')
refnode_id = validated_data.pop('refnode')
refnode = m.TreeNode.objects.get(pk=refnode_id)
refnode = TreeNode.objects.get(pk=refnode_id)
if where == 'syn':
node = treelib.create_child(refnode,m.UlohaVzorakNode,uloha = uloha)
node = treelib.create_child(refnode,UlohaVzorakNode,uloha = uloha)
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':
node = treelib.create_node_before(refnode,m.UlohaVzorakNode,uloha = uloha)
node = treelib.create_node_before(refnode,UlohaVzorakNode,uloha = uloha)
node.refnode = None
node.where = None
node.uloha_id = None
@ -244,7 +248,7 @@ class UlohaVzorakNodeCreateSerializer(serializers.ModelSerializer):
return node
class Meta:
model = m.UlohaVzorakNode
model = UlohaVzorakNode
fields = ('refnode', 'uloha_id', 'where')
depth = DEFAULT_NODE_DEPTH
@ -253,15 +257,15 @@ class UlohaVzorakNodeCreateSerializer(serializers.ModelSerializer):
class ReseniNodeSerializer(serializers.ModelSerializer):
class Meta:
model = m.ReseniNode
model = ReseniNode
fields = '__all__'
depth = DEFAULT_NODE_DEPTH
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:
model = m.ReseniNode
model = ReseniNode
fields = ('id','reseni')
depth = DEFAULT_NODE_DEPTH
@ -273,41 +277,41 @@ class ReseniNodeCreateSerializer(serializers.ModelSerializer):
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)
reseni = 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)
refnode = TreeNode.objects.get(pk=refnode_id)
# A vyrobime UlohaZadaniNode
if where == 'syn':
node = treelib.create_child(refnode,m.ReseniNode,reseni = reseni)
node = treelib.create_child(refnode,ReseniNode,reseni = reseni)
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':
node = treelib.create_node_before(refnode,m.ReseniNode,reseni = reseni)
node = treelib.create_node_before(refnode,ReseniNode,reseni = reseni)
node.where = None
node.refnode = None
node.reseni_id = None
return node
class Meta:
model = m.ReseniNode
model = ReseniNode
fields = ('reseni_id','where','refnode')
depth = DEFAULT_NODE_DEPTH
class TreeNodeSerializer(PolymorphicSerializer):
model_serializer_mapping = {
m.RocnikNode: RocnikNodeSerializer,
m.CisloNode: CisloNodeSerializer,
m.MezicisloNode: MezicisloNodeSerializer,
m.TemaVCisleNode: TemaVCisleNodeSerializer,
m.OrgTextNode: OrgTextNodeSerializer,
m.UlohaZadaniNode: UlohaZadaniNodeSerializer,
m.UlohaVzorakNode: UlohaVzorakNodeSerializer,
m.PohadkaNode: PohadkaNodeSerializer,
m.TextNode: TextNodeSerializer,
m.CastNode: CastNodeSerializer,
m.ReseniNode: ReseniNodeSerializer,
RocnikNode: RocnikNodeSerializer,
CisloNode: CisloNodeSerializer,
MezicisloNode: MezicisloNodeSerializer,
TemaVCisleNode: TemaVCisleNodeSerializer,
OrgTextNode: OrgTextNodeSerializer,
UlohaZadaniNode: UlohaZadaniNodeSerializer,
UlohaVzorakNode: UlohaVzorakNodeSerializer,
PohadkaNode: PohadkaNodeSerializer,
TextNode: TextNodeSerializer,
CastNode: CastNodeSerializer,
ReseniNode: ReseniNodeSerializer,
}

34
treenode/templatetags.py

@ -1,6 +1,6 @@
from django import template
from enum import Enum
import seminar.models as m
from .models import RocnikNode, CisloNode, CastNode, TextNode, TemaVCisleNode, UlohaVzorakNode, UlohaZadaniNode, PohadkaNode
register = template.Library()
@ -11,8 +11,8 @@ def nodeType(value):
if isinstance(value,CastNode): return "Část"
if isinstance(value,TextNode): return "Text"
if isinstance(value,TemaVCisleNode): return "Téma v čísle"
if isinstance(value,KonferaNode): return "Konfera"
if isinstance(value,ClanekNode): return "Článek"
# if isinstance(value,KonferaNode): return "Konfera" # FIXME neexistuje
# if isinstance(value,ClanekNode): return "Článek" # FIXME neexistuje
if isinstance(value,UlohaVzorakNode): return "Vzorák"
if isinstance(value,UlohaZadaniNode): return "Zadání úlohy"
if isinstance(value,PohadkaNode): return "Pohádka"
@ -22,53 +22,57 @@ def nodeType(value):
@register.filter
def isRocnik(value):
return isinstance(value, m.RocnikNode)
return isinstance(value, RocnikNode)
@register.filter
def isCislo(value):
return isinstance(value, m.CisloNode)
return isinstance(value, CisloNode)
@register.filter
def isCast(value):
return isinstance(value, m.CastNode)
return isinstance(value, CastNode)
@register.filter
def isText(value):
return isinstance(value, m.TextNode)
return isinstance(value, TextNode)
@register.filter
def isTemaVCisle(value):
return isinstance(value, m.TemaVCisleNode)
return isinstance(value, TemaVCisleNode)
@register.filter
def isKonfera(value):
return isinstance(value, m.KonferaNode)
# FIXME neexistuje
# return isinstance(value, KonferaNode)
return False
@register.filter
def isClanek(value):
return isinstance(value, m.ClanekNode)
# FIXME neexistuje
# return isinstance(value, seminar.models.ClanekNode)
return False
@register.filter
def isUlohaVzorak(value):
return isinstance(value, m.UlohaVzorakNode)
return isinstance(value, UlohaVzorakNode)
@register.filter
def isUlohaZadani(value):
return isinstance(value, m.UlohaZadaniNode)
return isinstance(value, UlohaZadaniNode)
@register.filter
def isPohadka(value):
return isinstance(value, m.PohadkaNode)
return isinstance(value, PohadkaNode)
@register.filter
def isReseni(value):
return False
# return isinstance(value, m.OtisteneReseniNode)
# return isinstance(value, OtisteneReseniNode)
@register.filter
def isOrgText(value):
return False
# return isinstance(value, m.OrgTextNode)
# return isinstance(value, OrgTextNode)
###

12
treenode/tests.py

@ -1,16 +1,16 @@
from django.test import TestCase
import treenode.treelib as tl
import seminar.models as m
from .models import CastNode
class SimpleTreeLibTests(TestCase):
def setUp(self):
# 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.some_node = m.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.some_orphan = m.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.some_node = CastNode(root=self.root, first_child=None, succ=None, nadpis="Přetržené")
self.other_node = CastNode(root=self.root, first_child=None, succ=None, nadpis="Dítě")
self.some_orphan = CastNode(root=None, first_child=None, succ=None, nadpis="Ošklivé")
self.other_orphan = CastNode(root=None, first_child=None, succ=None, nadpis="Káčátko")
# Trochu je pospojujeme
self.root.first_child = self.some_node

6
treenode/treelib.py

@ -238,7 +238,7 @@ class TreeLibError(RuntimeError):
# Editace stromu:
def create_node_after(predecessor, type, **kwargs):
from seminar.models import TreeNode
from .models import TreeNode
if predecessor is None:
raise TreeLibError("Nelze vyrábět sirotky! (predecessor=None)")
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)
def create_child(parent, type, **kwargs):
from seminar.models import TreeNode
from .models import TreeNode
if parent is None:
raise TreeLibError("Nelze vyrábět sirotky! (parent=None)")
if not issubclass(type, TreeNode):
@ -293,7 +293,7 @@ def insert_last_child(parent, node):
last.save()
def create_node_before(successor, type, **kwargs):
from seminar.models import TreeNode
from .models import TreeNode
if successor is None:
raise TreeLibError("Nelze vyrábět sirotky! (successor=None)")
if not issubclass(type, TreeNode):

82
treenode/views.py

@ -6,8 +6,8 @@ from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import PermissionDenied
import seminar.models as s
import seminar.models as m
from .models import TemaVCisleNode, RocnikNode, CisloNode, UlohaVzorakNode, UlohaZadaniNode, TreeNode, CastNode, TextNode, ReseniNode, PohadkaNode, OrgTextNode
from .models.pomocne import Text, Obrazek
from treenode import treelib
import treenode.forms as f
import treenode.templatetags as tnltt
@ -29,7 +29,7 @@ class TNLData(object):
if parent:
self.tema_in_path = parent.tema_in_path
if isinstance(anode, m.TemaVCisleNode):
if isinstance(anode, TemaVCisleNode):
self.tema_in_path = True
def add_edit_options(self):
@ -51,11 +51,11 @@ class TNLData(object):
(All of them have method verejne.)"""
parent = anode # chceme začít už od konkrétního node včetně
while True:
rocnik = isinstance(parent, s.RocnikNode)
cislo = isinstance(parent, s.CisloNode)
uloha = (isinstance(parent, s.UlohaVzorakNode) or
isinstance(parent, s.UlohaZadaniNode))
tema = isinstance(parent, s.TemaVCisleNode)
rocnik = isinstance(parent, RocnikNode)
cislo = isinstance(parent, CisloNode)
uloha = (isinstance(parent, UlohaVzorakNode) or
isinstance(parent, UlohaZadaniNode))
tema = isinstance(parent, TemaVCisleNode)
if (rocnik or cislo or uloha or tema) or parent==None:
break
@ -158,7 +158,7 @@ class TNLData(object):
class TreeNodeView(generic.DetailView):
model = s.TreeNode
model = TreeNode
template_name = 'treenode/treenode.html'
def get_context_data(self,**kwargs):
@ -168,7 +168,7 @@ class TreeNodeView(generic.DetailView):
class TreeNodeJSONView(generic.DetailView):
model = s.TreeNode
model = TreeNode
def get(self,request,*args, **kwargs):
self.object = self.get_object()
@ -178,21 +178,21 @@ class TreeNodeJSONView(generic.DetailView):
class TreeNodePridatView(generic.View):
type_from_str = {
'rocnikNode': m.RocnikNode,
'cisloNode': m.CisloNode,
'castNode': m.CastNode,
'textNode': m.TextNode,
'temaVCisleNode': m.TemaVCisleNode,
'reseniNode': m.ReseniNode,
'ulohaZadaniNode': m.UlohaZadaniNode,
'ulohaVzorakNode': m.UlohaVzorakNode,
'pohadkaNode': m.PohadkaNode,
'orgText': m.OrgTextNode,
'rocnikNode': RocnikNode,
'cisloNode': CisloNode,
'castNode': CastNode,
'textNode': TextNode,
'temaVCisleNode': TemaVCisleNode,
'reseniNode': ReseniNode,
'ulohaZadaniNode': UlohaZadaniNode,
'ulohaVzorakNode': UlohaVzorakNode,
'pohadkaNode': PohadkaNode,
'orgText': OrgTextNode,
}
def post(self, request, *args, **kwargs):
######## 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']
co = self.kwargs['co']
typ = self.type_from_str[co]
@ -202,19 +202,19 @@ class TreeNodePridatView(generic.View):
if kam not in ('pred','syn','za'):
raise ValidationError('Přidat lze pouze před nebo za node nebo jako syna')
if co == m.TextNode:
new_obj = m.Text()
if co == TextNode:
new_obj = Text()
new_obj.save()
elif co == m.CastNode:
new_obj = m.CastNode()
elif co == CastNode:
new_obj = CastNode()
new_obj.nadpis = request.POST.get('pridat-castNode-{}-{}'.format(node.id,kam))
new_obj.save()
elif co == m.ReseniNode:
elif co == ReseniNode:
new_obj = m
pass
elif co == m.UlohaZadaniNode:
elif co == UlohaZadaniNode:
pass
elif co == m.UlohaReseniNode:
elif co == UlohaReseniNode:
pass
else:
new_obj = None
@ -225,15 +225,15 @@ class TreeNodePridatView(generic.View):
if kam == 'syn':
if typ == m.TextNode:
text_obj = m.Text()
if typ == TextNode:
text_obj = Text()
text_obj.save()
node = treelib.create_child(node, typ, text=text_obj)
else:
node = treelib.create_child(node, typ)
if kam == 'za':
if typ == m.TextNode:
text_obj = m.Text()
if typ == TextNode:
text_obj = Text()
text_obj.save()
node = treelib.create_node_after(node, typ, text=text_obj)
else:
@ -244,7 +244,7 @@ class TreeNodePridatView(generic.View):
class TreeNodeSmazatView(generic.base.View):
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:
raise NotImplementedError('Mazání TreeNode se syny není zatím podporováno!')
treelib.disconnect_node(node)
@ -254,7 +254,7 @@ class TreeNodeSmazatView(generic.base.View):
class TreeNodeOdvesitPrycView(generic.base.View):
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)
node.root = None
node.save()
@ -263,7 +263,7 @@ class TreeNodeOdvesitPrycView(generic.base.View):
class TreeNodePodvesitView(generic.base.View):
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']
if kam == 'pred':
treelib.lower_node(node)
@ -274,21 +274,21 @@ class TreeNodePodvesitView(generic.base.View):
class TreeNodeProhoditView(generic.base.View):
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)
return redirect(request.headers.get('referer'))
#FIXME ve formulari predat puvodni url a vratit redirect na ni
class SirotcinecView(generic.ListView):
model = s.TreeNode
model = TreeNode
template_name = 'treenode/orphanage.html'
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
class TextWebView(generic.DetailView):
model = s.Text
model = Text
def get(self,request,*args, **kwargs):
self.object = self.get_object()
@ -300,7 +300,7 @@ class VueTestView(generic.TemplateView):
class NahrajObrazekKTreeNoduView(LoginRequiredMixin, CreateView):
model = s.Obrazek
model = Obrazek
form_class = f.NahrajObrazekKTreeNoduForm
def get_initial(self):
@ -316,7 +316,7 @@ class NahrajObrazekKTreeNoduView(LoginRequiredMixin, CreateView):
print(form)
self.object = form.save(commit=False)
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()
return JsonResponse({"url":self.object.na_web.url})

25
treenode/viewsets.py

@ -3,7 +3,12 @@ from rest_framework import status
from rest_framework.response import Response
from django.core.exceptions import PermissionDenied
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
from treenode.permissions import AllowWrite
@ -66,17 +71,17 @@ class ReadWriteSerializerMixin(object):
return self.create_serializer_class
class TextViewSet(PermissionMixin, viewsets.ModelViewSet):
queryset = m.Text.objects.all()
queryset = Text.objects.all()
serializer_class = views.TextSerializer
class TextNodeViewSet(PermissionMixin, ReadWriteSerializerMixin,viewsets.ModelViewSet):
queryset = m.TextNode.objects.all()
queryset = TextNode.objects.all()
read_serializer_class = views.TextNodeSerializer
write_serializer_class = views.TextNodeWriteSerializer
create_serializer_class = views.TextNodeCreateSerializer
class CastNodeViewSet(PermissionMixin, ReadWriteSerializerMixin,viewsets.ModelViewSet):
queryset = m.CastNode.objects.all()
queryset = CastNode.objects.all()
read_serializer_class = views.CastNodeSerializer
write_serializer_class = views.CastNodeSerializer
create_serializer_class = views.CastNodeCreateSerializer
@ -95,7 +100,7 @@ class UlohaVzorakNodeViewSet(PermissionMixin, ReadWriteSerializerMixin, viewsets
create_serializer_class = views.UlohaVzorakNodeCreateSerializer
def get_queryset(self):
queryset = m.UlohaVzorakNode.objects.all()
queryset = UlohaVzorakNode.objects.all()
nazev = self.request.query_params.get('nazev',None)
if nazev is not None:
queryset = queryset.filter(nazev__contains=nazev)
@ -114,7 +119,7 @@ class ReseniViewSet(viewsets.ModelViewSet):
serializer_class = views.ReseniSerializer
def get_queryset(self):
queryset = m.Reseni.objects.all()
queryset = Reseni.objects.all()
#FIXME upravit nazvy dle skutecnych polozek reseni
nazev = self.request.query_params.get('nazev',None)
if nazev is not None:
@ -128,7 +133,7 @@ class UlohaViewSet(viewsets.ModelViewSet):
serializer_class = views.UlohaSerializer
def get_queryset(self):
queryset = m.Uloha.objects.all()
queryset = Uloha.objects.all()
nazev = self.request.query_params.get('nazev',None)
if nazev is not None:
queryset = queryset.filter(nazev__contains=nazev)
@ -138,13 +143,13 @@ class UlohaViewSet(viewsets.ModelViewSet):
return queryset
class UlohaZadaniNodeViewSet(ReadWriteSerializerMixin, viewsets.ModelViewSet):
queryset = m.UlohaZadaniNode.objects.all()
queryset = UlohaZadaniNode.objects.all()
read_serializer_class = views.UlohaZadaniNodeSerializer
write_serializer_class = views.UlohaZadaniNodeWriteSerializer
create_serializer_class = views.UlohaZadaniNodeCreateSerializer
class ReseniNodeViewSet(ReadWriteSerializerMixin, viewsets.ModelViewSet):
queryset = m.ReseniNode.objects.all()
queryset = ReseniNode.objects.all()
read_serializer_class = views.ReseniNodeSerializer
write_serializer_class = views.ReseniNodeWriteSerializer
create_serializer_class = views.ReseniNodeCreateSerializer
@ -155,7 +160,7 @@ class ProblemViewSet(viewsets.ModelViewSet):
serializer_class = views.ProblemSerializer
def get_queryset(self):
queryset = m.Problem.objects.all()
queryset = Problem.objects.all()
ucel = self.request.query_params.get('ucel',None)
rocnik = self.request.query_params.get('rocnik',None)
tema = self.request.query_params.get('tema',None)

6
tvorba/models.py

@ -297,7 +297,7 @@ class Cislo(SeminarModelBase):
except ObjectDoesNotExist:
# Neexistující *Node nemá smysl aktualizovat, ale je potřeba ho naopak vyrobit
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)
def zlomovy_deadline_pro_papirove_cislo(self):
@ -572,7 +572,7 @@ class Tema(Problem):
def cislo_node(self):
tema_node_set = self.temavcislenode_set.all()
tema_cisla_vyskyt = []
from seminar.models.treenode import CisloNode
from treenode.models import CisloNode
for tn in tema_node_set:
tema_cisla_vyskyt.append(
treelib.get_upper_node_of_type(tn, CisloNode).cislo)
@ -648,7 +648,7 @@ class Uloha(Problem):
def cislo_node(self):
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)

80
tvorba/testutils.py

@ -6,10 +6,12 @@ import lorem
import django.contrib.auth
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
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
@ -56,12 +58,12 @@ def gen_zadani_ulohy(rnd, cisla, organizatori, pocet_oboru, poradi_cisla, poradi
rnd.choice(jmeno),
rnd.choice(kde)]
)
text_zadani = m.Text.objects.create(
text_zadani = Text.objects.create(
na_web = text,
do_cisla = text,
)
zad = m.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)
zad = TextNode.objects.create(text = text_zadani, 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
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í.
obsah = rnd.choice(reseni)
text_vzoraku = m.Text.objects.create(
text_vzoraku = Text.objects.create(
na_web = obsah,
do_cisla = obsah
)
vzorak = m.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)
vzorak = TextNode.objects.create(text = text_vzoraku, 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.opravovatele.set(rnd.sample(organizatori, pocet_opravovatelu))
@ -134,7 +136,7 @@ def gen_rocniky(last_rocnik, size):
node = None
for ri in range(min(last_rocnik - size, 1), last_rocnik + 1):
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()
node = node2
rocniky.append(rocnik)
@ -169,7 +171,7 @@ def gen_cisla(rnd, rocniky):
datum_vydani=vydano,
verejne_db=True,
)
node2 = m.CisloNode.objects.get(cislo = cislo)
node2 = CisloNode.objects.get(cislo = cislo)
node2.succ = node
node2.root = rocnik.rocniknode
cislo.save()
@ -197,7 +199,7 @@ def add_first_child(node, child):
def get_text():
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):
tema = Tema.objects.create(
@ -217,54 +219,54 @@ def gen_dlouhe_tema(rnd, organizatori, rocnik, nazev, obor, kod):
for cislo in cisla:
# Přidáme TemaVCisleNode do daného čísla
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)
# 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)
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)
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)
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)
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)
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)
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)
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)
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)
cast_node3.succ = cast_node3a
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)
# Občas přidáme mezičíslo
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
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)
add_first_child(mezicislo_node, cast_node_mezicislo)
odstavec = lorem.paragraph()
text_mezicislo = m.Text.objects.create(na_web = odstavec, do_cisla = odstavec)
text_node_mezicislo = m.TextNode.objects.create(text = text_mezicislo, root=cislo_node.root)
text_mezicislo = Text.objects.create(na_web = odstavec, do_cisla = odstavec)
text_node_mezicislo = TextNode.objects.create(text = text_mezicislo, root=cislo_node.root)
add_first_child(cast_node_mezicislo, text_node_mezicislo)
return tema
@ -308,7 +310,7 @@ def gen_temata(rnd, rocniky, rocnik_cisla, organizatori):
# Vyrobíme TemaVCisleNody pro obsah
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?
otec = cisla[i-1].cislonode
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(kde)]
)
text_zadani = m.Text.objects.create(
text_zadani = Text.objects.create(
na_web = obsah,
do_cisla = obsah,
)
zad = m.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)
zad = TextNode.objects.create(text = text_zadani, 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
# 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:
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
# 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
res_tema_node = None;
for node in all_children(cislo_se_vzorakem.cislonode):
if isinstance(node, m.TemaVCisleNode):
if isinstance(node, TemaVCisleNode):
if node.tema == tema:
res_tema_node = node
if res_tema_node is None:
@ -440,7 +442,7 @@ def otec_syn(otec, syn):
def gen_clanek(rnd, organizatori, resitele):
logger.info("Generuji článek do čísla 22.2")
clanek = m.Clanek.objects.create(
clanek = Clanek.objects.create(
nazev="Článek o Lorem ipsum",
nadproblem=None,
stav='vyreseny',
@ -467,7 +469,7 @@ def gen_clanek(rnd, organizatori, resitele):
)
hodnoceni.save()
reseninode = m.ReseniNode.objects.create(
reseninode = ReseniNode.objects.create(
reseni=reseni
)
reseninode.save()
@ -483,26 +485,26 @@ def gen_clanek(rnd, organizatori, resitele):
# 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
# (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í...
castnode = reseninode.first_child
# Úvodní odstaveček
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,
do_cisla=obsah,
)
text.save()
create_child(reseninode, m.TextNode, text=text)
create_child(reseninode, TextNode, text=text)
# Několik odstavců lorem ipsum
for _ in range(rnd.randint(3, 7)):
lipsum = lorem.paragraph()
text = m.Text.objects.create(
text = Text.objects.create(
na_web=lipsum,
do_cisla=lipsum,
)
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})")

8
tvorba/views/__init__.py

@ -14,10 +14,10 @@ from django.db.models import Q, Sum, Count
from django.views.generic.base import RedirectView
from django.core.exceptions import PermissionDenied
import seminar.models as m
from personalni.models import Resitel
from soustredeni.models import Konfera
from tvorba.models import Problem, Cislo, Rocnik, Tema, Clanek, Deadline, Uloha
from treenode.models import TemaVCisleNode, PohadkaNode
from various.models import Nastaveni
from treenode import treelib
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])
# elif isinstance(self.object, Tema):
# 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:
# raise ValueError("Obecný problém nejde zobrazit.")
# return context
@ -144,9 +144,9 @@ def ZadaniTemataView(request):
# tematko_object = Tema.objects.filter(rocnik=rocnik_object[0], kod=tematko)
# seznam = vytahniZLesaSeznam(tematko_object[0], nastaveni.aktualni_rocnik().rocniknode)
# for node, depth in seznam:
# if node.isinstance(node, m.KonferaNode):
# if node.isinstance(node, KonferaNode): # FIXME neexistuje
# 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
#
# return render(request, 'tvorba/tematka/toaletak.html', {})

5
various/views/final.py

@ -14,7 +14,8 @@ from django.views import generic
import novinky.views
import treenode.treelib as t
import tvorba.views
import seminar.models as m
from treenode.models import CisloNode
from personalni.models import Resitel, Osoba
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
# protože isinstance vrátí vždy jen TreeNode
# 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
while node is not None:
node_ct = node.polymorphic_ctype

Loading…
Cancel
Save