diff --git a/preferences/__init__.py b/preferences/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/preferences/admin.py b/preferences/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/preferences/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/preferences/apps.py b/preferences/apps.py new file mode 100644 index 00000000..85238099 --- /dev/null +++ b/preferences/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PreferencesConfig(AppConfig): + name = 'preferences' diff --git a/preferences/forms.py b/preferences/forms.py new file mode 100644 index 00000000..ec1de82b --- /dev/null +++ b/preferences/forms.py @@ -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)' diff --git a/preferences/migrations/0001_initial.py b/preferences/migrations/0001_initial.py new file mode 100644 index 00000000..8604dc84 --- /dev/null +++ b/preferences/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/preferences/migrations/0002_auto_20170625_1923.py b/preferences/migrations/0002_auto_20170625_1923.py new file mode 100644 index 00000000..9244811a --- /dev/null +++ b/preferences/migrations/0002_auto_20170625_1923.py @@ -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), + ), + ] diff --git a/preferences/migrations/__init__.py b/preferences/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/preferences/models.py b/preferences/models.py new file mode 100644 index 00000000..00fa0cb1 --- /dev/null +++ b/preferences/models.py @@ -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) + diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html new file mode 100644 index 00000000..a4d6c583 --- /dev/null +++ b/preferences/templates/preferences/display_preferences.html @@ -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 %} + + + Editer + + {% endif %} +

Préférences utilisateur

+ + + + + + + + + + + +
Téléphone obligatoirement requis{{ useroptions.is_tel_mandatory }}Activation du solde pour les utilisateurs{{ useroptions.user_solde }}
Champ gpg fingerprint{{ useroptions.gpg_fingerprint }}
+

Préférences machines

+ + + + + + + + + + + +
Mot de passe par machine{{ machineoptions.password_machine }}Machines/interfaces autorisées par utilisateurs{{ machineoptions.max_lambdauser_interfaces }}
Alias dns autorisé par utilisateur{{ machineoptions.max_lambdauser_aliases }}
+

Préférences generales

+ + + + + + + + + + + +
Affichage de résultats dans le champ de recherche{{ generaloptions.search_display_page }}Nombre d'items affichés en liste (taille normale){{ generaloptions.pagination_number }}
Nombre d'items affichés en liste (taille élevée){{ generaloptions.pagination_large_number }}
+
+
+
+{% endblock %} diff --git a/preferences/templates/preferences/edit_preferences.html b/preferences/templates/preferences/edit_preferences.html new file mode 100644 index 00000000..ca4b2736 --- /dev/null +++ b/preferences/templates/preferences/edit_preferences.html @@ -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 %} + +
+{% csrf_token %} +{% bootstrap_form useroptions %} +{% bootstrap_form machineoptions %} +{% bootstrap_form generaloptions %} +{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %} +
+
+
+
+{% endblock %} diff --git a/preferences/templates/preferences/sidebar.html b/preferences/templates/preferences/sidebar.html new file mode 100644 index 00000000..4f69298b --- /dev/null +++ b/preferences/templates/preferences/sidebar.html @@ -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 %} diff --git a/preferences/tests.py b/preferences/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/preferences/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/preferences/urls.py b/preferences/urls.py new file mode 100644 index 00000000..51a0edf9 --- /dev/null +++ b/preferences/urls.py @@ -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'), +] diff --git a/preferences/views.py b/preferences/views.py new file mode 100644 index 00000000..18673bdd --- /dev/null +++ b/preferences/views.py @@ -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) + diff --git a/re2o/settings.py b/re2o/settings.py index e11d899a..09d0278e 100644 --- a/re2o/settings.py +++ b/re2o/settings.py @@ -70,6 +70,7 @@ INSTALLED_APPS = ( 'topologie', 'search', 're2o', + 'preferences', 'logs', 'rest_framework', 'reversion' diff --git a/re2o/urls.py b/re2o/urls.py index 62f2641a..74e3640c 100644 --- a/re2o/urls.py +++ b/re2o/urls.py @@ -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')), + ] diff --git a/templates/base.html b/templates/base.html index aa7222dd..0bb98e65 100644 --- a/templates/base.html +++ b/templates/base.html @@ -85,9 +85,18 @@ with this program; if not, write to the Free Software Foundation, Inc., Login {% endif %} - - - + + + {% if is_cableur %} + + {% endif %} +