Priprava GUI, chybi operace pro presun mezi vrstvami.
This commit is contained in:
		
							parent
							
								
									1b11c6a281
								
							
						
					
					
						commit
						49b517bef0
					
				
					 4 changed files with 226 additions and 55 deletions
				
			
		
							
								
								
									
										29
									
								
								mamweb/static/css/mamweb-dev.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								mamweb/static/css/mamweb-dev.css
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,29 @@ | |||
| .pink { | ||||
| 	background-color: #ffc0cb; | ||||
| } | ||||
| 
 | ||||
| div.borderized { | ||||
| 	border-style: solid; | ||||
| 	border-radius: 5px; | ||||
| 	padding: 5px; | ||||
| 	padding-right: 20px; | ||||
| } | ||||
| 
 | ||||
| div.tnmenu { | ||||
| 	float: right; | ||||
| 	margin-right: 0px; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| div.parent { | ||||
| 	border-width: 2px; | ||||
| } | ||||
| 
 | ||||
| div.children { | ||||
| 	border-width: 1px; | ||||
| } | ||||
| 
 | ||||
| div.node_type { | ||||
| 	background-color: #d4d4d4; | ||||
| } | ||||
| 
 | ||||
|  | @ -2,11 +2,19 @@ | |||
| {# <b>{{depth}}</b> #} | ||||
| <div class="borderized parent"> | ||||
| <div class="node_type"> | ||||
| 	{{obj.node}} | ||||
| {{obj.node}} | ||||
| {% if obj.node|deletable %} | ||||
| 	<button>Smazat</button> | ||||
| 	<button>O úroveň výš</button> | ||||
| 	<button>Podvěsit pod ^</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 %} | ||||
|  | @ -22,38 +30,63 @@ | |||
| {% else %} | ||||
| Objekt jiného typu {{obj.node}} | ||||
| {% endif %} | ||||
|     {%if obj.children %} | ||||
| 	<div class="borderized children"> | ||||
| 	 <div class="pink">Přidat před | ||||
| 		 <select> | ||||
| 			<option value="TextNode">Text</option> | ||||
| 			<option value="NadpisNode">Nadpis</option> | ||||
| 			<option value="UlohaNode">Úloha</option> | ||||
| 			<option value="TemaNode">Téma</option> | ||||
| 		 </select> | ||||
| 		 <button>Přídat</button> | ||||
| 	 </div> | ||||
|          {%for ch in obj.children %} | ||||
|               {%with obj=ch depth=depth|add:"1" template_name="seminar/treenode_recursive.html" %} | ||||
|                    {%include template_name%} | ||||
|               {%endwith%} | ||||
| 	      <div class="pink"> | ||||
| 		      {% if forloop.last %} Přidat za {% else %} Přidat mezi {% endif %} | ||||
| 		 <select> | ||||
| 			<option value="TextNode">Text</option> | ||||
| 			<option value="NadpisNode">Nadpis</option> | ||||
| 			<option value="UlohaNode">Úloha</option> | ||||
| 			<option value="TemaNode">Téma</option> | ||||
| 		 </select> | ||||
| 		 <button>Přídat na stejnou úroveň</button> | ||||
| 		 <button>Přídat jako syna</button> | ||||
| 		     | ||||
| 		 {% if not forloop.last %} | ||||
| 		 <button>Prohodit ^ a v</button> | ||||
| 		 {% endif %} | ||||
| 
 | ||||
| 	      </div> | ||||
|          {%endfor%} | ||||
| {%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 -------- #} | ||||
| 		{%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 ---------#} | ||||
| 			{# ----------- 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 -------- #} | ||||
| 			<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> | ||||
|     {%endif%} | ||||
| {%endif%} | ||||
| </div> | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| from django import template | ||||
| from enum import Enum | ||||
| import seminar.models as m | ||||
| 
 | ||||
| register = template.Library() | ||||
|  | @ -18,45 +19,144 @@ def nodeType(value): | |||
| 
 | ||||
| @register.filter | ||||
| def isRocnik(value): | ||||
| 	 return isinstance(value, m.RocnikNode) | ||||
| 	return isinstance(value, m.RocnikNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isCislo(value): | ||||
| 	 return isinstance(value, m.CisloNode) | ||||
| 	return isinstance(value, m.CisloNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isCast(value): | ||||
| 	 return isinstance(value, m.CastNode) | ||||
| 	return isinstance(value, m.CastNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isText(value): | ||||
| 	 return isinstance(value, m.TextNode) | ||||
| 	return isinstance(value, m.TextNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isTemaVCisle(value): | ||||
| 	 return isinstance(value, m.TemaVCisleNode) | ||||
| 	return isinstance(value, m.TemaVCisleNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isKonfera(value): | ||||
| 	 return isinstance(value, m.KonferaNode) | ||||
| 	return isinstance(value, m.KonferaNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isClanek(value): | ||||
| 	 return isinstance(value, m.ClanekNode) | ||||
| 	return isinstance(value, m.ClanekNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isUlohaVzorak(value): | ||||
| 	 return isinstance(value, m.UlohaVzorakNode) | ||||
| 	return isinstance(value, m.UlohaVzorakNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isUlohaZadani(value): | ||||
| 	 return isinstance(value, m.UlohaZadaniNode) | ||||
| 	return isinstance(value, m.UlohaZadaniNode) | ||||
| 
 | ||||
| @register.filter | ||||
| def isPohadka(value): | ||||
| 	 return isinstance(value, m.PohadkaNode) | ||||
| 	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 isOtisteneReseniNode(value): | ||||
| #	 return isinstance(value, m.OtisteneReseniNode) | ||||
| #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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin | |||
| from django.db import transaction | ||||
| 
 | ||||
| import seminar.models as s | ||||
| import seminar.models as m | ||||
| from seminar.models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Tema, Clanek, Osoba, Skola # Tohle je stare a chceme se toho zbavit. Pouzivejte s.ToCoChci | ||||
| #from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva | ||||
| from seminar import utils,treelib | ||||
|  | @ -84,17 +85,25 @@ class ObalkovaniView(generic.ListView): | |||
| 		return context | ||||
| 
 | ||||
| class TNLData(object): | ||||
| 	def __init__(self,anode): | ||||
| 	def __init__(self,anode,parent=None): | ||||
| 		self.node = anode | ||||
| 		self.children = [] | ||||
| 		self.parent = parent | ||||
| 		self.tema_in_path = False | ||||
| 		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) | ||||
| 			out.children.append(outitem) | ||||
| 		return out | ||||
| 
 | ||||
| 
 | ||||
| def treenode_strom_na_seznamy(node): | ||||
| 	out = TNLData(node) | ||||
| 	for ch in treelib.all_children(node): | ||||
| 		outitem = treenode_strom_na_seznamy(ch) | ||||
| 		out.children.append(outitem) | ||||
| 	return out | ||||
| 
 | ||||
| class TreeNodeView(generic.DetailView): | ||||
| 	model = s.TreeNode | ||||
|  | @ -102,7 +111,7 @@ class TreeNodeView(generic.DetailView): | |||
| 
 | ||||
| 	def get_context_data(self,**kwargs): | ||||
| 		context = super().get_context_data(**kwargs) | ||||
| 		context['tnldata'] = treenode_strom_na_seznamy(self.object) | ||||
| 		context['tnldata'] = TNLData.from_treenode(self.object) | ||||
| 		return context | ||||
| 	 | ||||
| # TODO Co chceme vlastně zobrazovat na této stránce? Zatím je zde aktuální číslo, ale může tu být cokoli jiného... | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue