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 %}
|
||||
|
||||
<form>
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
{%with obj=tnldata depth=1 template_name="seminar/treenode_recursive.html" %}
|
||||
{%include template_name%}
|
||||
{%endwith%}
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
{% 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}}
|
||||
<select>
|
||||
{% for chld in obj.node|appendableChildren %}
|
||||
<option value="{{chld.0}}">{{chld.1}}</option>
|
||||
<select name="pridat-typ-{{obj.node.id}}-{{kam_slug}}">
|
||||
{% for typ in dostupne_typy %}
|
||||
<option value="{{typ.0}}">{{typ.1}}</option>
|
||||
{% endfor %}
|
||||
</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>
|
||||
{% endif %}{# appendablebleChildren #}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
<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|isCast %}
|
||||
<h{{depth}}> {{obj.node.nadpis}} </h{{depth}}>
|
||||
{% elif obj.node|isText %}
|
||||
{{obj.node.text.na_web}}
|
||||
{% else %}
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
<button type="submit" formaction="{%url 'treenode_odvesit' obj.node.id%}">Odvěsit na úroveň {{obj.parent.node}}</button>
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
|
||||
|
||||
|
@ -28,16 +28,16 @@
|
|||
{%if obj.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 %}
|
||||
|
||||
{# ----------- 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 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 %}
|
||||
{% 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 %}
|
||||
{# ----------- Prohazujeme sousedy ----------#}
|
||||
<div class="pink">
|
||||
|
@ -49,6 +49,6 @@
|
|||
</div>
|
||||
{% else %}
|
||||
{# ----------- 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%}
|
||||
</div>
|
||||
|
|
|
@ -155,6 +155,7 @@ def canPodvesitPred(value):
|
|||
class NodeTypes(Enum):
|
||||
ROCNIK = ('rocnikNode','Ročník')
|
||||
CISLO = ('cisloNode', 'Číslo')
|
||||
MEZICISLO = ('mezicisloNode', 'Mezičíslo')
|
||||
CAST = ('castNode', 'Část')
|
||||
TEXT = ('textNode', 'Text')
|
||||
TEMAVCISLE = ('temaVCisleNode', 'Téma v čísle')
|
||||
|
@ -167,16 +168,16 @@ class NodeTypes(Enum):
|
|||
|
||||
|
||||
|
||||
@register.filter
|
||||
@register.simple_tag
|
||||
def appendableChildren(value):
|
||||
if isTemaVCisle(value):
|
||||
if isTemaVCisle(value.node):
|
||||
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):
|
||||
if isOrgText(value.node) or isReseni(value.node) or isUlohaZadani(value.node) or isUlohaVzorak(value.node):
|
||||
return (NodeTypes.CAST.value,
|
||||
NodeTypes.TEXT.value,
|
||||
)
|
||||
|
|
|
@ -181,6 +181,7 @@ def create_node_after(predecessor, type, **kwargs):
|
|||
predecessor.save()
|
||||
new_node.succ = succ
|
||||
new_node.save()
|
||||
return new_node
|
||||
|
||||
# Vyrábí prvního syna, ostatní nalepí za (existují-li)
|
||||
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
|
||||
new_node.succ = orig_child
|
||||
new_node.save()
|
||||
return new_node
|
||||
|
||||
def insert_last_child(parent, node):
|
||||
""" 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.succ = successor
|
||||
new.save()
|
||||
return new
|
||||
|
||||
|
||||
# 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('problem/<int:pk>/', views.ProblemView.as_view(), name='seminar_problem'),
|
||||
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/smazat/<int:pk>', views.TreeNodeView.as_view(), name='treenode_smazat'),
|
||||
path('treenode/editor/odvesit/<int:pk>', views.TreeNodeView.as_view(), name='treenode_odvesit'),
|
||||
path('treenode/editor/podvesit/predchozi/<int:pk>', views.TreeNodeView.as_view(), name='treenode_podvesit_predchozi'),
|
||||
path('treenode/editor/podvesit/nasledujici/<int:pk>', views.TreeNodeView.as_view(), name='treenode_podvesit_nasledujici'),
|
||||
path('treenode/editor/prohodit/<int:pk>', views.TreeNodeView.as_view(), name='treenode_prohodit'),
|
||||
path('treenode/editor/pridat/<int:pk>/<str:kam>/', views.TreeNodePridatView.as_view(), name='treenode_pridat'),
|
||||
path('treenode/editor/smazat/<int:pk>/', views.TreeNodeSmazatView.as_view(), name='treenode_smazat'),
|
||||
path('treenode/editor/odvesit/<int:pk>/', views.TreeNodeOdvesitView.as_view(), name='treenode_odvesit'),
|
||||
path('treenode/editor/podvesit/<int:pk>/<str:kam>/', views.TreeNodePodvesitView.as_view(), name='treenode_podvesit'),
|
||||
path('treenode/editor/prohodit/<int:pk>/', views.TreeNodeProhoditView.as_view(), name='treenode_prohodit'),
|
||||
#path('problem/(?P<pk>\d+)/(?P<prispevek>\d+)/', views.PrispevekView.as_view(), name='seminar_problem_prispevek'),
|
||||
|
||||
# Soustredeni
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# 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.urls import reverse,reverse_lazy
|
||||
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
|
||||
|
@ -133,6 +133,8 @@ class TNLData(object):
|
|||
for tnl in result:
|
||||
found.append(tnl)
|
||||
return found
|
||||
def __repr__(self):
|
||||
return("TNL({})".format(self.node))
|
||||
|
||||
class TreeNodeView(generic.DetailView):
|
||||
model = s.TreeNode
|
||||
|
@ -143,6 +145,68 @@ class TreeNodeView(generic.DetailView):
|
|||
context['tnldata'] = TNLData.from_treenode(self.object)
|
||||
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):
|
||||
model = s.Problem
|
||||
# Zkopírujeme template_name od TreeNodeView, protože jsme prakticky jen trošku upravený TreeNodeView
|
||||
|
|
Loading…
Reference in a new issue