diff --git a/seminar/templates/seminar/treenode_add_stub.html b/seminar/templates/seminar/treenode_add_stub.html new file mode 100644 index 00000000..e53c070b --- /dev/null +++ b/seminar/templates/seminar/treenode_add_stub.html @@ -0,0 +1,11 @@ +{% load treenodes %} +{% if obj.node|appendableChildren %} +
Přidat {{kam}} + + +
+{% endif %}{# appendablebleChildren #} diff --git a/seminar/templates/seminar/treenode_name.html b/seminar/templates/seminar/treenode_name.html new file mode 100644 index 00000000..ef15de1e --- /dev/null +++ b/seminar/templates/seminar/treenode_name.html @@ -0,0 +1,16 @@ +{% load treenodes %} +{% if obj.node|isRocnik %} + Ročník {{obj.node.rocnik}} +{% elif obj.node|isCislo %} + Číslo {{obj.node.cislo}} +{% elif obj.node|isTemaVCisle %} + Téma {{obj.node.tema.nazev}} +{% elif obj.node|isUlohaZadani %} +Úloha {{obj.node.uloha.kod_v_rocniku}} ({{obj.node.uloha.max_body}} b) +{% elif obj.node|isUlohaVzorak %} +Řešení: {{obj.node.uloha.kod_v_rocniku}} +{% elif obj.node|isText %} +{{obj.node.text.na_web}} +{% else %} +Objekt jiného typu {{obj.node}} +{% endif %} diff --git a/seminar/templates/seminar/treenode_recursive.html b/seminar/templates/seminar/treenode_recursive.html index d76670d6..81011cc5 100644 --- a/seminar/templates/seminar/treenode_recursive.html +++ b/seminar/templates/seminar/treenode_recursive.html @@ -2,91 +2,53 @@ {# {{depth}} #}
-{{obj.node}} -{% if obj.node|deletable %} - -{% endif %} -{% if not obj.children and obj.node|appendableChildren %} -{% endif %} -
-{% if obj|editableSiblings %} -
- - + {{obj.node}} + {% if obj.node|deletable %} + + {% endif %} + {% if obj.parent and obj.parent|editableSiblings %} + + {% endif %} + {% if obj|canPodvesitPred %} + - nejsou testovací data + {% endif %} + {% if obj|canPodvesitZa %} + - nejsou testovací data + {% endif %} + +
+{% if False %} +
+ FIXME: není zatím implementováno + - nejsou testovací data +
{% endif %} -{% if obj.node|isRocnik %} - Ročník {{obj.node.rocnik}} -{% elif obj.node|isCislo %} - Číslo {{obj.node.cislo}} -{% elif obj.node|isTemaVCisle %} - Téma {{obj.node.tema.nazev}} -{% elif obj.node|isUlohaZadani %} -Úloha {{obj.node.uloha.kod_v_rocniku}} ({{obj.node.uloha.max_body}} b) -{% elif obj.node|isUlohaVzorak %} -Řešení: {{obj.node.uloha.kod_v_rocniku}} -{% elif obj.node|isText %} -{{obj.node.text.na_web}} -{% else %} -Objekt jiného typu {{obj.node}} -{% endif %} - +{% include "seminar/treenode_name.html" %} {%if obj.children %}
- {# ----------- Přidáváme před prvního syna -------- #} - {% if obj.node|appendableChildren %} -
Přidat před - - -
- {% endif %}{# appendablebleChildren #} - {# ----------- /Přidáváme před -------- #} + {% with kam="před" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %} {%for ch in obj.children %} {# ----------- Vypisujeme podstrom ----------#} - {%with obj=ch depth=depth|add:"1" template_name="seminar/treenode_recursive.html" %} - {%include template_name%} - {%endwith%} - {# ----------- /Vypisujeme podstrom ---------#} + {%with obj=ch depth=depth|add:"1" %} {%include "seminar/treenode_recursive.html" %} {%endwith%} {# ----------- Přidáváme mezi syny / za posledního -------- #} - {% if obj.node|appendableChildren %} -
- {% if forloop.last %} Přidat za {% else %} Přidat mezi {% endif %} - - -
- {% endif %}{# appendablebleChildren #} - {# ----------- /Přidáváme mezi syny / za posledního -------- #} + {% if forloop.last %} + {% with kam="za" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %} + {% else %} + {% with kam="mezi" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %} + {% endif %} + {# ----------- Prohazujeme sousedy ----------#}
{% if not forloop.last and ch|editableSiblings %} {% endif %}
- - {% empty %} - {# ----------- Přidáváme prvního syna -------- #} - {% if obj.node|appendableChildren %} -
- Přidat jako syna - - -
- {% endif %} - {# ----------- /Přidáváme prvního syna -------- #} {% endfor %}
+{% else %} + {# ----------- Přidáváme prvního syna ----------#} + {% with kam="jako syna" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %} {%endif%}
diff --git a/seminar/templatetags/treenodes.py b/seminar/templatetags/treenodes.py index 5e28c31d..b1e7b65d 100644 --- a/seminar/templatetags/treenodes.py +++ b/seminar/templatetags/treenodes.py @@ -116,6 +116,41 @@ def editableChildren(value): return False return True +@register.filter +def textOnlySubtree(value): + text_only = True + if isText(value.node): + return True + if not isCast(value.node): + return False + for ch in value.children: + if not textOnlySubtree(ch): + return False + return True + +def canPodvesit(obj,new_parent): + if isCast(new_parent.node): +# print("Lze",obj,new_parent) + return True + if textOnlySubtree(obj): +# print("Lze",obj,new_parent) + return True + return False + +@register.filter +def canPodvesitZa(value): + if not value.index or value.index+1 >= len(value.parent.children): + return False + new_parent = value.parent.children[value.index+1] + return canPodvesit(value,new_parent) + +@register.filter +def canPodvesitPred(value): + if not value.index or value.index <= 0: + return False + new_parent = value.parent.children[value.index-1] + return canPodvesit(value,new_parent) + class NodeTypes(Enum): ROCNIK = ('rocnikNode','Ročník') diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 8bd850eb..48708b26 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -85,21 +85,22 @@ class ObalkovaniView(generic.ListView): return context class TNLData(object): - def __init__(self,anode,parent=None): + def __init__(self,anode,parent=None, index=None): self.node = anode self.children = [] self.parent = parent self.tema_in_path = False + self.index = index if parent: self.tema_in_path = parent.tema_in_path if isinstance(anode, m.TemaVCisleNode): self.tema_in_path = True @classmethod - def from_treenode(cls,anode,parent=None): - out = cls(anode,parent) - for ch in treelib.all_children(anode): - outitem = cls.from_treenode(ch,out) + def from_treenode(cls,anode,parent=None,index=None): + out = cls(anode,parent,index) + for (idx,ch) in enumerate(treelib.all_children(anode)): + outitem = cls.from_treenode(ch,out,idx) out.children.append(outitem) return out