forms.py 6.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# 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.
22 23 24
"""
Formulaire d'edition des réglages : user, machine, topologie, asso...
"""
25

26 27
from __future__ import unicode_literals

28
from django.forms import ModelForm, Form
29
from django import forms
30 31 32
from .models import OptionalUser, OptionalMachine, OptionalTopologie
from .models import GeneralOption, AssoOption, MailMessageOption, Service

33

34
class EditOptionalUserForm(ModelForm):
35
    """Formulaire d'édition des options de l'user. (solde, telephone..)"""
36 37 38 39 40
    class Meta:
        model = OptionalUser
        fields = '__all__'

    def __init__(self, *args, **kwargs):
41
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
42 43 44 45 46 47 48 49 50 51
        super(EditOptionalUserForm, self).__init__(
            *args,
            prefix=prefix,
            **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'

52

53
class EditOptionalMachineForm(ModelForm):
54
    """Options machines (max de machines, etc)"""
55 56 57 58 59
    class Meta:
        model = OptionalMachine
        fields = '__all__'

    def __init__(self, *args, **kwargs):
60
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
61 62 63 64 65 66 67 68 69 70 71 72
        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"

73

74
class EditOptionalTopologieForm(ModelForm):
75
    """Options de topologie, formulaire d'edition (vlan par default etc)"""
76 77 78 79 80
    class Meta:
        model = OptionalTopologie
        fields = '__all__'

    def __init__(self, *args, **kwargs):
81
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
82 83 84 85 86 87 88 89 90 91
        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"

92

93
class EditGeneralOptionForm(ModelForm):
94
    """Options générales (affichages de résultats de recherche, etc)"""
95 96 97 98 99
    class Meta:
        model = GeneralOption
        fields = '__all__'

    def __init__(self, *args, **kwargs):
100
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
101 102 103 104 105 106 107 108 109 110 111 112 113
        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)'
114
        self.fields['site_name'].label = 'Nom du site web'
115 116 117
        self.fields['email_from'].label = "Adresse mail d\
        'expedition automatique"

118 119

class EditAssoOptionForm(ModelForm):
120
    """Options de l'asso (addresse, telephone, etc)"""
121 122 123 124
    class Meta:
        model = AssoOption
        fields = '__all__'

125
    def __init__(self, *args, **kwargs):
126
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
127 128 129 130 131
        super(EditAssoOptionForm, self).__init__(
            *args,
            prefix=prefix,
            **kwargs
        )
132 133 134 135 136 137 138
        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'
139 140 141
        self.fields['utilisateur_asso'].label = 'Compte utilisé pour\
        faire les modifications depuis /admin'

142

143
class EditMailMessageOptionForm(ModelForm):
144
    """Formulaire d'edition des messages de bienvenue personnalisés"""
145 146 147 148
    class Meta:
        model = MailMessageOption
        fields = '__all__'

149
    def __init__(self, *args, **kwargs):
150
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
151 152 153 154 155 156 157 158 159 160
        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'

161

162
class ServiceForm(ModelForm):
163
    """Edition, ajout de services sur la page d'accueil"""
164 165 166
    class Meta:
        model = Service
        fields = '__all__'
167

168
    def __init__(self, *args, **kwargs):
169
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
170 171 172
        super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs)


173 174 175 176 177 178 179
class DelServiceForm(Form):
    """Suppression de services sur la page d'accueil"""
    services = forms.ModelMultipleChoiceField(
        queryset=Service.objects.all(),
        label="Enregistrements service actuels",
        widget=forms.CheckboxSelectMultiple
    )