8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 20:33:11 +00:00

Crée une application préférences pour les options de config

This commit is contained in:
chibrac 2017-06-26 00:50:55 +02:00
parent c0410f9faf
commit 51759d2c93
17 changed files with 480 additions and 3 deletions

0
preferences/__init__.py Normal file
View file

3
preferences/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
preferences/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class PreferencesConfig(AppConfig):
name = 'preferences'

59
preferences/forms.py Normal file
View file

@ -0,0 +1,59 @@
# Re2o un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from django.forms import ModelForm, Form, ValidationError
from django import forms
from .models import OptionalUser, OptionalMachine, GeneralOption
from django.db.models import Q
class EditUserOptionsForm(ModelForm):
class Meta:
model = OptionalUser
fields = '__all__'
def __init__(self, *args, **kwargs):
super(EditUserOptionsForm, self).__init__(*args, **kwargs)
self.fields['is_tel_mandatory'].label = 'Exiger un numéro de téléphone'
self.fields['user_solde'].label = 'Activation du solde pour les utilisateurs'
class EditMachineOptionsForm(ModelForm):
class Meta:
model = OptionalMachine
fields = '__all__'
def __init__(self, *args, **kwargs):
super(EditMachineOptionsForm, self).__init__(*args, **kwargs)
self.fields['password_machine'].label = "Possibilité d'attribuer un mot de passe par interface"
self.fields['max_lambdauser_interfaces'].label = "Maximum d'interfaces autorisées pour un user normal"
self.fields['max_lambdauser_aliases'].label = "Maximum d'alias dns autorisés pour un user normal"
class EditGeneralOptionsForm(ModelForm):
class Meta:
model = GeneralOption
fields = '__all__'
def __init__(self, *args, **kwargs):
super(EditGeneralOptionsForm, self).__init__(*args, **kwargs)
self.fields['search_display_page'].label = 'Resultats affichés dans une recherche'
self.fields['pagination_number'].label = 'Items par page, taille normale (ex users)'
self.fields['pagination_large_number'].label = 'Items par page, taille élevée (machines)'

View file

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-06-25 02:19
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='GeneralOption',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('search_display_page', models.IntegerField(default=15)),
],
),
migrations.CreateModel(
name='OptionalMachine',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password_machine', models.BooleanField(default=True)),
('max_lambdauser_interfaces', models.IntegerField(default=10)),
('max_lambdauser_aliases', models.IntegerField(default=10)),
],
),
migrations.CreateModel(
name='OptionalUser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_tel_mandatory', models.BooleanField(default=True)),
('user_solde', models.BooleanField(default=True)),
],
),
]

View file

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-06-25 17:23
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='generaloption',
name='pagination_large_number',
field=models.IntegerField(default=8),
),
migrations.AddField(
model_name='generaloption',
name='pagination_number',
field=models.IntegerField(default=25),
),
migrations.AddField(
model_name='optionaluser',
name='gpg_fingerprint',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='optionalmachine',
name='password_machine',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='optionaluser',
name='user_solde',
field=models.BooleanField(default=False),
),
]

View file

44
preferences/models.py Normal file
View file

@ -0,0 +1,44 @@
# Re2o un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from django.db import models
class OptionalUser(models.Model):
is_tel_mandatory = models.BooleanField(default=True)
user_solde = models.BooleanField(default=False)
gpg_fingerprint = models.BooleanField(default=True)
class OptionalMachine(models.Model):
password_machine = models.BooleanField(default=False)
max_lambdauser_interfaces = models.IntegerField(default=10)
max_lambdauser_aliases = models.IntegerField(default=10)
#class OptionalTopologie(models.Model):
class GeneralOption(models.Model):
search_display_page = models.IntegerField(default=15)
pagination_number = models.IntegerField(default=25)
pagination_large_number = models.IntegerField(default=8)

View file

@ -0,0 +1,79 @@
{% extends "preferences/sidebar.html" %}
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load bootstrap3 %}
{% block title %}Création et modification des préférences{% endblock %}
{% block content %}
{% if is_bureau %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' %}">
<i class="glyphicon glyphicon-edit"></i>
Editer
</a>
{% endif %}
<h4>Préférences utilisateur</h4>
<table class="table table-striped">
<tr>
<th>Téléphone obligatoirement requis</th>
<td>{{ useroptions.is_tel_mandatory }}</td>
<th>Activation du solde pour les utilisateurs</th>
<td>{{ useroptions.user_solde }}</td>
</tr>
<tr>
<th>Champ gpg fingerprint</th>
<td>{{ useroptions.gpg_fingerprint }}</td>
</tr>
</table>
<h4>Préférences machines</h4>
<table class="table table-striped">
<tr>
<th>Mot de passe par machine</th>
<td>{{ machineoptions.password_machine }}</td>
<th>Machines/interfaces autorisées par utilisateurs</th>
<td>{{ machineoptions.max_lambdauser_interfaces }}</td>
</tr>
<tr>
<th>Alias dns autorisé par utilisateur</th>
<td>{{ machineoptions.max_lambdauser_aliases }}</td>
</tr>
</table>
<h4>Préférences generales</h4>
<table class="table table-striped">
<tr>
<th>Affichage de résultats dans le champ de recherche</th>
<td>{{ generaloptions.search_display_page }}</td>
<th>Nombre d'items affichés en liste (taille normale)</th>
<td>{{ generaloptions.pagination_number }}</td>
</tr>
<tr>
<th>Nombre d'items affichés en liste (taille élevée)</th>
<td>{{ generaloptions.pagination_large_number }}</td>
</tr>
</table>
<br />
<br />
<br />
{% endblock %}

View file

@ -0,0 +1,45 @@
{% extends "preferences/sidebar.html" %}
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load bootstrap3 %}
{% block title %}Création et modification des préférences{% endblock %}
{% block content %}
{% bootstrap_form_errors useroptions %}
{% bootstrap_form_errors machineoptions %}
{% bootstrap_form_errors generaloptions %}
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form useroptions %}
{% bootstrap_form machineoptions %}
{% bootstrap_form generaloptions %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<br />
<br />
<br />
{% endblock %}

View file

@ -0,0 +1,28 @@
{% extends "base.html" %}
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% block sidebar %}
{% endblock %}

3
preferences/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

31
preferences/urls.py Normal file
View file

@ -0,0 +1,31 @@
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^edit_options/$', views.edit_options, name='edit-options'),
url(r'^$', views.display_options, name='display-options'),
]

88
preferences/views.py Normal file
View file

@ -0,0 +1,88 @@
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# App de gestion des machines pour re2o
# Gabriel Détraz, Augustin Lemesle
# Gplv2
from django.shortcuts import render
from django.shortcuts import get_object_or_404, render, redirect
from django.template.context_processors import csrf
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template import Context, RequestContext, loader
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import Max, ProtectedError
from django.db import IntegrityError
from django.core.mail import send_mail
from django.utils import timezone
from django.core.urlresolvers import reverse
from django.db import transaction
from reversion.models import Version
from reversion import revisions as reversion
from .forms import EditUserOptionsForm, EditMachineOptionsForm, EditGeneralOptionsForm
from .models import OptionalUser, OptionalMachine, GeneralOption
def form(ctx, template, request):
c = ctx
c.update(csrf(request))
return render(request, template, c)
@login_required
@permission_required('cableur')
def display_options(request):
useroptions, created = OptionalUser.objects.get_or_create()
machineoptions, created = OptionalMachine.objects.get_or_create()
generaloptions, created = GeneralOption.objects.get_or_create()
return form({'useroptions': useroptions, 'machineoptions': machineoptions, 'generaloptions': generaloptions}, 'preferences/display_preferences.html', request)
@login_required
@permission_required('admin')
def edit_options(request):
""" Edition des préférences générales"""
useroptions_instance, created = OptionalUser.objects.get_or_create()
machineoptions_instance, created = OptionalMachine.objects.get_or_create()
generaloptions_instance, created = GeneralOption.objects.get_or_create()
useroptions = EditUserOptionsForm(request.POST or None, instance=useroptions_instance)
machineoptions = EditMachineOptionsForm(request.POST or None, instance=machineoptions_instance)
generaloptions = EditGeneralOptionsForm(request.POST or None, instance=generaloptions_instance)
if useroptions.is_valid():
with transaction.atomic(), reversion.create_revision():
useroptions.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in useroptions.changed_data))
if machineoptions.is_valid():
with transaction.atomic(), reversion.create_revision():
machineoptions.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machineoptions.changed_data))
if generaloptions.is_valid():
with transaction.atomic(), reversion.create_revision():
generaloptions.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in generaloptions.changed_data))
return form({'useroptions': useroptions, 'machineoptions': machineoptions, 'generaloptions': generaloptions}, 'preferences/edit_preferences.html', request)

View file

@ -70,6 +70,7 @@ INSTALLED_APPS = (
'topologie',
'search',
're2o',
'preferences',
'logs',
'rest_framework',
'reversion'

View file

@ -51,4 +51,6 @@ urlpatterns = [
url(r'^machines/', include('machines.urls', namespace='machines')),
url(r'^topologie/', include('topologie.urls', namespace='topologie')),
url(r'^logs/', include('logs.urls', namespace='logs')),
url(r'^preferences/', include('preferences.urls', namespace='preferences')),
]

View file

@ -87,6 +87,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endif %}
</li>
</ul>
{% if is_cableur %}
<ul class="nav navbar-nav navbar-right">
<li>
<a href="{% url 'preferences:display-options' %}">
<span class="glyphicon glyphicon-cog"></span> Preferences
</a>
</li>
</ul>
{% endif %}
</div>
</div>
</nav>