mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 16:42:25 +00:00
Add templatetags for all can_xxx
This commit is contained in:
parent
68fdea2618
commit
b066f66316
1 changed files with 47 additions and 7 deletions
|
@ -76,19 +76,13 @@ from django.template.base import Node, NodeList
|
||||||
|
|
||||||
import cotisations.models as cotisations
|
import cotisations.models as cotisations
|
||||||
import machines.models as machines
|
import machines.models as machines
|
||||||
|
import preferences.models as preferences
|
||||||
import topologie.models as topologie
|
import topologie.models as topologie
|
||||||
import users.models as users
|
import users.models as users
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
MODEL_NAME = {
|
MODEL_NAME = {
|
||||||
# topologie
|
|
||||||
'Stack' : topologie.Stack,
|
|
||||||
'Switch' : topologie.Switch,
|
|
||||||
'ModelSwitch' : topologie.ModelSwitch,
|
|
||||||
'ConstructorSwitch' : topologie.ConstructorSwitch,
|
|
||||||
'Port' : topologie.Port,
|
|
||||||
'Room' : topologie.Room,
|
|
||||||
# cotisations
|
# cotisations
|
||||||
'Facture' : cotisations.Facture,
|
'Facture' : cotisations.Facture,
|
||||||
'Vente' : cotisations.Vente,
|
'Vente' : cotisations.Vente,
|
||||||
|
@ -115,6 +109,21 @@ MODEL_NAME = {
|
||||||
'Service_link' : machines.Service_link,
|
'Service_link' : machines.Service_link,
|
||||||
'OuverturePortList' : machines.OuverturePortList,
|
'OuverturePortList' : machines.OuverturePortList,
|
||||||
'OuverturePort' : machines.OuverturePort,
|
'OuverturePort' : machines.OuverturePort,
|
||||||
|
# preferences
|
||||||
|
'OptionalUser': preferences.OptionalUser
|
||||||
|
'OptionalMachine': preferences.OptionalMachine
|
||||||
|
'OptionalTopologie': preferences.OptionalTopologie
|
||||||
|
'GeneralOption': preferences.GeneralOption
|
||||||
|
'Service': preferences.Service
|
||||||
|
'AssoOption': preferences.AssoOption
|
||||||
|
'MailMessageOption': preferences.MailMessageOption
|
||||||
|
# topologie
|
||||||
|
'Stack' : topologie.Stack,
|
||||||
|
'Switch' : topologie.Switch,
|
||||||
|
'ModelSwitch' : topologie.ModelSwitch,
|
||||||
|
'ConstructorSwitch' : topologie.ConstructorSwitch,
|
||||||
|
'Port' : topologie.Port,
|
||||||
|
'Room' : topologie.Room,
|
||||||
# users
|
# users
|
||||||
'User' : users.User,
|
'User' : users.User,
|
||||||
'Club' : users.Club,
|
'Club' : users.Club,
|
||||||
|
@ -126,6 +135,7 @@ MODEL_NAME = {
|
||||||
'Whitelist' : users.Whitelist,
|
'Whitelist' : users.Whitelist,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_model(model_name):
|
def get_model(model_name):
|
||||||
"""Retrieve the model object from its name"""
|
"""Retrieve the model object from its name"""
|
||||||
try:
|
try:
|
||||||
|
@ -147,6 +157,26 @@ def get_callback(tag_name, obj):
|
||||||
return acl_fct(obj.can_edit, False)
|
return acl_fct(obj.can_edit, False)
|
||||||
if tag_name == 'cannot_edit':
|
if tag_name == 'cannot_edit':
|
||||||
return acl_fct(obj.can_edit, True)
|
return acl_fct(obj.can_edit, True)
|
||||||
|
if tag_name == 'can_edit_all':
|
||||||
|
return acl_fct(obj.can_edit_all, False)
|
||||||
|
if tag_name == 'cannot_edit_all':
|
||||||
|
return acl_fct(obj.can_edit_all, True)
|
||||||
|
if tag_name == 'can_delete':
|
||||||
|
return acl_fct(obj.can_delete, False)
|
||||||
|
if tag_name == 'cannot_delete':
|
||||||
|
return acl_fct(obj.can_delete, True)
|
||||||
|
if tag_name == 'can_delete_all':
|
||||||
|
return acl_fct(obj.can_delete_all, False)
|
||||||
|
if tag_name == 'cannot_delete_all':
|
||||||
|
return acl_fct(obj.can_delete_all, True)
|
||||||
|
if tag_name == 'can_view':
|
||||||
|
return acl_fct(obj.can_view, False)
|
||||||
|
if tag_name == 'cannot_view':
|
||||||
|
return acl_fct(obj.can_view, True)
|
||||||
|
if tag_name == 'can_view_all':
|
||||||
|
return acl_fct(obj.can_view_all, False)
|
||||||
|
if tag_name == 'cannot_view_all':
|
||||||
|
return acl_fct(obj.can_view_all, 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
|
||||||
)
|
)
|
||||||
|
@ -169,6 +199,12 @@ def acl_fct(callback, reverse):
|
||||||
|
|
||||||
@register.tag('can_create')
|
@register.tag('can_create')
|
||||||
@register.tag('cannot_create')
|
@register.tag('cannot_create')
|
||||||
|
@register.tag('can_edit_all')
|
||||||
|
@register.tag('cannot_edit_all')
|
||||||
|
@register.tag('can_delete_all')
|
||||||
|
@register.tag('cannot_delete_all')
|
||||||
|
@register.tag('can_view_all')
|
||||||
|
@register.tag('cannot_view_all')
|
||||||
def acl_model_filter(parser, token):
|
def acl_model_filter(parser, token):
|
||||||
"""Generic definition of an acl templatetag for acl based on model"""
|
"""Generic definition of an acl templatetag for acl based on model"""
|
||||||
|
|
||||||
|
@ -205,6 +241,10 @@ def acl_model_filter(parser, token):
|
||||||
|
|
||||||
@register.tag('can_edit')
|
@register.tag('can_edit')
|
||||||
@register.tag('cannot_edit')
|
@register.tag('cannot_edit')
|
||||||
|
@register.tag('can_delete')
|
||||||
|
@register.tag('cannot_delete')
|
||||||
|
@register.tag('can_view')
|
||||||
|
@register.tag('cannot_view')
|
||||||
def acl_instance_filter(parser, token):
|
def acl_instance_filter(parser, token):
|
||||||
"""Generic definition of an acl templatetag for acl based on instance"""
|
"""Generic definition of an acl templatetag for acl based on instance"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue