forms.py 6.97 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
        self.fields['min_online_payment'].label = 'Montant de rechargement minimum en ligne'
        self.fields['self_adhesion'].label = 'Auto inscription'
54

55

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

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

76

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

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

95

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

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

122 123

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

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

146

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

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

165

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

172
    def __init__(self, *args, **kwargs):
173
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
174 175 176
        super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs)


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

    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()