seminar | treenode editor | Prototyp pridavani, funguje jen neco
This commit is contained in:
parent
84dcb34a70
commit
98eed4bab4
8 changed files with 98 additions and 22 deletions
|
@ -16,7 +16,8 @@ dfsdfs
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<form>
|
<form method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
{%with obj=tnldata depth=1 template_name="seminar/treenode_recursive.html" %}
|
{%with obj=tnldata depth=1 template_name="seminar/treenode_recursive.html" %}
|
||||||
{%include template_name%}
|
{%include template_name%}
|
||||||
{%endwith%}
|
{%endwith%}
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
{% load treenodes %}
|
{% load treenodes %}
|
||||||
{% if obj.node|appendableChildren %}
|
{% if kam_slug == "syn" %}
|
||||||
|
{% appendableChildren obj as dostupne_typy %}
|
||||||
|
{% else %}
|
||||||
|
{% appendableChildren obj.parent as dostupne_typy %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if dostupne_typy %}
|
||||||
<div class="pink">Přidat {{kam}}
|
<div class="pink">Přidat {{kam}}
|
||||||
<select>
|
<select name="pridat-typ-{{obj.node.id}}-{{kam_slug}}">
|
||||||
{% for chld in obj.node|appendableChildren %}
|
{% for typ in dostupne_typy %}
|
||||||
<option value="{{chld.0}}">{{chld.1}}</option>
|
<option value="{{typ.0}}">{{typ.1}}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<button action="submit" formaction="{%url 'treenode_pridat' obj.node.id%}">Přidat</button>
|
<button action="submit" formaction="{%url 'treenode_pridat' obj.node.id kam_slug%}">Přidat</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}{# appendablebleChildren #}
|
{% endif %}{# appendablebleChildren #}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
<h{{depth}}>Úloha {{obj.node.uloha.kod_v_rocniku}} ({{obj.node.uloha.max_body}} b)</h{{depth}}>
|
<h{{depth}}>Úloha {{obj.node.uloha.kod_v_rocniku}} ({{obj.node.uloha.max_body}} b)</h{{depth}}>
|
||||||
{% elif obj.node|isUlohaVzorak %}
|
{% elif obj.node|isUlohaVzorak %}
|
||||||
<h{{depth}}>Řešení: {{obj.node.uloha.kod_v_rocniku}}</h{{depth}}>
|
<h{{depth}}>Řešení: {{obj.node.uloha.kod_v_rocniku}}</h{{depth}}>
|
||||||
|
{% elif obj.node|isCast %}
|
||||||
|
<h{{depth}}> {{obj.node.nadpis}} </h{{depth}}>
|
||||||
{% elif obj.node|isText %}
|
{% elif obj.node|isText %}
|
||||||
{{obj.node.text.na_web}}
|
{{obj.node.text.na_web}}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
<button type="submit" formaction="{%url 'treenode_odvesit' obj.node.id%}">Odvěsit na úroveň {{obj.parent.node}}</button>
|
<button type="submit" formaction="{%url 'treenode_odvesit' obj.node.id%}">Odvěsit na úroveň {{obj.parent.node}}</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if obj|canPodvesitPred %}
|
{% if obj|canPodvesitPred %}
|
||||||
<button type="submit" formaction="{%url 'treenode_podvesit_predchozi' obj.node.id%}">Podvěsit pod předchozí</button> - nejsou testovací data
|
<button type="submit" formaction="{%url 'treenode_podvesit' obj.node.id 'predchozi'%}">Podvěsit pod předchozí</button> - nejsou testovací data
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if obj|canPodvesitZa %}
|
{% if obj|canPodvesitZa %}
|
||||||
<button type="submit" formaction="{%url 'treenode_podvesit_nasledujici' obj.node.id%}">Podvěsit pod následující</button> - nejsou testovací data
|
<button type="submit" formaction="{%url 'treenode_podvesit' obj.node.id 'nasledujíci'%}">Podvěsit pod následující</button> - nejsou testovací data
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,16 +28,16 @@
|
||||||
{%if obj.children %}
|
{%if obj.children %}
|
||||||
<div class="borderized children">
|
<div class="borderized children">
|
||||||
|
|
||||||
{% with kam="před" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
{% with kam="před" kam_slug="syn" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
||||||
{%for ch in obj.children %}
|
{%for ch in obj.children %}
|
||||||
|
|
||||||
{# ----------- Vypisujeme podstrom ----------#}
|
{# ----------- Vypisujeme podstrom ----------#}
|
||||||
{%with obj=ch depth=depth|add:"1" %} {%include "seminar/treenode_recursive.html" %} {%endwith%}
|
{%with obj=ch depth=depth|add:"1" %} {%include "seminar/treenode_recursive.html" %} {%endwith%}
|
||||||
{# ----------- Přidáváme mezi syny / za posledního -------- #}
|
{# ----------- Přidáváme mezi syny / za posledního -------- #}
|
||||||
{% if forloop.last %}
|
{% if forloop.last %}
|
||||||
{% with kam="za" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
{% with kam="za" kam_slug="za" obj=ch %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% with kam="mezi" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
{% with kam="mezi" obj=ch kam_slug="za" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# ----------- Prohazujeme sousedy ----------#}
|
{# ----------- Prohazujeme sousedy ----------#}
|
||||||
<div class="pink">
|
<div class="pink">
|
||||||
|
@ -49,6 +49,6 @@
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
{# ----------- Přidáváme prvního syna ----------#}
|
{# ----------- Přidáváme prvního syna ----------#}
|
||||||
{% with kam="jako syna" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
{% with kam="jako syna" kam_slug="syn" %} {% include "seminar/treenode_add_stub.html" %} {% endwith %}
|
||||||
{%endif%}
|
{%endif%}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -155,6 +155,7 @@ def canPodvesitPred(value):
|
||||||
class NodeTypes(Enum):
|
class NodeTypes(Enum):
|
||||||
ROCNIK = ('rocnikNode','Ročník')
|
ROCNIK = ('rocnikNode','Ročník')
|
||||||
CISLO = ('cisloNode', 'Číslo')
|
CISLO = ('cisloNode', 'Číslo')
|
||||||
|
MEZICISLO = ('mezicisloNode', 'Mezičíslo')
|
||||||
CAST = ('castNode', 'Část')
|
CAST = ('castNode', 'Část')
|
||||||
TEXT = ('textNode', 'Text')
|
TEXT = ('textNode', 'Text')
|
||||||
TEMAVCISLE = ('temaVCisleNode', 'Téma v čísle')
|
TEMAVCISLE = ('temaVCisleNode', 'Téma v čísle')
|
||||||
|
@ -167,16 +168,16 @@ class NodeTypes(Enum):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.simple_tag
|
||||||
def appendableChildren(value):
|
def appendableChildren(value):
|
||||||
if isTemaVCisle(value):
|
if isTemaVCisle(value.node):
|
||||||
return (NodeTypes.RESENI.value,
|
return (NodeTypes.RESENI.value,
|
||||||
NodeTypes.ULOHAZADANI.value,
|
NodeTypes.ULOHAZADANI.value,
|
||||||
NodeTypes.ULOHAVZORAK.value,
|
NodeTypes.ULOHAVZORAK.value,
|
||||||
NodeTypes.CAST.value,
|
NodeTypes.CAST.value,
|
||||||
NodeTypes.TEXT.value,
|
NodeTypes.TEXT.value,
|
||||||
)
|
)
|
||||||
if isOrgText(value) or isReseni(value) or isUlohaZadani(value) or isUlohaVzorak(value):
|
if isOrgText(value.node) or isReseni(value.node) or isUlohaZadani(value.node) or isUlohaVzorak(value.node):
|
||||||
return (NodeTypes.CAST.value,
|
return (NodeTypes.CAST.value,
|
||||||
NodeTypes.TEXT.value,
|
NodeTypes.TEXT.value,
|
||||||
)
|
)
|
||||||
|
|
|
@ -181,6 +181,7 @@ def create_node_after(predecessor, type, **kwargs):
|
||||||
predecessor.save()
|
predecessor.save()
|
||||||
new_node.succ = succ
|
new_node.succ = succ
|
||||||
new_node.save()
|
new_node.save()
|
||||||
|
return new_node
|
||||||
|
|
||||||
# Vyrábí prvního syna, ostatní nalepí za (existují-li)
|
# Vyrábí prvního syna, ostatní nalepí za (existují-li)
|
||||||
def create_child(parent, type, **kwargs):
|
def create_child(parent, type, **kwargs):
|
||||||
|
@ -193,6 +194,7 @@ def create_child(parent, type, **kwargs):
|
||||||
# Přidáme původního prvního syna jako potomka nového vrcholu
|
# Přidáme původního prvního syna jako potomka nového vrcholu
|
||||||
new_node.succ = orig_child
|
new_node.succ = orig_child
|
||||||
new_node.save()
|
new_node.save()
|
||||||
|
return new_node
|
||||||
|
|
||||||
def insert_last_child(parent, node):
|
def insert_last_child(parent, node):
|
||||||
""" Zadaný Node přidá jako posledního potomka otce. """
|
""" Zadaný Node přidá jako posledního potomka otce. """
|
||||||
|
@ -225,6 +227,7 @@ def create_node_before(successor, type, **kwargs):
|
||||||
new = type.objects.create(**kwargs)
|
new = type.objects.create(**kwargs)
|
||||||
new.succ = successor
|
new.succ = successor
|
||||||
new.save()
|
new.save()
|
||||||
|
return new
|
||||||
|
|
||||||
|
|
||||||
# ValueError, pokud je (aspoň) jeden parametr None
|
# ValueError, pokud je (aspoň) jeden parametr None
|
||||||
|
|
|
@ -26,12 +26,11 @@ urlpatterns = [
|
||||||
path('cislo/<int:rocnik>.<int:cislo>/', views.CisloView.as_view(), name='seminar_cislo'), # odkomentované jenom kvůli testování archivu
|
path('cislo/<int:rocnik>.<int:cislo>/', views.CisloView.as_view(), name='seminar_cislo'), # odkomentované jenom kvůli testování archivu
|
||||||
path('problem/<int:pk>/', views.ProblemView.as_view(), name='seminar_problem'),
|
path('problem/<int:pk>/', views.ProblemView.as_view(), name='seminar_problem'),
|
||||||
path('treenode/<int:pk>/', views.TreeNodeView.as_view(), name='seminar_treenode'),
|
path('treenode/<int:pk>/', views.TreeNodeView.as_view(), name='seminar_treenode'),
|
||||||
path('treenode/editor/pridat/<int:pk>', views.TreeNodeView.as_view(), name='treenode_pridat'),
|
path('treenode/editor/pridat/<int:pk>/<str:kam>/', views.TreeNodePridatView.as_view(), name='treenode_pridat'),
|
||||||
path('treenode/editor/smazat/<int:pk>', views.TreeNodeView.as_view(), name='treenode_smazat'),
|
path('treenode/editor/smazat/<int:pk>/', views.TreeNodeSmazatView.as_view(), name='treenode_smazat'),
|
||||||
path('treenode/editor/odvesit/<int:pk>', views.TreeNodeView.as_view(), name='treenode_odvesit'),
|
path('treenode/editor/odvesit/<int:pk>/', views.TreeNodeOdvesitView.as_view(), name='treenode_odvesit'),
|
||||||
path('treenode/editor/podvesit/predchozi/<int:pk>', views.TreeNodeView.as_view(), name='treenode_podvesit_predchozi'),
|
path('treenode/editor/podvesit/<int:pk>/<str:kam>/', views.TreeNodePodvesitView.as_view(), name='treenode_podvesit'),
|
||||||
path('treenode/editor/podvesit/nasledujici/<int:pk>', views.TreeNodeView.as_view(), name='treenode_podvesit_nasledujici'),
|
path('treenode/editor/prohodit/<int:pk>/', views.TreeNodeProhoditView.as_view(), name='treenode_prohodit'),
|
||||||
path('treenode/editor/prohodit/<int:pk>', views.TreeNodeView.as_view(), name='treenode_prohodit'),
|
|
||||||
#path('problem/(?P<pk>\d+)/(?P<prispevek>\d+)/', views.PrispevekView.as_view(), name='seminar_problem_prispevek'),
|
#path('problem/(?P<pk>\d+)/(?P<prispevek>\d+)/', views.PrispevekView.as_view(), name='seminar_problem_prispevek'),
|
||||||
|
|
||||||
# Soustredeni
|
# Soustredeni
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# coding:utf-8
|
# coding:utf-8
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render, redirect
|
||||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, JsonResponse
|
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, JsonResponse
|
||||||
from django.urls import reverse,reverse_lazy
|
from django.urls import reverse,reverse_lazy
|
||||||
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
|
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
|
||||||
|
@ -133,6 +133,8 @@ class TNLData(object):
|
||||||
for tnl in result:
|
for tnl in result:
|
||||||
found.append(tnl)
|
found.append(tnl)
|
||||||
return found
|
return found
|
||||||
|
def __repr__(self):
|
||||||
|
return("TNL({})".format(self.node))
|
||||||
|
|
||||||
class TreeNodeView(generic.DetailView):
|
class TreeNodeView(generic.DetailView):
|
||||||
model = s.TreeNode
|
model = s.TreeNode
|
||||||
|
@ -143,6 +145,68 @@ class TreeNodeView(generic.DetailView):
|
||||||
context['tnldata'] = TNLData.from_treenode(self.object)
|
context['tnldata'] = TNLData.from_treenode(self.object)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
class TreeNodePridatView(generic.View):
|
||||||
|
type_from_str = {
|
||||||
|
'rocnikNode': m.RocnikNode,
|
||||||
|
'cisloNode': m.CisloNode,
|
||||||
|
'castNode': m.CastNode,
|
||||||
|
'textNode': m.TextNode,
|
||||||
|
'temaVCisleNode': m.TemaVCisleNode,
|
||||||
|
'reseniNode': m.ReseniNode,
|
||||||
|
'ulohaZadaniNode': m.UlohaZadaniNode,
|
||||||
|
'ulohaVzorakNode': m.UlohaVzorakNode,
|
||||||
|
'pohadkaNode': m.PohadkaNode,
|
||||||
|
'orgText': m.OrgTextNode,
|
||||||
|
}
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
kam = self.kwargs['kam']
|
||||||
|
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||||
|
|
||||||
|
if kam not in ('syn','za'):
|
||||||
|
raise ValidationError('Přidat lze pouze před nebo za node')
|
||||||
|
if kam == 'syn':
|
||||||
|
strtyp = request.POST.get('pridat-typ-{}-syn'.format(node.id))
|
||||||
|
typ = self.type_from_str[strtyp]
|
||||||
|
node = treelib.create_child(node,typ)
|
||||||
|
if kam == 'za':
|
||||||
|
strtyp = request.POST.get('pridat-typ-{}-za'.format(node.id))
|
||||||
|
typ = self.type_from_str[strtyp]
|
||||||
|
node = treelib.create_node_after(node,typ)
|
||||||
|
|
||||||
|
return redirect(node.get_admin_url())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TreeNodeSmazatView(generic.base.View):
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TreeNodeOdvesitView(generic.base.View):
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TreeNodePodvesitView(generic.base.View):
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TreeNodeProhoditView(generic.base.View):
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ProblemView(generic.DetailView):
|
class ProblemView(generic.DetailView):
|
||||||
model = s.Problem
|
model = s.Problem
|
||||||
# Zkopírujeme template_name od TreeNodeView, protože jsme prakticky jen trošku upravený TreeNodeView
|
# Zkopírujeme template_name od TreeNodeView, protože jsme prakticky jen trošku upravený TreeNodeView
|
||||||
|
|
Loading…
Reference in a new issue