2017-06-25 22:50:55 +00:00
|
|
|
# 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
|
2019-09-29 14:02:28 +00:00
|
|
|
# Copyright © 2017 Lara Kermarec
|
2017-06-25 22:50:55 +00:00
|
|
|
# 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.
|
2017-10-14 04:03:53 +00:00
|
|
|
"""
|
2020-05-30 09:22:55 +00:00
|
|
|
Forms to edit preferences: users, machines, topology, organisation etc.
|
2017-10-14 04:03:53 +00:00
|
|
|
"""
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
from django.forms import ModelForm, Form
|
2019-09-23 21:39:54 +00:00
|
|
|
from django.db.models import Q
|
2017-06-25 22:50:55 +00:00
|
|
|
from django import forms
|
2018-08-05 16:48:35 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2018-07-26 19:53:32 +00:00
|
|
|
from re2o.mixins import FormRevMixin
|
2018-04-16 03:28:27 +00:00
|
|
|
from .models import (
|
|
|
|
OptionalUser,
|
|
|
|
OptionalMachine,
|
|
|
|
OptionalTopologie,
|
|
|
|
GeneralOption,
|
|
|
|
AssoOption,
|
|
|
|
MailMessageOption,
|
2018-04-16 16:22:51 +00:00
|
|
|
HomeOption,
|
2018-06-30 17:19:40 +00:00
|
|
|
Service,
|
2018-09-19 21:24:03 +00:00
|
|
|
MailContact,
|
2018-07-10 23:07:31 +00:00
|
|
|
Reminder,
|
2018-07-11 00:19:29 +00:00
|
|
|
RadiusKey,
|
2018-09-19 21:24:03 +00:00
|
|
|
SwitchManagementCred,
|
2018-12-02 16:03:27 +00:00
|
|
|
RadiusOption,
|
2019-01-20 23:54:02 +00:00
|
|
|
CotisationsOption,
|
2019-09-09 15:04:30 +00:00
|
|
|
DocumentTemplate,
|
2019-09-21 21:10:28 +00:00
|
|
|
RadiusAttribute,
|
2019-11-04 16:55:03 +00:00
|
|
|
Mandate,
|
2018-04-16 03:28:27 +00:00
|
|
|
)
|
2018-09-19 21:24:03 +00:00
|
|
|
from topologie.models import Switch
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2019-01-20 23:54:02 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class EditOptionalUserForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit user preferences."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
class Meta:
|
|
|
|
model = OptionalUser
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2017-06-25 22:50:55 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(EditOptionalUserForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
self.fields["is_tel_mandatory"].label = _("Telephone number required")
|
|
|
|
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["shell_default"].label = _("Default shell")
|
2020-04-23 10:07:15 +00:00
|
|
|
self.fields["self_change_shell"].label = _("Self change shell")
|
|
|
|
self.fields["self_change_pseudo"].label = _("Self change pseudo")
|
|
|
|
self.fields["self_room_policy"].label = _("Self room policy")
|
|
|
|
self.fields["local_email_accounts_enabled"].label = _("Local email accounts enabled")
|
|
|
|
self.fields["local_email_domain"].label = _("Local email domain")
|
|
|
|
self.fields["max_email_address"].label = _("Max local email address")
|
|
|
|
self.fields["delete_notyetactive"].label = _("Delete not yet active users")
|
|
|
|
self.fields["disable_emailnotyetconfirmed"].label = _("Disabled email not yet confirmed")
|
|
|
|
self.fields["self_adhesion"].label = _("Self registration")
|
|
|
|
self.fields["all_users_active"].label = _("All users are state active by default")
|
|
|
|
self.fields["allow_set_password_during_user_creation"].label = _("Allow set password during user creation")
|
|
|
|
self.fields["allow_archived_connexion"].label = _("Allow archived connexion")
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class EditOptionalMachineForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit machine preferences."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
class Meta:
|
|
|
|
model = OptionalMachine
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2017-06-25 22:50:55 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(EditOptionalMachineForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
self.fields["password_machine"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Possibility to set a password per machine"
|
2019-11-04 16:55:03 +00:00
|
|
|
)
|
|
|
|
self.fields["max_lambdauser_interfaces"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Maximum number of interfaces allowed for a standard user"
|
2019-11-04 16:55:03 +00:00
|
|
|
)
|
|
|
|
self.fields["max_lambdauser_aliases"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Maximum number of DNS aliases allowed for a standard user"
|
2017-10-14 04:03:53 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["ipv6_mode"].label = _("IPv6 mode")
|
|
|
|
self.fields["create_machine"].label = _("Can create a machine")
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
class EditOptionalTopologieForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit the configuration of switches."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-09 19:05:50 +00:00
|
|
|
automatic_provision_switchs = forms.ModelMultipleChoiceField(
|
2019-11-04 16:55:03 +00:00
|
|
|
Switch.objects.all(), required=False
|
2018-07-09 19:05:50 +00:00
|
|
|
)
|
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = OptionalTopologie
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2017-08-26 13:10:18 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(EditOptionalTopologieForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
self.initial["automatic_provision_switchs"] = Switch.objects.filter(
|
|
|
|
automatic_provision=True
|
|
|
|
).order_by("interface__domain__name")
|
2018-07-09 19:05:50 +00:00
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
instance = super().save(commit)
|
|
|
|
Switch.objects.all().update(automatic_provision=False)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.cleaned_data["automatic_provision_switchs"].update(
|
|
|
|
automatic_provision=True
|
|
|
|
)
|
2018-07-09 19:05:50 +00:00
|
|
|
return instance
|
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class EditGeneralOptionForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit general preferences."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
class Meta:
|
|
|
|
model = GeneralOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2017-06-25 22:50:55 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(EditGeneralOptionForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
self.fields["general_message_fr"].label = _("General message in French")
|
|
|
|
self.fields["general_message_en"].label = _("General message in English")
|
|
|
|
self.fields["search_display_page"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Number of results displayed when searching"
|
2019-11-04 16:55:03 +00:00
|
|
|
)
|
|
|
|
self.fields["pagination_number"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Number of items per page, standard size (e.g. users)"
|
2017-10-14 04:03:53 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["pagination_large_number"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Number of items per page, large size (e.g. machines)"
|
2019-11-04 16:55:03 +00:00
|
|
|
)
|
|
|
|
self.fields["req_expire_hrs"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Time before expiration of the reset password link (in hours)"
|
2019-11-04 16:55:03 +00:00
|
|
|
)
|
|
|
|
self.fields["site_name"].label = _("Website name")
|
2019-11-16 14:07:59 +00:00
|
|
|
self.fields["email_from"].label = _("Email address for automatic emailing")
|
|
|
|
self.fields["GTU_sum_up"].label = _("Summary of the General Terms of Use")
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["GTU"].label = _("General Terms of Use")
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
|
|
|
|
class EditAssoOptionForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit information about the organisation."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class Meta:
|
|
|
|
model = AssoOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2017-08-24 19:36:59 +00:00
|
|
|
|
2017-09-08 21:30:47 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(EditAssoOptionForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
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")
|
2020-05-17 10:51:05 +00:00
|
|
|
self.fields["profile_image"].label = _("Profile image")
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["pseudo"].label = _("Usual name")
|
|
|
|
self.fields["utilisateur_asso"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Account used for editing from /admin"
|
2017-10-14 04:03:53 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["description"].label = _("Description")
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2018-03-18 09:10:56 +00:00
|
|
|
|
2017-09-08 20:53:13 +00:00
|
|
|
class EditMailMessageOptionForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit welcome email messages."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-09-08 20:53:13 +00:00
|
|
|
class Meta:
|
|
|
|
model = MailMessageOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2017-09-08 20:53:13 +00:00
|
|
|
|
2017-09-08 21:30:47 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(EditMailMessageOptionForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
self.fields["welcome_mail_fr"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Message for the French welcome email"
|
2019-11-04 16:55:03 +00:00
|
|
|
)
|
|
|
|
self.fields["welcome_mail_en"].label = _(
|
2019-11-16 14:07:59 +00:00
|
|
|
"Message for the English welcome email"
|
2017-10-14 04:03:53 +00:00
|
|
|
)
|
|
|
|
|
2017-09-08 20:53:13 +00:00
|
|
|
|
2018-04-16 16:22:51 +00:00
|
|
|
class EditHomeOptionForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit the social networks information displayed on the home
|
|
|
|
page.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-04-16 03:28:27 +00:00
|
|
|
class Meta:
|
2018-04-16 16:22:51 +00:00
|
|
|
model = HomeOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2018-04-16 03:28:27 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(EditHomeOptionForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
self.fields["facebook_url"].label = _("Facebook URL")
|
|
|
|
self.fields["twitter_url"].label = _("Twitter URL")
|
|
|
|
self.fields["twitter_account_name"].label = _("Twitter account name")
|
2018-04-16 03:28:27 +00:00
|
|
|
|
|
|
|
|
2018-12-02 16:03:27 +00:00
|
|
|
class EditRadiusOptionForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit RADIUS preferences."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-12-02 16:03:27 +00:00
|
|
|
class Meta:
|
|
|
|
model = RadiusOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2018-12-02 16:03:27 +00:00
|
|
|
|
2019-01-11 12:43:57 +00:00
|
|
|
def clean(self):
|
|
|
|
cleaned_data = super().clean()
|
2019-11-04 16:55:03 +00:00
|
|
|
ignored = ("radius_general_policy", "vlan_decision_ok")
|
|
|
|
fields = (f for f in self.fields.keys() if "vlan" not in f and f not in ignored)
|
2019-01-11 12:43:57 +00:00
|
|
|
for f in fields:
|
|
|
|
choice = cleaned_data.get(f)
|
2019-11-04 16:55:03 +00:00
|
|
|
vlan = cleaned_data.get(f + "_vlan")
|
2019-01-11 12:43:57 +00:00
|
|
|
if choice == RadiusOption.SET_VLAN and vlan is None:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.add_error(f, _("You chose to set vlan but did not set any VLAN."))
|
|
|
|
self.add_error(f + "_vlan", _("Please, choose a VLAN."))
|
2019-01-11 12:43:57 +00:00
|
|
|
return cleaned_data
|
|
|
|
|
2018-12-02 16:03:27 +00:00
|
|
|
|
2019-01-03 21:34:45 +00:00
|
|
|
class EditCotisationsOptionForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to edit subscription preferences."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-01-03 21:34:45 +00:00
|
|
|
class Meta:
|
|
|
|
model = CotisationsOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2019-01-03 21:34:45 +00:00
|
|
|
|
|
|
|
|
2019-09-21 21:10:28 +00:00
|
|
|
class MandateForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to add and edit mandates."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-09-21 21:10:28 +00:00
|
|
|
class Meta:
|
|
|
|
model = Mandate
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2019-09-21 21:10:28 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2019-09-21 21:10:28 +00:00
|
|
|
super(MandateForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
2019-09-23 21:39:54 +00:00
|
|
|
def clean_start_date(self):
|
2019-11-04 16:55:03 +00:00
|
|
|
date = self.cleaned_data.get("start_date")
|
2019-09-23 21:39:54 +00:00
|
|
|
existing_mandates = Mandate.objects.filter(
|
|
|
|
start_date__gte=date, end_date__lt=date
|
|
|
|
)
|
|
|
|
if existing_mandates:
|
|
|
|
raise forms.ValidationError(
|
2019-11-04 16:55:03 +00:00
|
|
|
_(
|
|
|
|
"There is already a mandate taking place at the specified start date."
|
|
|
|
)
|
2019-09-23 21:39:54 +00:00
|
|
|
)
|
|
|
|
return date
|
|
|
|
|
|
|
|
def clean_end_date(self):
|
2019-11-04 16:55:03 +00:00
|
|
|
date = self.cleaned_data.get("end_date")
|
2019-09-23 21:39:54 +00:00
|
|
|
if date is None:
|
|
|
|
return None
|
|
|
|
existing_mandates = Mandate.objects.filter(
|
|
|
|
start_date__gte=date, end_date__lt=date
|
|
|
|
)
|
|
|
|
if existing_mandates:
|
|
|
|
raise forms.ValidationError(
|
|
|
|
_("There is already a mandate taking place at the specified end date.")
|
|
|
|
)
|
|
|
|
return date
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
cleaned_data = super(MandateForm, self).clean()
|
2019-11-04 16:55:03 +00:00
|
|
|
start_date, end_date = cleaned_data["start_date"], cleaned_data["end_date"]
|
2019-09-28 10:38:57 +00:00
|
|
|
if end_date:
|
|
|
|
included_mandates = Mandate.objects.filter(
|
|
|
|
Q(start_date__gte=start_date, start_date__lt=end_date)
|
|
|
|
| Q(end_date__gt=start_date, end_date__lte=end_date)
|
2019-09-23 21:39:54 +00:00
|
|
|
)
|
2019-09-28 10:38:57 +00:00
|
|
|
if included_mandates:
|
|
|
|
raise forms.ValidationError(
|
|
|
|
_("The specified dates overlap with an existing mandate."),
|
2019-11-04 16:55:03 +00:00
|
|
|
code="invalid",
|
2019-09-28 10:38:57 +00:00
|
|
|
)
|
2019-09-23 21:39:54 +00:00
|
|
|
return cleaned_data
|
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
"""Warning, side effect : if a mandate with a null end_date
|
|
|
|
exists, its end_date will be set to instance.start_date, no matter the
|
|
|
|
value of commit."""
|
|
|
|
instance = super(MandateForm, self).save(commit=False)
|
|
|
|
if instance.end_date is None:
|
|
|
|
try:
|
|
|
|
previous_mandate = Mandate.objects.get(end_date__isnull=True)
|
|
|
|
previous_mandate.end_date = instance.start_date
|
|
|
|
previous_mandate.save()
|
|
|
|
except Mandate.DoesNotExist:
|
|
|
|
pass
|
|
|
|
if commit:
|
|
|
|
instance.save()
|
|
|
|
return instance
|
|
|
|
|
2019-09-21 21:10:28 +00:00
|
|
|
|
2017-08-25 02:35:49 +00:00
|
|
|
class ServiceForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to add and edit services displayed on the home page."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class Meta:
|
|
|
|
model = Service
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2017-08-25 02:35:49 +00:00
|
|
|
|
2017-10-08 20:22:04 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["name"].label = _("Name")
|
|
|
|
self.fields["url"].label = _("URL")
|
|
|
|
self.fields["description"].label = _("Description")
|
|
|
|
self.fields["image"].label = _("Image")
|
2017-10-08 20:22:04 +00:00
|
|
|
|
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
class DelServiceForm(Form):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to delete one or several services displayed on the home page.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
services = forms.ModelMultipleChoiceField(
|
2017-12-13 17:56:16 +00:00
|
|
|
queryset=Service.objects.none(),
|
2018-08-05 16:48:35 +00:00
|
|
|
label=_("Current services"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2017-10-14 04:03:53 +00:00
|
|
|
)
|
2017-12-13 17:56:16 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2017-12-13 17:56:16 +00:00
|
|
|
super(DelServiceForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["services"].queryset = instances
|
2017-12-13 17:56:16 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["services"].queryset = Service.objects.all()
|
|
|
|
|
2018-06-30 17:19:40 +00:00
|
|
|
|
2018-09-19 21:24:03 +00:00
|
|
|
class ReminderForm(FormRevMixin, ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to add and edit reminders."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-09-19 21:24:03 +00:00
|
|
|
class Meta:
|
|
|
|
model = Reminder
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2018-09-19 21:24:03 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2018-09-19 21:24:03 +00:00
|
|
|
super(ReminderForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
2018-07-10 23:07:31 +00:00
|
|
|
|
|
|
|
class RadiusKeyForm(FormRevMixin, ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to add and edit RADIUS keys."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-10 23:07:31 +00:00
|
|
|
members = forms.ModelMultipleChoiceField(
|
2019-11-04 16:55:03 +00:00
|
|
|
queryset=Switch.objects.all(), required=False
|
2018-07-10 23:07:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = RadiusKey
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2018-07-10 23:07:31 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2018-07-10 23:07:31 +00:00
|
|
|
super(RadiusKeyForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2019-11-04 16:55:03 +00:00
|
|
|
instance = kwargs.get("instance", None)
|
2018-07-10 23:07:31 +00:00
|
|
|
if instance:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.initial["members"] = Switch.objects.filter(radius_key=instance)
|
2018-07-10 23:07:31 +00:00
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
instance = super().save(commit)
|
2019-11-04 16:55:03 +00:00
|
|
|
instance.switch_set = self.cleaned_data["members"]
|
2018-07-11 00:19:29 +00:00
|
|
|
return instance
|
|
|
|
|
|
|
|
|
|
|
|
class SwitchManagementCredForm(FormRevMixin, ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to add and edit switch management credentials."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
members = forms.ModelMultipleChoiceField(Switch.objects.all(), required=False)
|
2018-07-11 00:19:29 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SwitchManagementCred
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2018-07-11 00:19:29 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2018-07-11 00:19:29 +00:00
|
|
|
super(SwitchManagementCredForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2019-11-04 16:55:03 +00:00
|
|
|
instance = kwargs.get("instance", None)
|
2018-07-11 00:19:29 +00:00
|
|
|
if instance:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.initial["members"] = Switch.objects.filter(management_creds=instance)
|
2018-07-11 00:19:29 +00:00
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
instance = super().save(commit)
|
2019-11-04 16:55:03 +00:00
|
|
|
instance.switch_set = self.cleaned_data["members"]
|
2018-07-10 23:07:31 +00:00
|
|
|
return instance
|
|
|
|
|
|
|
|
|
|
|
|
class MailContactForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to add and edit contact email addresses."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-06-30 17:19:40 +00:00
|
|
|
class Meta:
|
|
|
|
model = MailContact
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2018-06-30 17:19:40 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2018-06-30 17:19:40 +00:00
|
|
|
super(MailContactForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class DelMailContactForm(Form):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to delete one or several contact email addresses."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-06-30 17:19:40 +00:00
|
|
|
mailcontacts = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=MailContact.objects.none(),
|
2019-01-08 23:39:47 +00:00
|
|
|
label=_("Current email addresses"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2018-06-30 17:19:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2018-06-30 17:19:40 +00:00
|
|
|
super(DelMailContactForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["mailcontacts"].queryset = instances
|
2018-06-30 17:19:40 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["mailcontacts"].queryset = MailContact.objects.all()
|
2018-08-05 16:48:35 +00:00
|
|
|
|
2019-01-20 23:54:02 +00:00
|
|
|
|
|
|
|
class DocumentTemplateForm(FormRevMixin, ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to add and edit document templates."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-01-20 23:54:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = DocumentTemplate
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2019-01-20 23:54:02 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
|
|
|
super(DocumentTemplateForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2019-01-20 23:54:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DelDocumentTemplateForm(FormRevMixin, Form):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to delete one or several document templates."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-01-20 23:54:02 +00:00
|
|
|
document_templates = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=DocumentTemplate.objects.none(),
|
2019-11-16 14:07:59 +00:00
|
|
|
label=_("Current document templates"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2019-01-20 23:54:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2019-01-20 23:54:02 +00:00
|
|
|
super(DelDocumentTemplateForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["document_templates"].queryset = instances
|
2019-01-20 23:54:02 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["document_templates"].queryset = Banque.objects.all()
|
2019-09-09 15:04:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RadiusAttributeForm(ModelForm):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to add and edit RADIUS attributes."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-09-09 15:04:30 +00:00
|
|
|
class Meta:
|
|
|
|
model = RadiusAttribute
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
2019-09-09 15:04:30 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
2019-09-09 15:04:30 +00:00
|
|
|
super(RadiusAttributeForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class DelRadiusAttributeForm(Form):
|
2020-04-29 12:23:12 +00:00
|
|
|
"""Form used to delete one or several RADIUS attributes."""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-09-09 15:04:30 +00:00
|
|
|
attributes = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=RadiusAttribute.objects.none(),
|
|
|
|
label=_("Current attributes"),
|
2019-11-04 16:55:03 +00:00
|
|
|
widget=forms.CheckboxSelectMultiple,
|
2019-09-09 15:04:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2019-11-04 16:55:03 +00:00
|
|
|
instances = kwargs.pop("instances", None)
|
2019-09-09 15:04:30 +00:00
|
|
|
super(DelServiceForm, self).__init__(*args, **kwargs)
|
|
|
|
if instances:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["attributes"].queryset = instances
|
2019-09-09 15:04:30 +00:00
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
self.fields["attributes"].queryset = Attributes.objects.all()
|