2017-06-25 22:50:55 +00:00
|
|
|
# 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.
|
2017-10-14 04:03:53 +00:00
|
|
|
"""
|
|
|
|
Formulaire d'edition des réglages : user, machine, topologie, asso...
|
|
|
|
"""
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
2018-05-06 17:11:12 +00:00
|
|
|
from re2o.mixins import FormRevMixin
|
2017-09-10 23:29:24 +00:00
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
from django.forms import ModelForm, Form
|
2017-06-25 22:50:55 +00:00
|
|
|
from django import forms
|
2018-04-16 03:28:27 +00:00
|
|
|
from .models import (
|
|
|
|
OptionalUser,
|
|
|
|
OptionalMachine,
|
|
|
|
OptionalTopologie,
|
|
|
|
GeneralOption,
|
|
|
|
AssoOption,
|
|
|
|
MailMessageOption,
|
2018-04-16 16:22:51 +00:00
|
|
|
HomeOption,
|
2018-06-30 17:19:40 +00:00
|
|
|
Service,
|
2018-07-01 15:13:09 +00:00
|
|
|
MailContact,
|
2018-05-06 17:11:12 +00:00
|
|
|
Reminder
|
2018-04-16 03:28:27 +00:00
|
|
|
)
|
2018-07-09 19:05:50 +00:00
|
|
|
from topologie.models import Switch
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class EditOptionalUserForm(ModelForm):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Formulaire d'édition des options de l'user. (solde, telephone..)"""
|
2017-06-25 22:50:55 +00:00
|
|
|
class Meta:
|
|
|
|
model = OptionalUser
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-14 04:03:53 +00:00
|
|
|
super(EditOptionalUserForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class EditOptionalMachineForm(ModelForm):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Options machines (max de machines, etc)"""
|
2017-06-25 22:50:55 +00:00
|
|
|
class Meta:
|
|
|
|
model = OptionalMachine
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-14 04:03:53 +00:00
|
|
|
super(EditOptionalMachineForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**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"
|
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
class EditOptionalTopologieForm(ModelForm):
|
2018-07-09 19:05:50 +00:00
|
|
|
"""Options de topologie, formulaire d'edition (vlan par default etc)
|
|
|
|
On rajoute un champ automatic provision switchs pour gérer facilement
|
|
|
|
l'ajout de switchs au provisionning automatique"""
|
|
|
|
automatic_provision_switchs = forms.ModelMultipleChoiceField(
|
|
|
|
Switch.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = OptionalTopologie
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-14 04:03:53 +00:00
|
|
|
super(EditOptionalTopologieForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
self.fields['vlan_decision_ok'].label = "Vlan où placer les\
|
|
|
|
machines après acceptation RADIUS"
|
|
|
|
self.fields['vlan_decision_nok'].label = "Vlan où placer les\
|
|
|
|
machines après rejet RADIUS"
|
|
|
|
|
2018-07-09 19:05:50 +00:00
|
|
|
self.initial['automatic_provision_switchs'] = Switch.objects.filter(automatic_provision=True)
|
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
instance = super().save(commit)
|
|
|
|
Switch.objects.all().update(automatic_provision=False)
|
|
|
|
self.cleaned_data['automatic_provision_switchs'].update(automatic_provision=True)
|
|
|
|
return instance
|
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class EditGeneralOptionForm(ModelForm):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Options générales (affichages de résultats de recherche, etc)"""
|
2017-06-25 22:50:55 +00:00
|
|
|
class Meta:
|
|
|
|
model = GeneralOption
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-14 04:03:53 +00:00
|
|
|
super(EditGeneralOptionForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**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)'
|
|
|
|
self.fields['req_expire_hrs'].label = 'Temps avant expiration du lien\
|
|
|
|
de reinitialisation de mot de passe (en heures)'
|
2017-09-08 21:30:47 +00:00
|
|
|
self.fields['site_name'].label = 'Nom du site web'
|
2017-10-14 04:03:53 +00:00
|
|
|
self.fields['email_from'].label = "Adresse mail d\
|
|
|
|
'expedition automatique"
|
2018-01-14 22:47:44 +00:00
|
|
|
self.fields['GTU_sum_up'].label = "Résumé des CGU"
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
|
|
|
|
class EditAssoOptionForm(ModelForm):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Options de l'asso (addresse, telephone, etc)"""
|
2017-08-24 19:36:59 +00:00
|
|
|
class Meta:
|
|
|
|
model = AssoOption
|
|
|
|
fields = '__all__'
|
|
|
|
|
2017-09-08 21:30:47 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-14 04:03:53 +00:00
|
|
|
super(EditAssoOptionForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|
2017-09-08 21:30:47 +00:00
|
|
|
self.fields['name'].label = 'Nom de l\'asso'
|
|
|
|
self.fields['siret'].label = 'SIRET'
|
|
|
|
self.fields['adresse1'].label = 'Adresse (ligne 1)'
|
|
|
|
self.fields['adresse2'].label = 'Adresse (ligne 2)'
|
|
|
|
self.fields['contact'].label = 'Email de contact'
|
|
|
|
self.fields['telephone'].label = 'Numéro de téléphone'
|
|
|
|
self.fields['pseudo'].label = 'Pseudo d\'usage'
|
2017-10-14 04:03:53 +00:00
|
|
|
self.fields['utilisateur_asso'].label = 'Compte utilisé pour\
|
|
|
|
faire les modifications depuis /admin'
|
|
|
|
|
2018-03-18 09:10:56 +00:00
|
|
|
def clean(self):
|
|
|
|
cleaned_data = super().clean()
|
|
|
|
payment = cleaned_data.get('payment')
|
|
|
|
|
|
|
|
if payment == 'NONE':
|
|
|
|
return cleaned_data
|
|
|
|
|
|
|
|
if not cleaned_data.get('payment_id', ''):
|
|
|
|
msg = forms.ValidationError("Vous devez spécifier un identifiant \
|
|
|
|
de paiement.")
|
|
|
|
self.add_error('payment_id', msg)
|
|
|
|
if not cleaned_data.get('payment_pass', ''):
|
|
|
|
msg = forms.ValidationError("Vous devez spécifier un mot de passe \
|
|
|
|
de paiement.")
|
|
|
|
self.add_error('payment_pass', msg)
|
|
|
|
|
|
|
|
return cleaned_data
|
|
|
|
|
|
|
|
|
2017-09-08 20:53:13 +00:00
|
|
|
class EditMailMessageOptionForm(ModelForm):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Formulaire d'edition des messages de bienvenue personnalisés"""
|
2017-09-08 20:53:13 +00:00
|
|
|
class Meta:
|
|
|
|
model = MailMessageOption
|
|
|
|
fields = '__all__'
|
|
|
|
|
2017-09-08 21:30:47 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-14 04:03:53 +00:00
|
|
|
super(EditMailMessageOptionForm, self).__init__(
|
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
self.fields['welcome_mail_fr'].label = 'Message dans le\
|
|
|
|
mail de bienvenue en français'
|
|
|
|
self.fields['welcome_mail_en'].label = 'Message dans le\
|
|
|
|
mail de bienvenue en anglais'
|
|
|
|
|
2017-09-08 20:53:13 +00:00
|
|
|
|
2018-04-16 16:22:51 +00:00
|
|
|
class EditHomeOptionForm(ModelForm):
|
|
|
|
"""Edition forms of Home options"""
|
2018-04-16 03:28:27 +00:00
|
|
|
class Meta:
|
2018-04-16 16:22:51 +00:00
|
|
|
model = HomeOption
|
2018-04-16 03:28:27 +00:00
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2018-04-16 16:22:51 +00:00
|
|
|
super(EditHomeOptionForm, self).__init__(
|
2018-04-16 03:28:27 +00:00
|
|
|
*args,
|
|
|
|
prefix=prefix,
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-05-06 17:11:12 +00:00
|
|
|
class ServiceForm(FormRevMixin, ModelForm):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Edition, ajout de services sur la page d'accueil"""
|
2017-08-24 19:36:59 +00:00
|
|
|
class Meta:
|
|
|
|
model = Service
|
|
|
|
fields = '__all__'
|
2017-08-25 02:35:49 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
2018-05-06 17:11:12 +00:00
|
|
|
class ReminderForm(FormRevMixin, ModelForm):
|
|
|
|
"""Edition, ajout de rappel"""
|
|
|
|
class Meta:
|
|
|
|
model = Reminder
|
|
|
|
fields = '__all__'
|
2017-12-13 17:56:16 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-05-06 17:11:12 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
super(ReminderForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2018-06-30 17:19:40 +00:00
|
|
|
|
2018-07-01 15:13:09 +00:00
|
|
|
|
2018-06-30 17:19:40 +00:00
|
|
|
class MailContactForm(ModelForm):
|
|
|
|
"""Edition, ajout d'adresse de contact"""
|
|
|
|
class Meta:
|
|
|
|
model = MailContact
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
super(MailContactForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class DelMailContactForm(Form):
|
|
|
|
"""Suppression d'adresse de contact"""
|
|
|
|
mailcontacts = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=MailContact.objects.none(),
|
|
|
|
label="Enregistrements adresses actuels",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
instances = kwargs.pop('instances', None)
|
|
|
|
super(DelMailContactForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
|
|
|
self.fields['mailcontacts'].queryset = instances
|
|
|
|
else:
|
|
|
|
self.fields['mailcontacts'].queryset = MailContact.objects.all()
|