From 8bb6e770fe79568643b8fac06c6ef2e8def2730e Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Fri, 12 Jun 2020 01:56:07 +0200 Subject: [PATCH] seminar | treenode editor | prepracovan system pridavani TreeNodu Zatim jen rozepsano, nefunkcni. --- mamweb/static/css/mamweb-dev.css | 3 ++ seminar/static/seminar/treenode_editor.js | 18 +++++++++ seminar/templates/seminar/treenode.html | 1 + .../templates/seminar/treenode_add_stub.html | 14 ++++++- seminar/templatetags/treenodes.py | 38 +++++++++++++++++++ seminar/urls.py | 2 +- seminar/views/views_all.py | 38 +++++++++++++++---- 7 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 seminar/static/seminar/treenode_editor.js diff --git a/mamweb/static/css/mamweb-dev.css b/mamweb/static/css/mamweb-dev.css index 1f4d286d..23472e51 100644 --- a/mamweb/static/css/mamweb-dev.css +++ b/mamweb/static/css/mamweb-dev.css @@ -27,3 +27,6 @@ div.node_type { background-color: #d4d4d4; } +.hidden-tn { + display: none; +} diff --git a/seminar/static/seminar/treenode_editor.js b/seminar/static/seminar/treenode_editor.js new file mode 100644 index 00000000..d7f20d0d --- /dev/null +++ b/seminar/static/seminar/treenode_editor.js @@ -0,0 +1,18 @@ +function showSelectedItemForm(sel,id){ + var option; + var name; + var div; + Array.from(sel.options).forEach(function(option){ + console.log(option); + name = 'pridat-'+option.value+'-'+id; + div = document.getElementById(name); + console.log(div); + div.style.display = 'none'; + }); + name = sel.options[sel.selectedIndex].value; + name = 'pridat-'+name+'-'+id; + div = document.getElementById(name); + console.log(div); + div.style.display = 'block'; + +} diff --git a/seminar/templates/seminar/treenode.html b/seminar/templates/seminar/treenode.html index a6dc39f9..1440de86 100644 --- a/seminar/templates/seminar/treenode.html +++ b/seminar/templates/seminar/treenode.html @@ -10,6 +10,7 @@ dfsdfs {% block custom_css %} + {% endblock custom_css %} {% load comments %} diff --git a/seminar/templates/seminar/treenode_add_stub.html b/seminar/templates/seminar/treenode_add_stub.html index 09f2d2fa..dd3fc670 100644 --- a/seminar/templates/seminar/treenode_add_stub.html +++ b/seminar/templates/seminar/treenode_add_stub.html @@ -5,13 +5,23 @@ {% appendableChildren obj.parent as dostupne_typy %} {% endif %} +{# ulohaZadani ulohaVzorak Reseni Cast Text #} {% if dostupne_typy %}
Přidat {{kam}} - {% for typ in dostupne_typy %} {% endfor %} - +
+ Nadpis: + +
+
Vytvořit
+
Vytvořit, Tady bude autocomplete na reseniNode
+
Vytvořit zadání
+
Vytvořit vzorák k: Tady bude autocomplete na problémy k aktuálnímu kontextu
+ +
{% endif %}{# appendablebleChildren #} diff --git a/seminar/templatetags/treenodes.py b/seminar/templatetags/treenodes.py index 2aa914e4..f1fae1bf 100644 --- a/seminar/templatetags/treenodes.py +++ b/seminar/templatetags/treenodes.py @@ -185,7 +185,45 @@ def appendableChildren(value): return appendableChildren(value.parent) return None +@register.simple_tag +def canAppendReseni(value): + if isTemaVCisle(value.node): + return True + if isCast(value.node): + return canAppendReseni(value.parent) + return False + +@register.simple_tag +def canAppendUlohaZadani(value): + if isTemaVCisle(value.node): + return True + if isCast(value.node): + return canAppendUlohaZadani(value.parent) + return False + +@register.simple_tag +def canAppendUlohaVzorak(value): + if isTemaVCisle(value.node): + return True + if isCast(value.node): + return canAppendUlohaVzorak(value.parent) + return False +@register.simple_tag +def canAppendCast(value): + if isTemaVCisle(value.node) or isOrgText(value.node) or isReseni(value.node) or isUlohaZadani(value.node) or isUlohaVzorak(value.node): + return True + if isCast(value.node): + return canAppendCast(value.parent) + return False + +@register.simple_tag +def canAppendText(value): + if isTemaVCisle(value.node) or isOrgText(value.node) or isReseni(value.node) or isUlohaZadani(value.node) or isUlohaVzorak(value.node): + return True + if isCast(value.node): + return canAppendText(value.parent) + return False #@register.filter #def is(value): diff --git a/seminar/urls.py b/seminar/urls.py index 2b93f00b..b7633919 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -26,7 +26,7 @@ urlpatterns = [ path('cislo/./', views.CisloView.as_view(), name='seminar_cislo'), # odkomentované jenom kvůli testování archivu path('problem//', views.ProblemView.as_view(), name='seminar_problem'), path('treenode//', views.TreeNodeView.as_view(), name='seminar_treenode'), - path('treenode/editor/pridat///', views.TreeNodePridatView.as_view(), name='treenode_pridat'), + path('treenode/editor/pridat////', views.TreeNodePridatView.as_view(), name='treenode_pridat'), path('treenode/editor/smazat//', views.TreeNodeSmazatView.as_view(), name='treenode_smazat'), path('treenode/editor/odvesitpryc//', views.TreeNodeOdvesitPrycView.as_view(), name='treenode_odvesitpryc'), path('treenode/editor/podvesit///', views.TreeNodePodvesitView.as_view(), name='treenode_podvesit'), diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 9089b63b..a4448d8a 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -159,14 +159,40 @@ class TreeNodePridatView(generic.View): } def post(self, request, *args, **kwargs): + ######## FIXME: ROZEPSANE, NEFUNGUJE, DOPSAT !!!!!! ########### node = s.TreeNode.objects.get(pk=self.kwargs['pk']) kam = self.kwargs['kam'] + co = self.kwargs['co'] + typ = self.type_from_str[co] + + raise NotImplementedError('Neni to dopsane, dopis to!') + + if kam not in ('pred','syn','za'): + raise ValidationError('Přidat lze pouze před nebo za node nebo jako syna') + + if co == m.TextNode: + new_obj = m.Text() + new_obj.save() + elif co == m.CastNode: + new_obj = m.CastNode() + new_obj.nadpis = request.POST.get('pridat-castNode-{}-{}'.format(node.id,kam)) + new_obj.save() + elif co == m.ReseniNode: + new_obj = m. + pass + elif co == m.UlohaZadaniNode: + pass + elif co == m.UlohaReseniNode: + pass + else: + new_obj = None + + + if kam == 'pred': + pass + - 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] if typ == m.TextNode: text_obj = m.Text() text_obj.save() @@ -174,8 +200,6 @@ class TreeNodePridatView(generic.View): else: 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] if typ == m.TextNode: text_obj = m.Text() text_obj.save() @@ -226,7 +250,7 @@ class SirotcinecView(generic.ListView): template_name = 'seminar/orphanage.html' def get_queryset(self): - return s.TreeNode.objects.not_instance_of(s.RocnikNode).filter(root=None,succ=None,father_of_first=None) + return s.TreeNode.objects.not_instance_of(s.RocnikNode).filter(root=None,prev=None,succ=None,father_of_first=None) class ProblemView(generic.DetailView): model = s.Problem