You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
3.5 KiB

from django import template
from enum import Enum
import seminar.models as m
register = template.Library()
@register.filter
def nodeType(value):
if isinstance(value,RocnikNode): return "Ročník"
if isinstance(value,CisloNode): return "Číslo"
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,UlohaVzorakNode): return "Vzorák"
if isinstance(value,UlohaZadaniNode): return "Zadání úlohy"
if isinstance(value,PohadkaNode): return "Pohádka"
@register.filter
def isRocnik(value):
return isinstance(value, m.RocnikNode)
@register.filter
def isCislo(value):
return isinstance(value, m.CisloNode)
@register.filter
def isCast(value):
return isinstance(value, m.CastNode)
@register.filter
def isText(value):
return isinstance(value, m.TextNode)
@register.filter
def isTemaVCisle(value):
return isinstance(value, m.TemaVCisleNode)
@register.filter
def isKonfera(value):
return isinstance(value, m.KonferaNode)
@register.filter
def isClanek(value):
return isinstance(value, m.ClanekNode)
@register.filter
def isUlohaVzorak(value):
return isinstance(value, m.UlohaVzorakNode)
@register.filter
def isUlohaZadani(value):
return isinstance(value, m.UlohaZadaniNode)
@register.filter
def isPohadka(value):
return isinstance(value, m.PohadkaNode)
@register.filter
def isReseni(value):
return False
# return isinstance(value, m.OtisteneReseniNode)
@register.filter
def isOrgText(value):
return False
# return isinstance(value, m.OrgTextNode)
###
#@register.filter
#def podvesitelneNody(value):
# if isText()
@register.filter
def deletable(value):
if isTemaVCisle(value):
return True
if isOrgText(value):
return True
if isReseni(value):
return True
if isUlohaZadani(value):
return True
if isUlohaVzorak(value):
return True
if isCast(value):
return True
if isText(value):
return True
return False
@register.filter
def editableSiblings(value):
if isCast(value.node):
return True
if isText(value.node):
return True
if isReseni(value.node) and value.tema_in_path:
return True
if isUlohaZadani(value.node) and value.tema_in_path:
return True
if isUlohaVzorak(value.node) and value.tema_in_path:
return True
return False
@register.filter
def editableChildren(value):
if isRocnik(value.node):
return False
if isCislo(value.node):
return False
if isText(value.node):
return False
return True
class NodeTypes(Enum):
ROCNIK = ('rocnikNode','Ročník')
CISLO = ('cisloNode', 'Číslo')
CAST = ('castNode', 'Část')
TEXT = ('textNode', 'Text')
TEMAVCISLE = ('temaVCisleNode', 'Téma v čísle')
RESENI = ('reseniNode','Řešení')
ULOHAZADANI = ('ulohaZadaniNode','Zadání')
ULOHAVZORAK = ('ulohaVzorakNode','Vzorák')
POHADKA = ('pohadkaNode','Pohádka')
ORGTEXT = ('orgText','Orgtext')
@register.filter
def appendableChildren(value):
if isTemaVCisle(value):
return (NodeTypes.RESENI.value,
NodeTypes.ULOHAZADANI.value,
NodeTypes.ULOHAVZORAK.value,
NodeTypes.CAST.value,
NodeTypes.TEXT.value,
)
if isOrgText(value) or isReseni(value) or isUlohaZadani(value) or isUlohaVzorak(value):
return (NodeTypes.CAST.value,
NodeTypes.TEXT.value,
)
if isCast(value):
return appendableChildren(value.parent)
return None
#@register.filter
#def is(value):
# return
#
# NodeTypes..value,
#@register.filter
#def is(value):
# return