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> #} | {# <b>{{depth}}</b> #} | ||||||
| <div class="borderized parent"> | <div class="borderized parent"> | ||||||
| <div class="node_type"> | <div class="node_type"> | ||||||
| {{obj.node}} | 	{{obj.node}} | ||||||
| {% if obj.node|deletable %} | 	{% if obj.node|deletable %} | ||||||
| 	<button>Smazat</button> | 		<button>Smazat</button> | ||||||
| {% endif %} | 	{% endif %} | ||||||
| {% if not obj.children and  obj.node|appendableChildren %} | 	{% if obj.parent and  obj.parent|editableSiblings %} | ||||||
| {% endif %} | 		<button>Odvěsit na úroveň {{obj.parent.node}}</button> | ||||||
| </div> | 	{% endif %} | ||||||
| {% if obj|editableSiblings %} | 	{% if obj|canPodvesitPred %} | ||||||
| <div class="node_move"> | 		<button>Podvěsit pod předchozí</button> - nejsou testovací data | ||||||
| 	<button>Odvěsit na úroveň {{obj.parent.node}}</button> | 	{% endif %} | ||||||
| 	<button>Podvěsit pod předchozí</button> | 	{% if obj|canPodvesitZa %} | ||||||
| </div> | 		<button>Podvěsit pod následující</button> - nejsou testovací data | ||||||
| {% endif %} | 	{% 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 %} |  | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | </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 %} | {%if obj.children %} | ||||||
| 	<div class="borderized children"> | 	<div class="borderized children"> | ||||||
| 
 | 
 | ||||||
| 		{# ----------- Přidáváme před prvního syna -------- #} | 		{% with kam="před" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %} | ||||||
| 		{% 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 -------- #} |  | ||||||
| 		{%for ch in obj.children %} | 		{%for ch in obj.children %} | ||||||
| 		 | 		 | ||||||
| 			{# ----------- Vypisujeme podstrom ----------#} | 			{# ----------- Vypisujeme podstrom ----------#} | ||||||
| 			{%with obj=ch depth=depth|add:"1" template_name="seminar/treenode_recursive.html" %} | 			{%with obj=ch depth=depth|add:"1" %} {%include "seminar/treenode_recursive.html" %} {%endwith%} | ||||||
| 				{%include template_name%} |  | ||||||
| 			{%endwith%} |  | ||||||
| 			{# ----------- /Vypisujeme podstrom ---------#} |  | ||||||
| 			{# ----------- Přidáváme mezi syny / za posledního -------- #} | 			{# ----------- Přidáváme mezi syny / za posledního -------- #} | ||||||
| 			{% if obj.node|appendableChildren %} | 			{% if forloop.last %} | ||||||
| 				<div class="pink"> | 				{% with kam="za" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %} | ||||||
| 					{% if forloop.last %} Přidat za {% else %} Přidat mezi {% endif %} | 			{% else %} | ||||||
| 					<select> | 				{% with kam="mezi" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %} | ||||||
| 						{% for chld in obj.node|appendableChildren %} | 			{% endif %} | ||||||
| 							<option value="{{chld.0}}">{{chld.1}}</option> | 			{# ----------- Prohazujeme sousedy ----------#} | ||||||
| 						{% endfor %} |  | ||||||
| 					</select> |  | ||||||
| 					<button>Přídat</button> |  | ||||||
| 				</div> |  | ||||||
| 			{% endif %}{# appendablebleChildren #} |  | ||||||
| 			{# ----------- /Přidáváme mezi syny / za posledního -------- #} |  | ||||||
| 			<div class="pink"> | 			<div class="pink"> | ||||||
| 			{% if not forloop.last and ch|editableSiblings %} | 			{% if not forloop.last and ch|editableSiblings %} | ||||||
| 				<button>Prohodit ^ a v</button> | 				<button>Prohodit ^ a v</button> | ||||||
| 			{% endif %} | 			{% endif %} | ||||||
| 			</div> | 			</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 %} | 		{% endfor %} | ||||||
| 	</div> | 	</div> | ||||||
|  | {% else %} | ||||||
|  | 	{# ----------- Přidáváme prvního syna ----------#} | ||||||
|  | 	{% with kam="jako syna" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %} | ||||||
| {%endif%} | {%endif%} | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
|  | @ -116,6 +116,41 @@ def editableChildren(value): | ||||||
| 		return False | 		return False | ||||||
| 	return True | 	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): | class NodeTypes(Enum): | ||||||
| 	ROCNIK = ('rocnikNode','Ročník') | 	ROCNIK = ('rocnikNode','Ročník') | ||||||
|  |  | ||||||
|  | @ -85,21 +85,22 @@ class ObalkovaniView(generic.ListView): | ||||||
| 		return context | 		return context | ||||||
| 
 | 
 | ||||||
| class TNLData(object): | class TNLData(object): | ||||||
| 	def __init__(self,anode,parent=None): | 	def __init__(self,anode,parent=None, index=None): | ||||||
| 		self.node = anode | 		self.node = anode | ||||||
| 		self.children = [] | 		self.children = [] | ||||||
| 		self.parent = parent | 		self.parent = parent | ||||||
| 		self.tema_in_path = False | 		self.tema_in_path = False | ||||||
|  | 		self.index = index | ||||||
| 		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, m.TemaVCisleNode): | ||||||
| 			self.tema_in_path = True | 			self.tema_in_path = True | ||||||
| 
 | 
 | ||||||
| 	@classmethod | 	@classmethod | ||||||
| 	def from_treenode(cls,anode,parent=None): | 	def from_treenode(cls,anode,parent=None,index=None): | ||||||
| 		out = cls(anode,parent) | 		out = cls(anode,parent,index) | ||||||
| 		for ch in treelib.all_children(anode): | 		for (idx,ch) in enumerate(treelib.all_children(anode)): | ||||||
| 			outitem = cls.from_treenode(ch,out) | 			outitem = cls.from_treenode(ch,out,idx) | ||||||
| 			out.children.append(outitem) | 			out.children.append(outitem) | ||||||
| 		return out | 		return out | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue