Commit b5513db8 authored by Hugo LEVY-FALK's avatar Hugo LEVY-FALK

Suppression du dictionnaire de mort dans re2o/templatetags/acl.py

parent af35507c
...@@ -74,82 +74,42 @@ import sys ...@@ -74,82 +74,42 @@ import sys
from django import template from django import template
from django.template.base import Node, NodeList 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() 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): def get_model(model_name):
"""Retrieve the model object from its name""" """Retrieve the model object from its name"""
splitted = model_name.split('.')
if len(splitted) > 1:
try:
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: try:
return MODEL_NAME[model_name] if app_label is not None:
except KeyError: 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( raise template.TemplateSyntaxError(
"%r is not a valid model for an acl tag" % model_name "%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): def get_callback(tag_name, obj=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment