forms.py 10.5 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
from django.utils.translation import ugettext_lazy as _
31
from re2o.mixins import FormRevMixin
Gabriel Detraz's avatar
Gabriel Detraz committed
32 33 34 35 36 37 38
from .models import (
    OptionalUser,
    OptionalMachine,
    OptionalTopologie,
    GeneralOption,
    AssoOption,
    MailMessageOption,
Gabriel Detraz's avatar
Gabriel Detraz committed
39
    HomeOption,
40 41
    Service,
    MailContact
Gabriel Detraz's avatar
Gabriel Detraz committed
42
)
43

44

45
class EditOptionalUserForm(ModelForm):
46
    """Formulaire d'édition des options de l'user. (solde, telephone..)"""
47 48 49 50 51
    class Meta:
        model = OptionalUser
        fields = '__all__'

    def __init__(self, *args, **kwargs):
52
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
53 54 55 56 57
        super(EditOptionalUserForm, self).__init__(
            *args,
            prefix=prefix,
            **kwargs
        )
Maël Kervella's avatar
Maël Kervella committed
58
        self.fields['is_tel_mandatory'].label = (
59
            _("Telephone number required")
Maël Kervella's avatar
Maël Kervella committed
60
        )
61 62 63 64 65
        self.fields['gpg_fingerprint'].label = _("GPG fingerprint")
        self.fields['all_can_create_club'].label = _("All can create a club")
        self.fields['all_can_create_adherent'].label = _("All can create a member")
        self.fields['self_adhesion'].label = _("Self registration")
        self.fields['shell_default'].label = _("Default shell")
66

67

68
class EditOptionalMachineForm(ModelForm):
69
    """Options machines (max de machines, etc)"""
70 71 72 73 74
    class Meta:
        model = OptionalMachine
        fields = '__all__'

    def __init__(self, *args, **kwargs):
75
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
76 77 78 79 80
        super(EditOptionalMachineForm, self).__init__(
            *args,
            prefix=prefix,
            **kwargs
        )
81 82 83 84 85 86 87 88 89 90 91
        self.fields['password_machine'].label = _("Possibility to set a"
                                                  " password per machine")
        self.fields['max_lambdauser_interfaces'].label = _("Maximum number of"
                                                           " interfaces"
                                                           " allowed for a"
                                                           " standard user")
        self.fields['max_lambdauser_aliases'].label = _("Maximum number of DNS"
                                                        " aliases allowed for"
                                                        " a standard user")
        self.fields['ipv6_mode'].label = _("IPv6 mode")
        self.fields['create_machine'].label = _("Can create a machine")
92

93

94
class EditOptionalTopologieForm(ModelForm):
95
    """Options de topologie, formulaire d'edition (vlan par default etc)"""
96 97 98 99 100
    class Meta:
        model = OptionalTopologie
        fields = '__all__'

    def __init__(self, *args, **kwargs):
101
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
102 103 104 105 106
        super(EditOptionalTopologieForm, self).__init__(
            *args,
            prefix=prefix,
            **kwargs
        )
107 108 109 110 111
        self.fields['radius_general_policy'].label = _("RADIUS general policy")
        self.fields['vlan_decision_ok'].label = _("VLAN for machines accepted"
                                                  " by RADIUS")
        self.fields['vlan_decision_nok'].label = _("VLAN for machines rejected"
                                                   " by RADIUS")
112

113

114
class EditGeneralOptionForm(ModelForm):
115
    """Options générales (affichages de résultats de recherche, etc)"""
116 117 118 119 120
    class Meta:
        model = GeneralOption
        fields = '__all__'

    def __init__(self, *args, **kwargs):
121
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
122 123 124 125 126
        super(EditGeneralOptionForm, self).__init__(
            *args,
            prefix=prefix,
            **kwargs
        )
127 128
        self.fields['general_message_fr'].label = _("General message in French")
        self.fields['general_message_en'].label = _("General message in English")
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        self.fields['search_display_page'].label = _("Number of results"
                                                     " displayed when"
                                                     " searching")
        self.fields['pagination_number'].label = _("Number of items per page,"
                                                   " standard size (e.g."
                                                   " users)")
        self.fields['pagination_large_number'].label = _("Number of items per"
                                                         " page, large size"
                                                         " (e.g. machines)")
        self.fields['req_expire_hrs'].label = _("Time before expiration of the"
                                                " reset password link (in"
                                                " hours)")
        self.fields['site_name'].label = _("Website name")
        self.fields['email_from'].label = _("Email address for automatic"
                                            " emailing")
        self.fields['GTU_sum_up'].label = _("Summary of the General Terms of"
                                            " Use")
        self.fields['GTU'].label = _("General Terms of Use")
147

148 149

class EditAssoOptionForm(ModelForm):
150
    """Options de l'asso (addresse, telephone, etc)"""
151 152 153 154
    class Meta:
        model = AssoOption
        fields = '__all__'

155
    def __init__(self, *args, **kwargs):
156
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
157 158 159 160 161
        super(EditAssoOptionForm, self).__init__(
            *args,
            prefix=prefix,
            **kwargs
        )
162 163 164 165 166 167 168 169 170 171 172 173 174
        self.fields['name'].label = _("Organisation name")
        self.fields['siret'].label = _("SIRET number")
        self.fields['adresse1'].label = _("Address (line 1)")
        self.fields['adresse2'].label = _("Address (line 2)")
        self.fields['contact'].label = _("Contact email address")
        self.fields['telephone'].label = _("Telephone number")
        self.fields['pseudo'].label = _("Usual name")
        self.fields['utilisateur_asso'].label = _("Account used for editing"
                                                  " from /admin")
        self.fields['payment'].label = _("Payment")
        self.fields['payment_id'].label = _("Payment ID")
        self.fields['payment_pass'].label = _("Payment password")
        self.fields['description'].label = _("Description")
175

176

177
class EditMailMessageOptionForm(ModelForm):
178
    """Formulaire d'edition des messages de bienvenue personnalisés"""
179 180 181 182
    class Meta:
        model = MailMessageOption
        fields = '__all__'

183
    def __init__(self, *args, **kwargs):
184
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
185 186 187 188 189
        super(EditMailMessageOptionForm, self).__init__(
            *args,
            prefix=prefix,
            **kwargs
        )
190 191 192 193
        self.fields['welcome_mail_fr'].label = _("Message for the French"
                                                 " welcome email")
        self.fields['welcome_mail_en'].label = _("Message for the English"
                                                 " welcome email")
194

195

Gabriel Detraz's avatar
Gabriel Detraz committed
196 197
class EditHomeOptionForm(ModelForm):
    """Edition forms of Home options"""
Gabriel Detraz's avatar
Gabriel Detraz committed
198
    class Meta:
Gabriel Detraz's avatar
Gabriel Detraz committed
199
        model = HomeOption
Gabriel Detraz's avatar
Gabriel Detraz committed
200 201 202 203
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
Gabriel Detraz's avatar
Gabriel Detraz committed
204
        super(EditHomeOptionForm, self).__init__(
Gabriel Detraz's avatar
Gabriel Detraz committed
205 206 207 208
            *args,
            prefix=prefix,
            **kwargs
        )
209 210 211
        self.fields['facebook_url'].label = _("Facebook URL")
        self.fields['twitter_url'].label = _("Twitter URL")
        self.fields['twitter_account_name'].label = _("Twitter account name")
Gabriel Detraz's avatar
Gabriel Detraz committed
212 213


214
class ServiceForm(ModelForm):
215
    """Edition, ajout de services sur la page d'accueil"""
216 217 218
    class Meta:
        model = Service
        fields = '__all__'
219

220
    def __init__(self, *args, **kwargs):
221
        prefix = kwargs.pop('prefix', self.Meta.model.__name__)
222
        super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs)
223 224 225 226
        self.fields['name'].label = _("Name")
        self.fields['url'].label = _("URL")
        self.fields['description'].label = _("Description")
        self.fields['image'].label = _("Image")
227 228


229 230 231
class DelServiceForm(Form):
    """Suppression de services sur la page d'accueil"""
    services = forms.ModelMultipleChoiceField(
232
        queryset=Service.objects.none(),
233
        label=_("Current services"),
234 235
        widget=forms.CheckboxSelectMultiple
    )
236 237 238 239 240 241 242 243

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

245 246
class MailContactForm(FormRevMixin, ModelForm):
    """Edit and add contact email adress"""
247 248 249 250 251 252 253 254 255 256
    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):
257
    """Delete contact email adress"""
258 259 260 261 262 263 264 265 266 267 268 269 270
    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()
271