seminar | treenode editor | pridany dalsi funkce
This commit is contained in:
parent
ae929c8a98
commit
336ef69054
5 changed files with 43 additions and 26 deletions
|
@ -826,9 +826,7 @@ class Text(SeminarModelBase):
|
|||
tn.save()
|
||||
|
||||
def __str__(self):
|
||||
parser = FirstTagParser()
|
||||
parser.feed(str(self.na_web))
|
||||
return parser.firstTag
|
||||
return str(self.na_web)[:20]
|
||||
|
||||
class Uloha(Problem):
|
||||
class Meta:
|
||||
|
|
|
@ -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' obj.node.id 'predchozi'%}">Podvěsit pod předchozí</button> - nejsou testovací data
|
||||
<button type="submit" formaction="{%url 'treenode_podvesit' obj.node.id 'pred'%}">Podvěsit pod předchozí</button> - nejsou testovací data
|
||||
{% endif %}
|
||||
{% if obj|canPodvesitZa %}
|
||||
<button type="submit" formaction="{%url 'treenode_podvesit' obj.node.id 'nasledujíci'%}">Podvěsit pod následující</button> - nejsou testovací data
|
||||
<button type="submit" formaction="{%url 'treenode_podvesit' obj.node.id 'za'%}">Podvěsit pod následující</button> - nejsou testovací data
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ def appendableChildren(value):
|
|||
return (NodeTypes.CAST.value,
|
||||
NodeTypes.TEXT.value,
|
||||
)
|
||||
if isCast(value):
|
||||
if isCast(value.node):
|
||||
return appendableChildren(value.parent)
|
||||
return None
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db import transaction
|
||||
# NOTE: node.prev a node.succ jsou implementovány přímo v models.TreeNode
|
||||
# TODO: Všechny tyto funkce se naivně spoléhají na to, že jako parametr dostanou nějaký TreeNode (některé možná zvládnou i None)
|
||||
# TODO: Chceme, aby všechno nějak zvládlo None jako parametr.
|
||||
|
@ -239,6 +240,7 @@ def swap(node, other):
|
|||
class TreeLibError(RuntimeError):
|
||||
pass
|
||||
|
||||
@transaction.atomic
|
||||
def swap_pred(node):
|
||||
if node is None:
|
||||
raise TreeLibError("Nelze přesunout None. Tohle by se nemělo stát.")
|
||||
|
@ -248,14 +250,19 @@ def swap_pred(node):
|
|||
pre_pred = safe_pred(pred)
|
||||
succ = node.succ
|
||||
|
||||
#TODO zkontrolovaz, ze toto poradi nerozbiji db a neskonci s unique constraint violation
|
||||
if pre_pred is not None:
|
||||
pre_pred.succ = node
|
||||
pre_pred.succ = None
|
||||
pre_pred.save()
|
||||
node.succ = pred
|
||||
node.save()
|
||||
pred.succ = succ
|
||||
pred.save()
|
||||
if pre_pred is not None:
|
||||
pre_pred.succ = node
|
||||
pre_pred.save()
|
||||
|
||||
@transaction.atomic
|
||||
def swap_succ(node):
|
||||
if node is None:
|
||||
raise TreeLibError("Nelze přesunout None. Tohle by se nemělo stát.")
|
||||
|
@ -266,12 +273,15 @@ def swap_succ(node):
|
|||
post_succ = succ.succ
|
||||
|
||||
if pred is not None:
|
||||
pred.succ = succ
|
||||
pred.succ = None
|
||||
pred.save()
|
||||
succ.succ = node
|
||||
succ.save()
|
||||
node.succ = post_succ
|
||||
node.save()
|
||||
if pred is not None:
|
||||
pred.succ = succ
|
||||
pred.save()
|
||||
|
||||
# Rotace stromu
|
||||
# Dokumentace viz wiki:
|
||||
|
|
|
@ -159,51 +159,60 @@ class TreeNodePridatView(generic.View):
|
|||
}
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
kam = self.kwargs['kam']
|
||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||
kam = self.kwargs['kam']
|
||||
|
||||
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 typ == m.TextNode:
|
||||
text_obj = m.Text()
|
||||
text_obj.save()
|
||||
node = treelib.create_child(node,typ,text=text_obj)
|
||||
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]
|
||||
node = treelib.create_node_after(node,typ)
|
||||
if typ == m.TextNode:
|
||||
text_obj = m.Text()
|
||||
text_obj.save()
|
||||
node = treelib.create_node_after(node,typ,text=text_obj)
|
||||
else:
|
||||
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
|
||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||
if node.first_child:
|
||||
raise NotImplemented('Mazání TreeNode se syny není zatím podporováno!')
|
||||
node.delete()
|
||||
|
||||
class TreeNodeOdvesitView(generic.base.View):
|
||||
def post(self, request, *args, **kwargs):
|
||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||
pass
|
||||
pass
|
||||
|
||||
class TreeNodePodvesitView(generic.base.View):
|
||||
def post(self, request, *args, **kwargs):
|
||||
pass
|
||||
pass
|
||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||
kam = self.kwargs['kam']
|
||||
if kam == 'pred':
|
||||
lower_node(node)
|
||||
elif kam == 'za':
|
||||
raise NotImplemented('Podvěsit za není zatím podporováno')
|
||||
|
||||
class TreeNodeProhoditView(generic.base.View):
|
||||
def post(self, request, *args, **kwargs):
|
||||
pass
|
||||
pass
|
||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||
treelib.swap_succ(node)
|
||||
#FIXME ve formulari predat puvodni url a vratit redirect na ni
|
||||
|
||||
|
||||
class ProblemView(generic.DetailView):
|
||||
|
|
Loading…
Reference in a new issue