8
0
Fork 0
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:
Hugo LEVY-FALK 2018-07-17 21:26:42 +02:00
parent ed91cdcfe5
commit 0b86dc1ec4
5 changed files with 118 additions and 108 deletions

View file

@ -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.

View file

@ -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):

View file

@ -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
@ -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)"

View file

@ -23,13 +23,15 @@ 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"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Nom du role</th> <th>{% trans "Role name" %}</th>
<th>Role spécifique</th> <th>{% trans "Specific role" %}</th>
<th>Serveurs inclus</th> <th>{% trans "Servers" %}</th>
<th></th> <th></th>
<th></th> <th></th>
</tr> </tr>

View file

@ -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
@ -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):
@ -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'