mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 00:13:45 +00:00
Ajout du tag can_view_any_app et autorise de mettre plusieurs apps dans can_view_app
This commit is contained in:
parent
be430c4651
commit
6b8b576452
1 changed files with 16 additions and 9 deletions
|
@ -180,13 +180,17 @@ def get_callback(tag_name, obj=None):
|
||||||
if tag_name == 'cannot_view_all':
|
if tag_name == 'cannot_view_all':
|
||||||
return acl_fct(obj.can_view_all, True)
|
return acl_fct(obj.can_view_all, True)
|
||||||
if tag_name == 'can_view_app':
|
if tag_name == 'can_view_app':
|
||||||
return acl_fct(sys.modules[obj].can_view, False)
|
return acl_fct(lambda x : (not any(not sys.modules[o].can_view(x) for o in obj), None), False)
|
||||||
if tag_name == 'cannot_view_app':
|
if tag_name == 'cannot_view_app':
|
||||||
return acl_fct(sys.modules[obj].can_view, True)
|
return acl_fct(lambda x : (not any(not sys.modules[o].can_view(x) for o in obj), None), True)
|
||||||
if tag_name == 'can_edit_history':
|
if tag_name == 'can_edit_history':
|
||||||
return acl_fct(lambda user:(user.has_perm('admin.change_logentry'),None),False)
|
return acl_fct(lambda user:(user.has_perm('admin.change_logentry'),None),False)
|
||||||
if tag_name == 'cannot_edit_history':
|
if tag_name == 'cannot_edit_history':
|
||||||
return acl_fct(lambda user:(user.has_perm('admin.change_logentry'),None),True)
|
return acl_fct(lambda user:(user.has_perm('admin.change_logentry'),None),True)
|
||||||
|
if tag_name == 'can_view_any_app':
|
||||||
|
return acl_fct(lambda x : (any(sys.modules[o].can_view(x) for o in obj), None), False)
|
||||||
|
if tag_name == 'cannot_view_any_app':
|
||||||
|
return acl_fct(lambda x : (any(sys.modules[o].can_view(x) for o in obj), None), True)
|
||||||
|
|
||||||
raise template.TemplateSyntaxError(
|
raise template.TemplateSyntaxError(
|
||||||
"%r tag is not a valid can_xxx tag" % tag_name
|
"%r tag is not a valid can_xxx tag" % tag_name
|
||||||
|
@ -228,22 +232,25 @@ def acl_history_filter(parser, token):
|
||||||
return AclNode(callback, oknodes, konodes)
|
return AclNode(callback, oknodes, konodes)
|
||||||
|
|
||||||
|
|
||||||
|
@register.tag('can_view_any_app')
|
||||||
|
@register.tag('cannot_view_any_app')
|
||||||
@register.tag('can_view_app')
|
@register.tag('can_view_app')
|
||||||
@register.tag('cannot_view_app')
|
@register.tag('cannot_view_app')
|
||||||
def acl_app_filter(parser, token):
|
def acl_app_filter(parser, token):
|
||||||
"""Templatetag for acl checking on applications."""
|
"""Templatetag for acl checking on applications."""
|
||||||
try:
|
try:
|
||||||
tag_name, app_name = token.split_contents()
|
tag_name, *app_name = token.split_contents()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise template.TemplateSyntaxError(
|
raise template.TemplateSyntaxError(
|
||||||
"%r tag require 1 argument : the application"
|
"%r tag require 1 argument : an application"
|
||||||
% token.contents.split()[0]
|
% token.contents.split()[0]
|
||||||
)
|
)
|
||||||
if not app_name in sys.modules.keys():
|
for name in app_name:
|
||||||
raise template.TemplateSyntaxError(
|
if not name in sys.modules.keys():
|
||||||
"%r is not a registered application for acl."
|
raise template.TemplateSyntaxError(
|
||||||
% app_name
|
"%r is not a registered application for acl."
|
||||||
)
|
% name
|
||||||
|
)
|
||||||
|
|
||||||
callback = get_callback(tag_name, app_name)
|
callback = get_callback(tag_name, app_name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue