|
|
@ -18,12 +18,30 @@ class PermissionMixin(object): |
|
|
|
# návštěvník nemusí být zalogován, aby si prohlížel obsah |
|
|
|
return [permission() for permission in permission_classes] |
|
|
|
|
|
|
|
def has_object_permission(self, request, view, obj): |
|
|
|
if obj.verejne: |
|
|
|
return True |
|
|
|
else: |
|
|
|
return False |
|
|
|
def verejne_nad(self, node): |
|
|
|
""" Returns output of verejne for closest Rocnik, Cislo or Problem above. |
|
|
|
(All of them have method verejne.)""" |
|
|
|
parent = get_parent(node) |
|
|
|
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): |
|
|
|
""" |
|
|
|