forms.py 4.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 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.

23 24
from __future__ import unicode_literals

25 26
from django.forms import ModelForm, Form, ValidationError
from django import forms
27
from .models import OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, AssoOption, MailMessageOption, Service
28 29
from django.db.models import Q

30
class EditOptionalUserForm(ModelForm):
31 32 33 34 35
    class Meta:
        model = OptionalUser
        fields = '__all__'

    def __init__(self, *args, **kwargs):
36
        super(EditOptionalUserForm, self).__init__(*args, **kwargs)
37 38 39
        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'

40
class EditOptionalMachineForm(ModelForm):
41 42 43 44 45
    class Meta:
        model = OptionalMachine
        fields = '__all__'

    def __init__(self, *args, **kwargs):
46
        super(EditOptionalMachineForm, self).__init__(*args, **kwargs)
47 48 49 50
        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"

51 52 53 54 55 56 57 58 59
class EditOptionalTopologieForm(ModelForm):
    class Meta:
        model = OptionalTopologie
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(EditOptionalTopologieForm, self).__init__(*args, **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"
60

61
class EditGeneralOptionForm(ModelForm):
62 63 64 65 66
    class Meta:
        model = GeneralOption
        fields = '__all__'

    def __init__(self, *args, **kwargs):
67
        super(EditGeneralOptionForm, self).__init__(*args, **kwargs)
68 69 70
        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)'
71 72 73
        self.fields['req_expire_hrs'].label = 'Temps avant expiration du lien de reinitialisation de mot de passe (en heures)'
        self.fields['site_name'].label = 'Nom du site web'
        self.fields['email_from'].label = 'Adresse mail d\'expedition automatique'
74 75 76 77 78 79

class EditAssoOptionForm(ModelForm):
    class Meta:
        model = AssoOption
        fields = '__all__'

80 81 82 83 84 85 86 87 88 89 90
    def __init__(self, *args, **kwargs):
        super(EditAssoOptionForm, self).__init__(*args, **kwargs)
        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'
        self.fields['utilisateur_asso'].label = 'Compte utilisé pour faire les modifications depuis /admin'

91 92 93 94 95
class EditMailMessageOptionForm(ModelForm):
    class Meta:
        model = MailMessageOption
        fields = '__all__'

96 97
    def __init__(self, *args, **kwargs):
        super(EditMailMessageOptionForm, self).__init__(*args, **kwargs)
98 99
        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'
100

101
class ServiceForm(ModelForm):
102 103 104
    class Meta:
        model = Service
        fields = '__all__'
105 106 107

class DelServiceForm(Form):
    services = forms.ModelMultipleChoiceField(queryset=Service.objects.all(), label="Enregistrements service actuels",  widget=forms.CheckboxSelectMultiple)