GUI temer hotovo, ceka na testovaci data.
This commit is contained in:
parent
49b517bef0
commit
6846f20898
5 changed files with 101 additions and 76 deletions
11
seminar/templates/seminar/treenode_add_stub.html
Normal file
11
seminar/templates/seminar/treenode_add_stub.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% load treenodes %}
|
||||
{% if obj.node|appendableChildren %}
|
||||
<div class="pink">Přidat {{kam}}
|
||||
<select>
|
||||
{% for chld in obj.node|appendableChildren %}
|
||||
<option value="{{chld.0}}">{{chld.1}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button>Přídat</button>
|
||||
</div>
|
||||
{% endif %}{# appendablebleChildren #}
|
16
seminar/templates/seminar/treenode_name.html
Normal file
16
seminar/templates/seminar/treenode_name.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
{% load treenodes %}
|
||||
{% if obj.node|isRocnik %}
|
||||
<h{{depth}}> Ročník {{obj.node.rocnik}} </h{{depth}}>
|
||||
{% elif obj.node|isCislo %}
|
||||
<h{{depth}}> Číslo {{obj.node.cislo}} </h{{depth}}>
|
||||
{% elif obj.node|isTemaVCisle %}
|
||||
<h{{depth}}> Téma {{obj.node.tema.nazev}} </h{{depth}}>
|
||||
{% elif obj.node|isUlohaZadani %}
|
||||
<h{{depth}}>Úloha {{obj.node.uloha.kod_v_rocniku}} ({{obj.node.uloha.max_body}} b)</h{{depth}}>
|
||||
{% elif obj.node|isUlohaVzorak %}
|
||||
<h{{depth}}>Řešení: {{obj.node.uloha.kod_v_rocniku}}</h{{depth}}>
|
||||
{% elif obj.node|isText %}
|
||||
{{obj.node.text.na_web}}
|
||||
{% else %}
|
||||
Objekt jiného typu {{obj.node}}
|
||||
{% endif %}
|
|
@ -2,91 +2,53 @@
|
|||
{# <b>{{depth}}</b> #}
|
||||
<div class="borderized parent">
|
||||
<div class="node_type">
|
||||
{{obj.node}}
|
||||
{% if obj.node|deletable %}
|
||||
<button>Smazat</button>
|
||||
{% endif %}
|
||||
{% if not obj.children and obj.node|appendableChildren %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if obj|editableSiblings %}
|
||||
<div class="node_move">
|
||||
<button>Odvěsit na úroveň {{obj.parent.node}}</button>
|
||||
<button>Podvěsit pod předchozí</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if obj.node|isRocnik %}
|
||||
<h{{depth}}> Ročník {{obj.node.rocnik}} </h{{depth}}>
|
||||
{% elif obj.node|isCislo %}
|
||||
<h{{depth}}> Číslo {{obj.node.cislo}} </h{{depth}}>
|
||||
{% elif obj.node|isTemaVCisle %}
|
||||
<h{{depth}}> Téma {{obj.node.tema.nazev}} </h{{depth}}>
|
||||
{% elif obj.node|isUlohaZadani %}
|
||||
<h{{depth}}>Úloha {{obj.node.uloha.kod_v_rocniku}} ({{obj.node.uloha.max_body}} b)</h{{depth}}>
|
||||
{% elif obj.node|isUlohaVzorak %}
|
||||
<h{{depth}}>Řešení: {{obj.node.uloha.kod_v_rocniku}}</h{{depth}}>
|
||||
{% elif obj.node|isText %}
|
||||
{{obj.node.text.na_web}}
|
||||
{% else %}
|
||||
Objekt jiného typu {{obj.node}}
|
||||
{% endif %}
|
||||
{{obj.node}}
|
||||
{% if obj.node|deletable %}
|
||||
<button>Smazat</button>
|
||||
{% endif %}
|
||||
{% if obj.parent and obj.parent|editableSiblings %}
|
||||
<button>Odvěsit na úroveň {{obj.parent.node}}</button>
|
||||
{% endif %}
|
||||
{% if obj|canPodvesitPred %}
|
||||
<button>Podvěsit pod předchozí</button> - nejsou testovací data
|
||||
{% endif %}
|
||||
{% if obj|canPodvesitZa %}
|
||||
<button>Podvěsit pod následující</button> - nejsou testovací data
|
||||
{% endif %}
|
||||
|
||||
|
||||
</div>
|
||||
{% if False %}
|
||||
<div class="node_move">
|
||||
FIXME: není zatím implementováno
|
||||
<button>Zvyš úroveň nadpisu</button> - nejsou testovací data
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include "seminar/treenode_name.html" %}
|
||||
{%if obj.children %}
|
||||
<div class="borderized children">
|
||||
|
||||
{# ----------- Přidáváme před prvního syna -------- #}
|
||||
{% if obj.node|appendableChildren %}
|
||||
<div class="pink">Přidat před
|
||||
<select>
|
||||
{% for chld in obj.node|appendableChildren %}
|
||||
<option value="{{chld.0}}">{{chld.1}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button>Přídat</button>
|
||||
</div>
|
||||
{% 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 %}
|
||||
<div class="pink">
|
||||
{% if forloop.last %} Přidat za {% else %} Přidat mezi {% endif %}
|
||||
<select>
|
||||
{% for chld in obj.node|appendableChildren %}
|
||||
<option value="{{chld.0}}">{{chld.1}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button>Přídat</button>
|
||||
</div>
|
||||
{% 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 ----------#}
|
||||
<div class="pink">
|
||||
{% if not forloop.last and ch|editableSiblings %}
|
||||
<button>Prohodit ^ a v</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% empty %}
|
||||
{# ----------- Přidáváme prvního syna -------- #}
|
||||
{% if obj.node|appendableChildren %}
|
||||
<div class="pink">
|
||||
Přidat jako syna
|
||||
<select>
|
||||
{% for chld in obj.node|appendableChildren %}
|
||||
<option value="{{chld.0}}">{{chld.1}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button>Přidat</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{# ----------- /Přidáváme prvního syna -------- #}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{# ----------- Přidáváme prvního syna ----------#}
|
||||
{% with kam="jako syna" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
||||
{%endif%}
|
||||
</div>
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue