Browse Source

seminar | treenode editor | prepracovan system pridavani TreeNodu

Zatim jen rozepsano, nefunkcni.
export_seznamu_prednasek
parent
commit
8bb6e770fe
  1. 3
      mamweb/static/css/mamweb-dev.css
  2. 18
      seminar/static/seminar/treenode_editor.js
  3. 1
      seminar/templates/seminar/treenode.html
  4. 12
      seminar/templates/seminar/treenode_add_stub.html
  5. 38
      seminar/templatetags/treenodes.py
  6. 2
      seminar/urls.py
  7. 38
      seminar/views/views_all.py

3
mamweb/static/css/mamweb-dev.css

@ -27,3 +27,6 @@ div.node_type {
background-color: #d4d4d4;
}
.hidden-tn {
display: none;
}

18
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';
}

1
seminar/templates/seminar/treenode.html

@ -10,6 +10,7 @@ dfsdfs
{% block custom_css %}
<link rel="stylesheet" type="text/css" href="{% static 'css/mamweb-dev.css' %}" />
<script src="/static/seminar/treenode_editor.js"></script>
{% endblock custom_css %}
{% load comments %}

12
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 %}
<div class="pink">Přidat {{kam}}
<select name="pridat-typ-{{obj.node.id}}-{{kam_slug}}">
<select name="pridat-typ-{{obj.node.id}}-{{kam_slug}}" onchange="showSelectedItemForm(this,'{{obj.node.id}}-{{kam_slug}}')">
{% for typ in dostupne_typy %}
<option value="{{typ.0}}">{{typ.1}}</option>
{% endfor %}
</select>
<div class="hidden-tn" id="pridat-castNode-{{obj.node.id}}-{{kam_slug}}">
Nadpis: <input name="pridat-cast-{{obj.node.id}}-{{kam_slug}}" type="text">
<button action="submit" formaction="{%url 'treenode_pridat' obj.node.id kam_slug%}">Přidat</button>
</div>
<div class="hidden-tn" id="pridat-textNode-{{obj.node.id}}-{{kam_slug}}"> Vytvořit</div>
<div class="hidden-tn" id="pridat-reseniNode-{{obj.node.id}}-{{kam_slug}}">Vytvořit, Tady bude autocomplete na reseniNode</div>
<div class="hidden-tn" id="pridat-ulohaZadaniNode-{{obj.node.id}}-{{kam_slug}}">Vytvořit zadání</div>
<div class="hidden-tn" id="pridat-ulohaVzorakNode-{{obj.node.id}}-{{kam_slug}}">Vytvořit vzorák k: Tady bude autocomplete na problémy k aktuálnímu kontextu</div>
</div>
{% endif %}{# appendablebleChildren #}

38
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):

2
seminar/urls.py

@ -26,7 +26,7 @@ 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>/<str:kam>/', views.TreeNodePridatView.as_view(), name='treenode_pridat'),
path('treenode/editor/pridat/<str:co>/<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/odvesitpryc/<int:pk>/', views.TreeNodeOdvesitPrycView.as_view(), name='treenode_odvesitpryc'),
path('treenode/editor/podvesit/<int:pk>/<str:kam>/', views.TreeNodePodvesitView.as_view(), name='treenode_podvesit'),

38
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

Loading…
Cancel
Save