mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
TODO : offrir des cours d'anglais au cr@ns.
This commit is contained in:
parent
ed91cdcfe5
commit
0b86dc1ec4
5 changed files with 118 additions and 108 deletions
|
@ -121,7 +121,7 @@ in their own Payment models.
|
||||||
|
|
||||||
To have a closer look on how the payments works, please go to the wiki.
|
To have a closer look on how the payments works, please go to the wiki.
|
||||||
|
|
||||||
## MR xxx: Add role models
|
## MR 182: Add role models
|
||||||
|
|
||||||
Adds the Role model.
|
Adds the Role model.
|
||||||
You need to ensure that your database character set is utf-8.
|
You need to ensure that your database character set is utf-8.
|
||||||
|
|
|
@ -37,6 +37,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.forms import ModelForm, Form
|
from django.forms import ModelForm, Form
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.utils.translation import ugettext_lazy as _l
|
||||||
|
|
||||||
from re2o.field_permissions import FieldPermissionFormMixin
|
from re2o.field_permissions import FieldPermissionFormMixin
|
||||||
from re2o.mixins import FormRevMixin
|
from re2o.mixins import FormRevMixin
|
||||||
|
@ -499,7 +500,7 @@ class DelNasForm(FormRevMixin, Form):
|
||||||
|
|
||||||
|
|
||||||
class RoleForm(FormRevMixin, ModelForm):
|
class RoleForm(FormRevMixin, ModelForm):
|
||||||
"""Ajout et edition d'un role"""
|
"""Add and edit role."""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Role
|
model = Role
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
@ -514,10 +515,10 @@ class RoleForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
|
|
||||||
class DelRoleForm(FormRevMixin, Form):
|
class DelRoleForm(FormRevMixin, Form):
|
||||||
"""Suppression d'un ou plusieurs service"""
|
"""Deletion of one or several roles."""
|
||||||
role = forms.ModelMultipleChoiceField(
|
role = forms.ModelMultipleChoiceField(
|
||||||
queryset=Role.objects.none(),
|
queryset=Role.objects.none(),
|
||||||
label="Roles actuels",
|
label=_l("Current roles"),
|
||||||
widget=forms.CheckboxSelectMultiple
|
widget=forms.CheckboxSelectMultiple
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -527,9 +528,7 @@ class DelRoleForm(FormRevMixin, Form):
|
||||||
if instances:
|
if instances:
|
||||||
self.fields['role'].queryset = instances
|
self.fields['role'].queryset = instances
|
||||||
else:
|
else:
|
||||||
self.fields['role'].queryset = role.objects.all()
|
self.fields['role'].queryset = Role.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceForm(FormRevMixin, ModelForm):
|
class ServiceForm(FormRevMixin, ModelForm):
|
||||||
|
|
|
@ -42,6 +42,7 @@ from django.forms import ValidationError
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.core.validators import MaxValueValidator
|
from django.core.validators import MaxValueValidator
|
||||||
|
from django.utils.translation import ugettext_lazy as _l
|
||||||
|
|
||||||
from macaddress.fields import MACAddressField
|
from macaddress.fields import MACAddressField
|
||||||
|
|
||||||
|
@ -158,7 +159,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
||||||
user_request,
|
user_request,
|
||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
)[0]):
|
)[0]):
|
||||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||||
"d'un autre user que vous sans droit")
|
"d'un autre user que vous sans droit")
|
||||||
return True, None
|
return True, None
|
||||||
|
@ -176,7 +177,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
||||||
user_request,
|
user_request,
|
||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
)[0]):
|
)[0]):
|
||||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||||
"d'un autre user que vous sans droit")
|
"d'un autre user que vous sans droit")
|
||||||
return True, None
|
return True, None
|
||||||
|
@ -338,10 +339,10 @@ class IpType(RevMixin, AclMixin, models.Model):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
for ipv6 in Ipv6List.objects.filter(
|
for ipv6 in Ipv6List.objects.filter(
|
||||||
interface__in=Interface.objects.filter(
|
interface__in=Interface.objects.filter(
|
||||||
type__in=MachineType.objects.filter(ip_type=self)
|
type__in=MachineType.objects.filter(ip_type=self)
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
ipv6.check_and_replace_prefix(prefix=self.prefix_v6)
|
ipv6.check_and_replace_prefix(prefix=self.prefix_v6)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
@ -713,7 +714,7 @@ class Srv(RevMixin, AclMixin, models.Model):
|
||||||
choices=(
|
choices=(
|
||||||
(TCP, 'TCP'),
|
(TCP, 'TCP'),
|
||||||
(UDP, 'UDP'),
|
(UDP, 'UDP'),
|
||||||
),
|
),
|
||||||
default=TCP,
|
default=TCP,
|
||||||
)
|
)
|
||||||
extension = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
extension = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||||
|
@ -1047,7 +1048,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
user_request,
|
user_request,
|
||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
)[0]):
|
)[0]):
|
||||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||||
"d'un autre user que vous sans droit")
|
"d'un autre user que vous sans droit")
|
||||||
return True, None
|
return True, None
|
||||||
|
@ -1064,7 +1065,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
user_request,
|
user_request,
|
||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
)[0]):
|
)[0]):
|
||||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||||
"d'un autre user que vous sans droit")
|
"d'un autre user que vous sans droit")
|
||||||
return True, None
|
return True, None
|
||||||
|
@ -1165,7 +1166,7 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
user_request,
|
user_request,
|
||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
)[0]):
|
)[0]):
|
||||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||||
"d'un autre user que vous sans droit")
|
"d'un autre user que vous sans droit")
|
||||||
return True, None
|
return True, None
|
||||||
|
@ -1182,7 +1183,7 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
user_request,
|
user_request,
|
||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
)[0]):
|
)[0]):
|
||||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||||
"d'un autre user que vous sans droit")
|
"d'un autre user que vous sans droit")
|
||||||
return True, None
|
return True, None
|
||||||
|
@ -1358,11 +1359,11 @@ class Domain(RevMixin, AclMixin, models.Model):
|
||||||
return False, (u"Vous ne pouvez pas ajouter un alias à une "
|
return False, (u"Vous ne pouvez pas ajouter un alias à une "
|
||||||
"machine d'un autre user que vous sans droit")
|
"machine d'un autre user que vous sans droit")
|
||||||
if Domain.objects.filter(
|
if Domain.objects.filter(
|
||||||
cname__in=Domain.objects.filter(
|
cname__in=Domain.objects.filter(
|
||||||
interface_parent__in=(interface.machine.user
|
interface_parent__in=(interface.machine.user
|
||||||
.user_interfaces())
|
.user_interfaces())
|
||||||
)
|
)
|
||||||
).count() >= max_lambdauser_aliases:
|
).count() >= max_lambdauser_aliases:
|
||||||
return False, (u"Vous avez atteint le maximum d'alias "
|
return False, (u"Vous avez atteint le maximum d'alias "
|
||||||
"autorisés que vous pouvez créer vous même "
|
"autorisés que vous pouvez créer vous même "
|
||||||
"(%s) " % max_lambdauser_aliases)
|
"(%s) " % max_lambdauser_aliases)
|
||||||
|
@ -1441,27 +1442,25 @@ class IpList(RevMixin, AclMixin, models.Model):
|
||||||
return self.ipv4
|
return self.ipv4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Role(RevMixin, AclMixin, models.Model):
|
class Role(RevMixin, AclMixin, models.Model):
|
||||||
""" Definition d'un role (routeur principal, routeur de backkup)"""
|
"""Define the role of a machine.
|
||||||
""" Sert à la génération automatique de la conf des serveurs"""
|
Allow automated generation of the server configuration.
|
||||||
PRETTY_NAME = "Roles des serveurs"
|
"""
|
||||||
|
|
||||||
ROLE = (
|
ROLE = (
|
||||||
('dhcp-server', 'dhcp-server'),
|
('dhcp-server', _l('DHCP server')),
|
||||||
('switch-conf-server', 'switch-conf-server'),
|
('switch-conf-server', _l('Switches configuration server')),
|
||||||
('dns-recursif-server', 'dns-recursif-server'),
|
('dns-recursif-server', _l('Recursive DNS server')),
|
||||||
('ntp-server', 'ntp-server'),
|
('ntp-server', _l('NTP server')),
|
||||||
('radius-server', 'radius-server'),
|
('radius-server', _l('Radius server')),
|
||||||
('ntp-server', 'ntp-server'),
|
('log-server', _l('Log server')),
|
||||||
('log-server', 'log-server'),
|
('ldap-master-server', _l('LDAP master server')),
|
||||||
('ldap-master-server', 'ldap-master-server'),
|
('ldap-backup-server', _l('LDAP backup server')),
|
||||||
('ldap-backup-server', 'ldap-backup-server'),
|
('smtp-server', _l('SMTP server')),
|
||||||
('smtp-server', 'smtp-server'),
|
('postgresql-server', _l('postgreSQL server')),
|
||||||
('postgresql-server', 'postgresql-server'),
|
('mysql-server', _l('mySQL server')),
|
||||||
('mysql-server', 'mysql-server'),
|
('sql-client', _l('SQL client')),
|
||||||
('sql-client', 'sql-client'),
|
('gateway', _l('Gatewaw')),
|
||||||
('gateway', 'gateway'),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
role_type = models.CharField(max_length=255, unique=True)
|
role_type = models.CharField(max_length=255, unique=True)
|
||||||
|
@ -1475,21 +1474,28 @@ class Role(RevMixin, AclMixin, models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_role", "Peut voir un objet service"),
|
("view_role", _l("Can view a role.")),
|
||||||
)
|
)
|
||||||
|
verbose_name = _l("Server role")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, machineid, *_args, **_kwargs):
|
def get_instance(cls, roleid, *_args, **_kwargs):
|
||||||
"""Get the Machine instance with machineid.
|
"""Get the Role instance with roleid.
|
||||||
:param userid: The id
|
|
||||||
:return: The user
|
Args:
|
||||||
|
roleid: The id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The role.
|
||||||
"""
|
"""
|
||||||
return cls.objects.get(pk=machineid)
|
return cls.objects.get(pk=roleid)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def interface_for_roletype(cls, roletype):
|
def interface_for_roletype(cls, roletype):
|
||||||
"""Return interfaces for a roletype"""
|
"""Return interfaces for a roletype"""
|
||||||
return Interface.objects.filter(role=cls.objects.filter(specific_role=roletype))
|
return Interface.objects.filter(
|
||||||
|
role=cls.objects.filter(specific_role=roletype)
|
||||||
|
)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Role, self).save(*args, **kwargs)
|
super(Role, self).save(*args, **kwargs)
|
||||||
|
@ -1497,6 +1503,7 @@ class Role(RevMixin, AclMixin, models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.role_type)
|
return str(self.role_type)
|
||||||
|
|
||||||
|
|
||||||
class Service(RevMixin, AclMixin, models.Model):
|
class Service(RevMixin, AclMixin, models.Model):
|
||||||
""" Definition d'un service (dhcp, dns, etc)"""
|
""" Definition d'un service (dhcp, dns, etc)"""
|
||||||
PRETTY_NAME = "Services à générer (dhcp, dns, etc)"
|
PRETTY_NAME = "Services à générer (dhcp, dns, etc)"
|
||||||
|
@ -1527,8 +1534,8 @@ class Service(RevMixin, AclMixin, models.Model):
|
||||||
""" Django ne peut créer lui meme les relations manytomany avec table
|
""" Django ne peut créer lui meme les relations manytomany avec table
|
||||||
intermediaire explicite"""
|
intermediaire explicite"""
|
||||||
for serv in servers.exclude(
|
for serv in servers.exclude(
|
||||||
pk__in=Interface.objects.filter(service=self)
|
pk__in=Interface.objects.filter(service=self)
|
||||||
):
|
):
|
||||||
link = Service_link(service=self, server=serv)
|
link = Service_link(service=self, server=serv)
|
||||||
link.save()
|
link.save()
|
||||||
Service_link.objects.filter(service=self).exclude(server__in=servers)\
|
Service_link.objects.filter(service=self).exclude(server__in=servers)\
|
||||||
|
@ -1686,7 +1693,7 @@ class OuverturePort(RevMixin, AclMixin, models.Model):
|
||||||
choices=(
|
choices=(
|
||||||
(TCP, 'TCP'),
|
(TCP, 'TCP'),
|
||||||
(UDP, 'UDP'),
|
(UDP, 'UDP'),
|
||||||
),
|
),
|
||||||
default=TCP,
|
default=TCP,
|
||||||
)
|
)
|
||||||
io = models.CharField(
|
io = models.CharField(
|
||||||
|
@ -1694,7 +1701,7 @@ class OuverturePort(RevMixin, AclMixin, models.Model):
|
||||||
choices=(
|
choices=(
|
||||||
(IN, 'IN'),
|
(IN, 'IN'),
|
||||||
(OUT, 'OUT'),
|
(OUT, 'OUT'),
|
||||||
),
|
),
|
||||||
default=OUT,
|
default=OUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -23,29 +23,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
|
|
||||||
{% load acl %}
|
{% load acl %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
<table class="table table-striped">
|
|
||||||
<thead>
|
<table class="table table-striped">
|
||||||
<tr>
|
<thead>
|
||||||
<th>Nom du role</th>
|
|
||||||
<th>Role spécifique</th>
|
|
||||||
<th>Serveurs inclus</th>
|
|
||||||
<th></th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
{% for role in role_list %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ role.role_type }}</td>
|
<th>{% trans "Role name" %}</th>
|
||||||
<td>{{ role.specific_role }}</td>
|
<th>{% trans "Specific role" %}</th>
|
||||||
<td>{% for serv in role.servers.all %}{{ serv }}, {% endfor %}</td>
|
<th>{% trans "Servers" %}</th>
|
||||||
<td class="text-right">
|
<th></th>
|
||||||
{% can_edit role %}
|
<th></th>
|
||||||
{% include 'buttons/edit.html' with href='machines:edit-role' id=role.id %}
|
|
||||||
{% acl_end %}
|
|
||||||
{% include 'buttons/history.html' with href='machines:history' name='role' id=role.id %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
</thead>
|
||||||
</table>
|
{% for role in role_list %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ role.role_type }}</td>
|
||||||
|
<td>{{ role.specific_role }}</td>
|
||||||
|
<td>{% for serv in role.servers.all %}{{ serv }}, {% endfor %}</td>
|
||||||
|
<td class="text-right">
|
||||||
|
{% can_edit role %}
|
||||||
|
{% include 'buttons/edit.html' with href='machines:edit-role' id=role.id %}
|
||||||
|
{% acl_end %}
|
||||||
|
{% include 'buttons/history.html' with href='machines:history' name='role' id=role.id %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.db.models import ProtectedError, F
|
from django.db.models import ProtectedError, F
|
||||||
from django.forms import modelformset_factory
|
from django.forms import modelformset_factory
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from rest_framework.renderers import JSONRenderer
|
from rest_framework.renderers import JSONRenderer
|
||||||
|
|
||||||
|
@ -181,14 +182,14 @@ def generate_ipv4_engine(is_type_tt):
|
||||||
"""
|
"""
|
||||||
return (
|
return (
|
||||||
'new Bloodhound( {{'
|
'new Bloodhound( {{'
|
||||||
'datumTokenizer: Bloodhound.tokenizers.obj.whitespace( "value" ),'
|
'datumTokenizer: Bloodhound.tokenizers.obj.whitespace( "value" ),'
|
||||||
'queryTokenizer: Bloodhound.tokenizers.whitespace,'
|
'queryTokenizer: Bloodhound.tokenizers.whitespace,'
|
||||||
'local: choices_ipv4[ $( "#{type_id}" ).val() ],'
|
'local: choices_ipv4[ $( "#{type_id}" ).val() ],'
|
||||||
'identify: function( obj ) {{ return obj.key; }}'
|
'identify: function( obj ) {{ return obj.key; }}'
|
||||||
'}} )'
|
'}} )'
|
||||||
).format(
|
).format(
|
||||||
type_id=f_type_id(is_type_tt)
|
type_id=f_type_id(is_type_tt)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def generate_ipv4_match_func(is_type_tt):
|
def generate_ipv4_match_func(is_type_tt):
|
||||||
|
@ -196,17 +197,17 @@ def generate_ipv4_match_func(is_type_tt):
|
||||||
"""
|
"""
|
||||||
return (
|
return (
|
||||||
'function(q, sync) {{'
|
'function(q, sync) {{'
|
||||||
'if (q === "") {{'
|
'if (q === "") {{'
|
||||||
'var first = choices_ipv4[$("#{type_id}").val()].slice(0, 5);'
|
'var first = choices_ipv4[$("#{type_id}").val()].slice(0, 5);'
|
||||||
'first = first.map( function (obj) {{ return obj.key; }} );'
|
'first = first.map( function (obj) {{ return obj.key; }} );'
|
||||||
'sync(engine_ipv4.get(first));'
|
'sync(engine_ipv4.get(first));'
|
||||||
'}} else {{'
|
'}} else {{'
|
||||||
'engine_ipv4.search(q, sync);'
|
'engine_ipv4.search(q, sync);'
|
||||||
'}}'
|
|
||||||
'}}'
|
'}}'
|
||||||
).format(
|
'}}'
|
||||||
type_id=f_type_id(is_type_tt)
|
).format(
|
||||||
)
|
type_id=f_type_id(is_type_tt)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def generate_ipv4_mbf_param(form_obj, is_type_tt):
|
def generate_ipv4_mbf_param(form_obj, is_type_tt):
|
||||||
|
@ -1168,10 +1169,10 @@ def edit_role(request, role_instance, **_kwargs):
|
||||||
if role.is_valid():
|
if role.is_valid():
|
||||||
if role.changed_data:
|
if role.changed_data:
|
||||||
role.save()
|
role.save()
|
||||||
messages.success(request, "Role modifié")
|
messages.success(request, _("Role updated"))
|
||||||
return redirect(reverse('machines:index-role'))
|
return redirect(reverse('machines:index-role'))
|
||||||
return form(
|
return form(
|
||||||
{'roleform': role, 'action_name': 'Editer'},
|
{'roleform': role, 'action_name': _('Edit')},
|
||||||
'machines/machine.html',
|
'machines/machine.html',
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
@ -1187,22 +1188,22 @@ def del_role(request, instances):
|
||||||
for role_del in role_dels:
|
for role_del in role_dels:
|
||||||
try:
|
try:
|
||||||
role_del.delete()
|
role_del.delete()
|
||||||
messages.success(request, "Le role a été supprimée")
|
messages.success(request, _("The role has been deleted."))
|
||||||
except ProtectedError:
|
except ProtectedError:
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
("Erreur le role suivant %s ne peut être supprimé"
|
(_("Error: The following role cannot be deleted: %(role)")
|
||||||
% role_del)
|
% {'role': role_del}
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return redirect(reverse('machines:index-role'))
|
return redirect(reverse('machines:index-role'))
|
||||||
return form(
|
return form(
|
||||||
{'roleform': role, 'action_name': 'Supprimer'},
|
{'roleform': role, 'action_name': _('Delete')},
|
||||||
'machines/machine.html',
|
'machines/machine.html',
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(Service)
|
@can_create(Service)
|
||||||
def add_service(request):
|
def add_service(request):
|
||||||
|
@ -1548,9 +1549,9 @@ def index_ipv6(request, interface, interfaceid):
|
||||||
def index_role(request):
|
def index_role(request):
|
||||||
""" View used to display the list of existing roles """
|
""" View used to display the list of existing roles """
|
||||||
role_list = (Role.objects
|
role_list = (Role.objects
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
'servers__domain__extension'
|
'servers__domain__extension'
|
||||||
).all())
|
).all())
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'machines/index_role.html',
|
'machines/index_role.html',
|
||||||
|
@ -1647,12 +1648,12 @@ def add_portlist(request):
|
||||||
""" View used to add a port policy """
|
""" View used to add a port policy """
|
||||||
port_list = EditOuverturePortListForm(request.POST or None)
|
port_list = EditOuverturePortListForm(request.POST or None)
|
||||||
port_formset = modelformset_factory(
|
port_formset = modelformset_factory(
|
||||||
OuverturePort,
|
OuverturePort,
|
||||||
fields=('begin', 'end', 'protocole', 'io'),
|
fields=('begin', 'end', 'protocole', 'io'),
|
||||||
extra=0,
|
extra=0,
|
||||||
can_delete=True,
|
can_delete=True,
|
||||||
min_num=1,
|
min_num=1,
|
||||||
validate_min=True,
|
validate_min=True,
|
||||||
)(request.POST or None, queryset=OuverturePort.objects.none())
|
)(request.POST or None, queryset=OuverturePort.objects.none())
|
||||||
if port_list.is_valid() and port_formset.is_valid():
|
if port_list.is_valid() and port_formset.is_valid():
|
||||||
pl = port_list.save()
|
pl = port_list.save()
|
||||||
|
@ -1699,11 +1700,12 @@ def configure_ports(request, interface_instance, **_kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
## Framework Rest
|
# Framework Rest
|
||||||
|
|
||||||
|
|
||||||
class JSONResponse(HttpResponse):
|
class JSONResponse(HttpResponse):
|
||||||
""" Class to build a JSON response. Used for API """
|
""" Class to build a JSON response. Used for API """
|
||||||
|
|
||||||
def __init__(self, data, **kwargs):
|
def __init__(self, data, **kwargs):
|
||||||
content = JSONRenderer().render(data)
|
content = JSONRenderer().render(data)
|
||||||
kwargs['content_type'] = 'application/json'
|
kwargs['content_type'] = 'application/json'
|
||||||
|
|
Loading…
Reference in a new issue