viewsets | Přidané permissions podle veřejnosti (NEOTESTOVANO!), poznámka k nastavení téhož u TNLData
This commit is contained in:
parent
0f9e1cf5ba
commit
1ca024835c
2 changed files with 24 additions and 5 deletions
|
@ -127,6 +127,7 @@ class TNLData(object):
|
||||||
def from_treenode(cls,anode,parent=None,index=None):
|
def from_treenode(cls,anode,parent=None,index=None):
|
||||||
out = cls(anode,parent,index)
|
out = cls(anode,parent,index)
|
||||||
for (idx,ch) in enumerate(treelib.all_children(anode)):
|
for (idx,ch) in enumerate(treelib.all_children(anode)):
|
||||||
|
# FIXME přidat filtrování na veřejnost
|
||||||
outitem = cls.from_treenode(ch,out,idx)
|
outitem = cls.from_treenode(ch,out,idx)
|
||||||
out.children.append(outitem)
|
out.children.append(outitem)
|
||||||
out.add_edit_options()
|
out.add_edit_options()
|
||||||
|
|
|
@ -18,12 +18,30 @@ class PermissionMixin(object):
|
||||||
# návštěvník nemusí být zalogován, aby si prohlížel obsah
|
# návštěvník nemusí být zalogován, aby si prohlížel obsah
|
||||||
return [permission() for permission in permission_classes]
|
return [permission() for permission in permission_classes]
|
||||||
|
|
||||||
def has_object_permission(self, request, view, obj):
|
def verejne_nad(self, node):
|
||||||
if obj.verejne:
|
""" Returns output of verejne for closest Rocnik, Cislo or Problem above.
|
||||||
return True
|
(All of them have method verejne.)"""
|
||||||
else:
|
parent = get_parent(node)
|
||||||
return False
|
while True:
|
||||||
|
rocnik = isinstance(parent, RocnikNode)
|
||||||
|
cislo = isinstance(parent, CisloNode)
|
||||||
|
problem = isinstance(parent, ProblemNode)
|
||||||
|
|
||||||
|
if (rocnik or cislo or problem):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
parent = get_parent(parent)
|
||||||
|
if rocnik:
|
||||||
|
return parent.rocnik.verejne()
|
||||||
|
elif cislo:
|
||||||
|
return parent.cislo.verejne()
|
||||||
|
elif problem:
|
||||||
|
return parent.problem.verjne()
|
||||||
|
|
||||||
|
def has_object_permission(self, request, view, obj):
|
||||||
|
# test that obj is Node
|
||||||
|
assert isinstance(obj, Node)
|
||||||
|
return verejne_nad(node)
|
||||||
|
|
||||||
class ReadWriteSerializerMixin(object):
|
class ReadWriteSerializerMixin(object):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue