forms.py 6.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
# 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
        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'
51
        self.fields['max_solde'].label = 'Solde maximum'
52

53

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

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

74

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

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

93

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

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

119 120

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

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

143

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

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

162

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

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


174 175 176
class DelServiceForm(Form):
    """Suppression de services sur la page d'accueil"""
    services = forms.ModelMultipleChoiceField(
177
        queryset=Service.objects.none(),
178 179 180
        label="Enregistrements service actuels",
        widget=forms.CheckboxSelectMultiple
    )
181 182 183 184 185 186 187 188

    def __init__(self, *args, **kwargs):
        instances = kwargs.pop('instances', None)
        super(DelServiceForm, self).__init__(*args, **kwargs)
        if instances:
            self.fields['services'].queryset = instances
        else:
            self.fields['services'].queryset = Service.objects.all()