mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 06:32:26 +00:00
Merge branch 'easier_acl' into 'master'
Suppression du dictionnaire dans re2o/templatetags/acl.py See merge request federez/re2o!205
This commit is contained in:
commit
ac7c847354
1 changed files with 25 additions and 65 deletions
|
@ -74,82 +74,42 @@ import sys
|
|||
|
||||
from django import template
|
||||
from django.template.base import Node, NodeList
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
import cotisations
|
||||
import machines
|
||||
import preferences
|
||||
import topologie
|
||||
import users
|
||||
|
||||
register = template.Library()
|
||||
|
||||
MODEL_NAME = {
|
||||
# cotisations
|
||||
'Facture': cotisations.models.Facture,
|
||||
'Vente': cotisations.models.Vente,
|
||||
'Article': cotisations.models.Article,
|
||||
'Banque': cotisations.models.Banque,
|
||||
'Paiement': cotisations.models.Paiement,
|
||||
'Cotisation': cotisations.models.Cotisation,
|
||||
# machines
|
||||
'Machine': machines.models.Machine,
|
||||
'MachineType': machines.models.MachineType,
|
||||
'IpType': machines.models.IpType,
|
||||
'Vlan': machines.models.Vlan,
|
||||
'Nas': machines.models.Nas,
|
||||
'SOA': machines.models.SOA,
|
||||
'Extension': machines.models.Extension,
|
||||
'Mx': machines.models.Mx,
|
||||
'Ns': machines.models.Ns,
|
||||
'Txt': machines.models.Txt,
|
||||
'Srv': machines.models.Srv,
|
||||
'Interface': machines.models.Interface,
|
||||
'Domain': machines.models.Domain,
|
||||
'IpList': machines.models.IpList,
|
||||
'Ipv6List': machines.models.Ipv6List,
|
||||
'machines.Service': machines.models.Service,
|
||||
'Service_link': machines.models.Service_link,
|
||||
'OuverturePortList': machines.models.OuverturePortList,
|
||||
'OuverturePort': machines.models.OuverturePort,
|
||||
# preferences
|
||||
'OptionalUser': preferences.models.OptionalUser,
|
||||
'OptionalMachine': preferences.models.OptionalMachine,
|
||||
'OptionalTopologie': preferences.models.OptionalTopologie,
|
||||
'GeneralOption': preferences.models.GeneralOption,
|
||||
'preferences.Service': preferences.models.Service,
|
||||
'AssoOption': preferences.models.AssoOption,
|
||||
'MailMessageOption': preferences.models.MailMessageOption,
|
||||
# topologie
|
||||
'Stack': topologie.models.Stack,
|
||||
'Switch': topologie.models.Switch,
|
||||
'AccessPoint': topologie.models.AccessPoint,
|
||||
'ModelSwitch': topologie.models.ModelSwitch,
|
||||
'ConstructorSwitch': topologie.models.ConstructorSwitch,
|
||||
'Port': topologie.models.Port,
|
||||
'Room': topologie.models.Room,
|
||||
'Building': topologie.models.Building,
|
||||
'SwitchBay': topologie.models.SwitchBay,
|
||||
# users
|
||||
'User': users.models.User,
|
||||
'Adherent': users.models.Adherent,
|
||||
'Club': users.models.Club,
|
||||
'ServiceUser': users.models.ServiceUser,
|
||||
'School': users.models.School,
|
||||
'ListRight': users.models.ListRight,
|
||||
'ListShell': users.models.ListShell,
|
||||
'Ban': users.models.Ban,
|
||||
'Whitelist': users.models.Whitelist,
|
||||
}
|
||||
|
||||
|
||||
def get_model(model_name):
|
||||
"""Retrieve the model object from its name"""
|
||||
splitted = model_name.split('.')
|
||||
if len(splitted) > 1:
|
||||
try:
|
||||
return MODEL_NAME[model_name]
|
||||
except KeyError:
|
||||
app_label, name = splitted
|
||||
except ValueError:
|
||||
raise template.TemplateSyntaxError(
|
||||
"%r is an inconsistent model name" % model_name
|
||||
)
|
||||
else:
|
||||
app_label, name = None, splitted[0]
|
||||
try:
|
||||
if app_label is not None:
|
||||
content_type = ContentType.objects.get(
|
||||
model=name,
|
||||
app_label=app_label
|
||||
)
|
||||
else:
|
||||
content_type = ContentType.objects.get(model=name)
|
||||
except ContentType.DoesNotExist:
|
||||
raise template.TemplateSyntaxError(
|
||||
"%r is not a valid model for an acl tag" % model_name
|
||||
)
|
||||
except ContentType.MultipleObjectsReturned:
|
||||
raise template.TemplateSyntaxError(
|
||||
"More than one model found for %r. Try with `app.model`."
|
||||
% model_name
|
||||
)
|
||||
return content_type.model_class()
|
||||
|
||||
|
||||
def get_callback(tag_name, obj=None):
|
||||
|
|
Loading…
Reference in a new issue