Commit 0b86dc1e authored by Levy--Falk Hugo's avatar Levy--Falk Hugo

TODO : offrir des cours d'anglais au cr@ns.

parent ed91cdcf
......@@ -121,7 +121,7 @@ in their own Payment models.
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.
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 import forms
from django.utils.translation import ugettext_lazy as _l
from re2o.field_permissions import FieldPermissionFormMixin
from re2o.mixins import FormRevMixin
......@@ -499,7 +500,7 @@ class DelNasForm(FormRevMixin, Form):
class RoleForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un role"""
"""Add and edit role."""
class Meta:
model = Role
fields = '__all__'
......@@ -514,10 +515,10 @@ class RoleForm(FormRevMixin, ModelForm):
class DelRoleForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs service"""
"""Deletion of one or several roles."""
role = forms.ModelMultipleChoiceField(
label="Roles actuels",
label=_l("Current roles"),
......@@ -527,9 +528,7 @@ class DelRoleForm(FormRevMixin, Form):
if instances:
self.fields['role'].queryset = instances
self.fields['role'].queryset = role.objects.all()
self.fields['role'].queryset = Role.objects.all()
class ServiceForm(FormRevMixin, ModelForm):
......@@ -42,6 +42,7 @@ from django.forms import ValidationError
from django.utils.functional import cached_property
from django.utils import timezone
from django.core.validators import MaxValueValidator
from django.utils.translation import ugettext_lazy as _l
from macaddress.fields import MACAddressField
......@@ -1441,27 +1442,25 @@ class IpList(RevMixin, AclMixin, models.Model):
return self.ipv4
class Role(RevMixin, AclMixin, models.Model):
""" Definition d'un role (routeur principal, routeur de backkup)"""
""" Sert à la génération automatique de la conf des serveurs"""
PRETTY_NAME = "Roles des serveurs"
"""Define the role of a machine.
Allow automated generation of the server configuration.
ROLE = (
('dhcp-server', 'dhcp-server'),
('switch-conf-server', 'switch-conf-server'),
('dns-recursif-server', 'dns-recursif-server'),
('ntp-server', 'ntp-server'),
('radius-server', 'radius-server'),
('ntp-server', 'ntp-server'),
('log-server', 'log-server'),
('ldap-master-server', 'ldap-master-server'),
('ldap-backup-server', 'ldap-backup-server'),
('smtp-server', 'smtp-server'),
('postgresql-server', 'postgresql-server'),
('mysql-server', 'mysql-server'),
('sql-client', 'sql-client'),
('gateway', 'gateway'),
('dhcp-server', _l('DHCP server')),
('switch-conf-server', _l('Switches configuration server')),
('dns-recursif-server', _l('Recursive DNS server')),
('ntp-server', _l('NTP server')),
('radius-server', _l('Radius server')),
('log-server', _l('Log server')),
('ldap-master-server', _l('LDAP master server')),
('ldap-backup-server', _l('LDAP backup server')),
('smtp-server', _l('SMTP server')),
('postgresql-server', _l('postgreSQL server')),
('mysql-server', _l('mySQL server')),
('sql-client', _l('SQL client')),
('gateway', _l('Gatewaw')),
role_type = models.CharField(max_length=255, unique=True)
......@@ -1475,21 +1474,28 @@ class Role(RevMixin, AclMixin, models.Model):
class Meta:
permissions = (
("view_role", "Peut voir un objet service"),
("view_role", _l("Can view a role.")),
verbose_name = _l("Server role")
def get_instance(cls, machineid, *_args, **_kwargs):
"""Get the Machine instance with machineid.
:param userid: The id
:return: The user
def get_instance(cls, roleid, *_args, **_kwargs):
"""Get the Role instance with roleid.
roleid: The id
The role.
return cls.objects.get(pk=machineid)
return cls.objects.get(pk=roleid)
def interface_for_roletype(cls, roletype):
"""Return interfaces for a roletype"""
return Interface.objects.filter(role=cls.objects.filter(specific_role=roletype))
return Interface.objects.filter(
def save(self, *args, **kwargs):
super(Role, self).save(*args, **kwargs)
......@@ -1497,6 +1503,7 @@ class Role(RevMixin, AclMixin, models.Model):
def __str__(self):
return str(self.role_type)
class Service(RevMixin, AclMixin, models.Model):
""" Definition d'un service (dhcp, dns, etc)"""
PRETTY_NAME = "Services à générer (dhcp, dns, etc)"
......@@ -23,13 +23,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load i18n %}
<table class="table table-striped">
<table class="table table-striped">
<th>Nom du role</th>
<th>Role spécifique</th>
<th>Serveurs inclus</th>
<th>{% trans "Role name" %}</th>
<th>{% trans "Specific role" %}</th>
<th>{% trans "Servers" %}</th>
......@@ -47,5 +49,5 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endfor %}
......@@ -40,6 +40,7 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import ProtectedError, F
from django.forms import modelformset_factory
from django.views.decorators.csrf import csrf_exempt
from django.utils.translation import ugettext as _
from rest_framework.renderers import JSONRenderer
......@@ -1168,10 +1169,10 @@ def edit_role(request, role_instance, **_kwargs):
if role.is_valid():
if role.changed_data:
messages.success(request, "Role modifié")
messages.success(request, _("Role updated"))
return redirect(reverse('machines:index-role'))
return form(
{'roleform': role, 'action_name': 'Editer'},
{'roleform': role, 'action_name': _('Edit')},
......@@ -1187,22 +1188,22 @@ def del_role(request, instances):
for role_del in role_dels:
messages.success(request, "Le role a été supprimée")
messages.success(request, _("The role has been deleted."))
except ProtectedError:
("Erreur le role suivant %s ne peut être supprimé"
% role_del)
(_("Error: The following role cannot be deleted: %(role)")
% {'role': role_del}
return redirect(reverse('machines:index-role'))
return form(
{'roleform': role, 'action_name': 'Supprimer'},
{'roleform': role, 'action_name': _('Delete')},
def add_service(request):
......@@ -1699,11 +1700,12 @@ def configure_ports(request, interface_instance, **_kwargs):
## Framework Rest
# Framework Rest
class JSONResponse(HttpResponse):
""" Class to build a JSON response. Used for API """
def __init__(self, data, **kwargs):
content = JSONRenderer().render(data)
kwargs['content_type'] = 'application/json'
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