8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 01:16:27 +00:00

Black on files

This commit is contained in:
chirac 2020-12-31 20:12:36 +01:00
parent 62561b27de
commit 7ed7a57014
10 changed files with 204 additions and 222 deletions

View file

@ -45,7 +45,11 @@ from django.utils.translation import ugettext_lazy as _
from django.shortcuts import get_object_or_404
from re2o.field_permissions import FieldPermissionFormMixin
from re2o.mixins import FormRevMixin, AutocompleteModelMixin, AutocompleteMultipleModelMixin
from re2o.mixins import (
FormRevMixin,
AutocompleteModelMixin,
AutocompleteMultipleModelMixin,
)
from .models import (
Article,
Paiement,
@ -80,12 +84,8 @@ class FactureForm(FieldPermissionFormMixin, FormRevMixin, ModelForm):
model = Facture
fields = "__all__"
widgets = {
"user": AutocompleteModelMixin(
url="/users/user-autocomplete",
),
"banque": AutocompleteModelMixin(
url="/cotisations/banque-autocomplete",
),
"user": AutocompleteModelMixin(url="/users/user-autocomplete"),
"banque": AutocompleteModelMixin(url="/cotisations/banque-autocomplete"),
}
def clean(self):

View file

@ -47,10 +47,7 @@ CHOICES_ACTION_TYPE = (
("all", _("All")),
)
CHOICES_TYPE = (
("ip", _("IPv4")),
("mac", _("MAC address")),
)
CHOICES_TYPE = (("ip", _("IPv4")), ("mac", _("MAC address")))
def all_classes(module):
@ -88,14 +85,11 @@ def classes_for_action_type(action_type):
users.models.User.__name__,
users.models.Adherent.__name__,
users.models.Club.__name__,
users.models.EMailAddress.__name__
users.models.EMailAddress.__name__,
]
if action_type == "machines":
return [
machines.models.Machine.__name__,
machines.models.Interface.__name__
]
return [machines.models.Machine.__name__, machines.models.Interface.__name__]
if action_type == "subscriptions":
return all_classes(cotisations.models)
@ -115,6 +109,7 @@ def classes_for_action_type(action_type):
class ActionsSearchForm(Form):
"""Form used to do an advanced search through the logs."""
user = forms.ModelChoiceField(
label=_("Performed by"),
queryset=users.models.User.objects.all(),
@ -143,13 +138,10 @@ class ActionsSearchForm(Form):
class MachineHistorySearchForm(Form):
"""Form used to do a search through the machine histories."""
q = forms.CharField(
label=_("Search"),
max_length=100,
)
q = forms.CharField(label=_("Search"), max_length=100)
t = forms.CharField(
label=_("Search type"),
widget=forms.Select(choices=CHOICES_TYPE)
label=_("Search type"), widget=forms.Select(choices=CHOICES_TYPE)
)
s = forms.DateField(required=False, label=_("Start date"))
e = forms.DateField(required=False, label=_("End date"))

View file

@ -40,7 +40,11 @@ from django.forms import ModelForm, Form
from django.utils.translation import ugettext_lazy as _
from re2o.field_permissions import FieldPermissionFormMixin
from re2o.mixins import FormRevMixin, AutocompleteModelMixin, AutocompleteMultipleModelMixin
from re2o.mixins import (
FormRevMixin,
AutocompleteModelMixin,
AutocompleteMultipleModelMixin,
)
from .models import (
Domain,
Machine,
@ -71,11 +75,7 @@ class EditMachineForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class Meta:
model = Machine
fields = "__all__"
widgets = {
"user": AutocompleteModelMixin(
url="/users/user-autocomplete",
),
}
widgets = {"user": AutocompleteModelMixin(url="/users/user-autocomplete")}
def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -97,17 +97,16 @@ class EditInterfaceForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
model = Interface
fields = ["machine", "machine_type", "ipv4", "mac_address", "details"]
widgets = {
"machine": AutocompleteModelMixin(
url="/machines/machine-autocomplete",
),
"machine": AutocompleteModelMixin(url="/machines/machine-autocomplete"),
"machine_type": AutocompleteModelMixin(
url="/machines/machinetype-autocomplete",
url="/machines/machinetype-autocomplete"
),
"ipv4": AutocompleteModelMixin(
url="/machines/iplist-autocomplete", forward=['machine_type'],
url="/machines/iplist-autocomplete",
forward=["machine_type"],
attrs={
'data-placeholder': 'Automatic assigment. Type to choose specific ip.',
}
"data-placeholder": "Automatic assigment. Type to choose specific ip."
},
),
}
@ -159,9 +158,7 @@ class AliasForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
model = Domain
fields = ["name", "extension", "ttl"]
widgets = {
"extension": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"extension": AutocompleteModelMixin(url="/machines/extension-autocomplete")
}
def __init__(self, *args, **kwargs):
@ -213,9 +210,7 @@ class MachineTypeForm(FormRevMixin, ModelForm):
model = MachineType
fields = ["name", "ip_type"]
widgets = {
"ip_type": AutocompleteModelMixin(
url="/machines/iptype-autocomplete",
),
"ip_type": AutocompleteModelMixin(url="/machines/iptype-autocomplete")
}
def __init__(self, *args, **kwargs):
@ -252,14 +247,10 @@ class IpTypeForm(FormRevMixin, ModelForm):
model = IpType
fields = "__all__"
widgets = {
"vlan": AutocompleteModelMixin(
url="/machines/vlan-autocomplete",
),
"extension": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"vlan": AutocompleteModelMixin(url="/machines/vlan-autocomplete"),
"extension": AutocompleteModelMixin(url="/machines/extension-autocomplete"),
"ouverture_ports": AutocompleteModelMixin(
url="/machines/ouvertureportlist-autocomplete",
url="/machines/ouvertureportlist-autocomplete"
),
}
@ -392,12 +383,8 @@ class MxForm(FormRevMixin, ModelForm):
model = Mx
fields = ["zone", "priority", "name", "ttl"]
widgets = {
"zone": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"name": AutocompleteModelMixin(
url="/machines/domain-autocomplete",
),
"zone": AutocompleteModelMixin(url="/machines/extension-autocomplete"),
"name": AutocompleteModelMixin(url="/machines/domain-autocomplete"),
}
def __init__(self, *args, **kwargs):
@ -435,12 +422,8 @@ class NsForm(FormRevMixin, ModelForm):
model = Ns
fields = ["zone", "ns", "ttl"]
widgets = {
"zone": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"ns": AutocompleteModelMixin(
url="/machines/domain-autocomplete",
),
"zone": AutocompleteModelMixin(url="/machines/extension-autocomplete"),
"ns": AutocompleteModelMixin(url="/machines/domain-autocomplete"),
}
def __init__(self, *args, **kwargs):
@ -476,9 +459,7 @@ class TxtForm(FormRevMixin, ModelForm):
model = Txt
fields = "__all__"
widgets = {
"zone": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"zone": AutocompleteModelMixin(url="/machines/extension-autocomplete")
}
def __init__(self, *args, **kwargs):
@ -511,9 +492,7 @@ class DNameForm(FormRevMixin, ModelForm):
model = DName
fields = "__all__"
widgets = {
"zone": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"zone": AutocompleteModelMixin(url="/machines/extension-autocomplete")
}
def __init__(self, *args, **kwargs):
@ -546,12 +525,8 @@ class SrvForm(FormRevMixin, ModelForm):
model = Srv
fields = "__all__"
widgets = {
"extension": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"target": AutocompleteModelMixin(
url="/machines/domain-autocomplete",
),
"extension": AutocompleteModelMixin(url="/machines/extension-autocomplete"),
"target": AutocompleteModelMixin(url="/machines/domain-autocomplete"),
}
def __init__(self, *args, **kwargs):
@ -585,10 +560,10 @@ class NasForm(FormRevMixin, ModelForm):
fields = "__all__"
widgets = {
"nas_type": AutocompleteModelMixin(
url="/machines/machinetype-autocomplete",
url="/machines/machinetype-autocomplete"
),
"machine_type": AutocompleteModelMixin(
url="/machines/machinetype-autocomplete",
url="/machines/machinetype-autocomplete"
),
}
@ -623,8 +598,8 @@ class RoleForm(FormRevMixin, ModelForm):
fields = "__all__"
widgets = {
"servers": AutocompleteMultipleModelMixin(
url="/machines/interface-autocomplete",
),
url="/machines/interface-autocomplete"
)
}
def __init__(self, *args, **kwargs):
@ -661,8 +636,8 @@ class ServiceForm(FormRevMixin, ModelForm):
fields = "__all__"
widgets = {
"servers": AutocompleteMultipleModelMixin(
url="/machines/interface-autocomplete",
),
url="/machines/interface-autocomplete"
)
}
def __init__(self, *args, **kwargs):
@ -750,8 +725,8 @@ class EditOuverturePortConfigForm(FormRevMixin, ModelForm):
fields = ["port_lists"]
widgets = {
"port_lists": AutocompleteMultipleModelMixin(
url="/machines/ouvertureportlist-autocomplete",
),
url="/machines/ouvertureportlist-autocomplete"
)
}
def __init__(self, *args, **kwargs):

View file

@ -43,7 +43,7 @@ from .models import (
Extension,
Domain,
OuverturePortList,
IpList
IpList,
)
from re2o.views import AutocompleteViewMixin
@ -84,8 +84,7 @@ class InterfaceAutocomplete(AutocompleteViewMixin):
def filter_results(self):
if self.q:
self.query_set = self.query_set.filter(
Q(domain__name__icontains=self.q)
| Q(machine__name__icontains=self.q)
Q(domain__name__icontains=self.q) | Q(machine__name__icontains=self.q)
)
@ -94,11 +93,11 @@ class IpListAutocomplete(AutocompleteViewMixin):
# Precision on search to add annotations so search behaves more like users expect it to
def filter_results(self):
machine_type = self.forwarded.get('machine_type', None)
machine_type = self.forwarded.get("machine_type", None)
self.query_set = self.query_set.filter(interface__isnull=True)
if machine_type:
self.query_set = self.query_set.filter(ip_type__machinetype__id=machine_type)
if self.q:
self.query_set = self.query_set.filter(
Q(ipv4__startswith=self.q)
ip_type__machinetype__id=machine_type
)
if self.q:
self.query_set = self.query_set.filter(Q(ipv4__startswith=self.q))

View file

@ -29,7 +29,6 @@ from django.utils.translation import ugettext as _
from dal import autocomplete
class RevMixin(object):
"""A mixin to subclass the save and delete function of a model
to enforce the versioning of the object before those actions
@ -260,6 +259,7 @@ class AutocompleteModelMixin(autocomplete.ModelSelect2):
""" A mixin subclassing django-autocomplete-light's Select2 model to pass default options
See https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#passing-options-to-select2
"""
def __init__(self, *args, **kwargs):
select2_attrs = kwargs.get("attrs", {})
kwargs["attrs"] = self.fill_default_select2_attrs(select2_attrs)
@ -271,9 +271,11 @@ class AutocompleteModelMixin(autocomplete.ModelSelect2):
See https://select2.org/configuration/options-api
"""
# By default, only trigger autocompletion after 3 characters have been typed
#attrs["data-minimum-input-length"] = attrs.get("data-minimum-input-length", 3)
# attrs["data-minimum-input-length"] = attrs.get("data-minimum-input-length", 3)
# If there are less than 10 results, just show all of them (no need to autocomplete)
attrs["data-minimum-results-for-search"] = attrs.get("data-minimum-results-for-search", 10)
attrs["data-minimum-results-for-search"] = attrs.get(
"data-minimum-results-for-search", 10
)
return attrs
@ -281,6 +283,7 @@ class AutocompleteMultipleModelMixin(autocomplete.ModelSelect2Multiple):
""" A mixin subclassing django-autocomplete-light's Select2 model to pass default options
See https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#passing-options-to-select2
"""
def __init__(self, *args, **kwargs):
select2_attrs = kwargs.get("attrs", {})
kwargs["attrs"] = self.fill_default_select2_attrs(select2_attrs)
@ -292,8 +295,9 @@ class AutocompleteMultipleModelMixin(autocomplete.ModelSelect2Multiple):
See https://select2.org/configuration/options-api
"""
# By default, only trigger autocompletion after 3 characters have been typed
#attrs["data-minimum-input-length"] = attrs.get("data-minimum-input-length", 3)
# attrs["data-minimum-input-length"] = attrs.get("data-minimum-input-length", 3)
# If there are less than 10 results, just show all of them (no need to autocomplete)
attrs["data-minimum-results-for-search"] = attrs.get("data-minimum-results-for-search", 10)
attrs["data-minimum-results-for-search"] = attrs.get(
"data-minimum-results-for-search", 10
)
return attrs

View file

@ -193,5 +193,5 @@ class AutocompleteViewMixin(LoginRequiredMixin, autocomplete.Select2QuerySetView
self.filter_results()
else:
if self.q:
self.query_set = self.query_set.filter(**{ self.query_filter: self.q})
self.query_set = self.query_set.filter(**{self.query_filter: self.q})
return self.query_set

View file

@ -37,7 +37,11 @@ from django.utils.translation import ugettext_lazy as _
from machines.models import Interface
from machines.forms import EditMachineForm, NewMachineForm
from re2o.mixins import FormRevMixin, AutocompleteModelMixin, AutocompleteMultipleModelMixin
from re2o.mixins import (
FormRevMixin,
AutocompleteModelMixin,
AutocompleteMultipleModelMixin,
)
from .models import (
Port,
@ -63,20 +67,14 @@ class PortForm(FormRevMixin, ModelForm):
model = Port
fields = "__all__"
widgets = {
"switch": AutocompleteModelMixin(
url="/topologie/switch-autocomplete",
),
"room": AutocompleteModelMixin(
url="/topologie/room-autocomplete",
),
"switch": AutocompleteModelMixin(url="/topologie/switch-autocomplete"),
"room": AutocompleteModelMixin(url="/topologie/room-autocomplete"),
"machine_interface": AutocompleteModelMixin(
url="/machine/machine-autocomplete",
),
"related": AutocompleteModelMixin(
url="/topologie/port-autocomplete",
url="/machine/machine-autocomplete"
),
"related": AutocompleteModelMixin(url="/topologie/port-autocomplete"),
"custom_profile": AutocompleteModelMixin(
url="/topologie/portprofile-autocomplete",
url="/topologie/portprofile-autocomplete"
),
}
@ -184,11 +182,9 @@ class EditSwitchForm(EditMachineForm):
fields = "__all__"
widgets = {
"switchbay": AutocompleteModelMixin(
url="/topologie/switchbay-autocomplete",
),
"user": AutocompleteModelMixin(
url="/users/user-autocomplete",
url="/topologie/switchbay-autocomplete"
),
"user": AutocompleteModelMixin(url="/users/user-autocomplete"),
}
@ -206,9 +202,7 @@ class EditRoomForm(FormRevMixin, ModelForm):
model = Room
fields = "__all__"
widgets = {
"building": AutocompleteModelMixin(
url="/topologie/building-autocomplete",
),
"building": AutocompleteModelMixin(url="/topologie/building-autocomplete")
}
def __init__(self, *args, **kwargs):
@ -229,7 +223,7 @@ class EditModelSwitchForm(FormRevMixin, ModelForm):
members = forms.ModelMultipleChoiceField(
Switch.objects.all(),
widget=AutocompleteMultipleModelMixin(url="/topologie/switch-autocomplete"),
required=False
required=False,
)
class Meta:
@ -274,9 +268,7 @@ class EditSwitchBayForm(FormRevMixin, ModelForm):
model = SwitchBay
fields = "__all__"
widgets = {
"building": AutocompleteModelMixin(
url="/topologie/building-autocomplete",
),
"building": AutocompleteModelMixin(url="/topologie/building-autocomplete")
}
def __init__(self, *args, **kwargs):
@ -324,11 +316,9 @@ class EditPortProfileForm(FormRevMixin, ModelForm):
fields = "__all__"
widgets = {
"vlan_tagged": AutocompleteMultipleModelMixin(
url="/machines/vlan-autocomplete",
),
"vlan_untagged": AutocompleteModelMixin(
url="/machines/vlan-autocomplete",
url="/machines/vlan-autocomplete"
),
"vlan_untagged": AutocompleteModelMixin(url="/machines/vlan-autocomplete"),
}
def __init__(self, *args, **kwargs):

View file

@ -34,15 +34,7 @@ from __future__ import unicode_literals
from django.db.models import Q, Value, CharField
from django.db.models.functions import Concat
from .models import (
Room,
Dormitory,
Building,
Switch,
PortProfile,
Port,
SwitchBay,
)
from .models import Room, Dormitory, Building, Switch, PortProfile, Port, SwitchBay
from re2o.views import AutocompleteViewMixin
@ -55,11 +47,27 @@ class RoomAutocomplete(AutocompleteViewMixin):
# Suppose we have a dorm named Dorm, a building name B, and rooms from 001 - 999
# Comments explain what we try to match
self.query_set = self.query_set.annotate(
full_name=Concat("building__name", Value(" "), "name"), # Match when the user searches "B 001"
full_name=Concat(
"building__name", Value(" "), "name"
), # Match when the user searches "B 001"
full_name_stuck=Concat("building__name", "name"), # Match "B001"
dorm_name=Concat("building__dormitory__name", Value(" "), "name"), # Match "Dorm 001"
dorm_full_name=Concat("building__dormitory__name", Value(" "), "building__name", Value(" "), "name"), # Match "Dorm B 001"
dorm_full_colon_name=Concat("building__dormitory__name", Value(" : "), "building__name", Value(" "), "name"), # Match "Dorm : B 001" (see Room's full_name property)
dorm_name=Concat(
"building__dormitory__name", Value(" "), "name"
), # Match "Dorm 001"
dorm_full_name=Concat(
"building__dormitory__name",
Value(" "),
"building__name",
Value(" "),
"name",
), # Match "Dorm B 001"
dorm_full_colon_name=Concat(
"building__dormitory__name",
Value(" : "),
"building__name",
Value(" "),
"name",
), # Match "Dorm : B 001" (see Room's full_name property)
).all()
if self.q:
@ -89,8 +97,7 @@ class BuildingAutocomplete(AutocompleteViewMixin):
if self.q:
self.query_set = self.query_set.filter(
Q(full_name__icontains=self.q)
| Q(full_name_colon__icontains=self.q)
Q(full_name__icontains=self.q) | Q(full_name_colon__icontains=self.q)
)
@ -106,9 +113,13 @@ class PortAutocomplete(AutocompleteViewMixin):
# We want to enter the switch name, not just the port number
# Because we're concatenating a CharField and an Integer, we have to sepcify the output_field
self.query_set = self.query_set.annotate(
full_name=Concat("switch__name", Value(" "), "port", output_field=CharField()),
full_name=Concat(
"switch__name", Value(" "), "port", output_field=CharField()
),
full_name_stuck=Concat("switch__name", "port", output_field=CharField()),
full_name_dash=Concat("switch__name", Value(" - "), "port", output_field=CharField()),
full_name_dash=Concat(
"switch__name", Value(" - "), "port", output_field=CharField()
),
).all()
if self.q:
@ -126,9 +137,19 @@ class SwitchBayAutocomplete(AutocompleteViewMixin):
def filter_results(self):
# Comments explain what we try to match
self.query_set = self.query_set.annotate(
full_name=Concat("building__name", Value(" "), "name"), # Match when the user searches ""
dorm_name=Concat("building__dormitory__name", Value(" "), "name"), # Match "Dorm Local Sud"
dorm_full_name=Concat("building__dormitory__name", Value(" "), "building__name", Value(" "), "name"), # Match "Dorm J Local Sud"
full_name=Concat(
"building__name", Value(" "), "name"
), # Match when the user searches ""
dorm_name=Concat(
"building__dormitory__name", Value(" "), "name"
), # Match "Dorm Local Sud"
dorm_full_name=Concat(
"building__dormitory__name",
Value(" "),
"building__name",
Value(" "),
"name",
), # Match "Dorm J Local Sud"
).all()
if self.q:

View file

@ -46,7 +46,10 @@ from os import walk, path
from django import forms
from django.forms import ModelForm, Form
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.contrib.auth.password_validation import validate_password, password_validators_help_text_html
from django.contrib.auth.password_validation import (
validate_password,
password_validators_help_text_html,
)
from django.core.validators import MinLengthValidator
from django.conf import settings
from django.utils import timezone
@ -60,7 +63,11 @@ from topologie.models import Port
from preferences.models import OptionalUser
from re2o.utils import remove_user_room
from re2o.base import get_input_formats_help_text
from re2o.mixins import FormRevMixin, AutocompleteMultipleModelMixin, AutocompleteModelMixin
from re2o.mixins import (
FormRevMixin,
AutocompleteMultipleModelMixin,
AutocompleteModelMixin,
)
from re2o.field_permissions import FieldPermissionFormMixin
from preferences.models import GeneralOption
@ -156,14 +163,10 @@ class ServiceUserAdminForm(FormRevMixin, forms.ModelForm):
"""
password1 = forms.CharField(
label=_("Password"),
widget=forms.PasswordInput,
max_length=255,
label=_("Password"), widget=forms.PasswordInput, max_length=255
)
password2 = forms.CharField(
label=_("Password confirmation"),
widget=forms.PasswordInput,
max_length=255,
label=_("Password confirmation"), widget=forms.PasswordInput, max_length=255
)
def __init__(self, *args, **kwargs):
@ -215,6 +218,7 @@ class PassForm(FormRevMixin, FieldPermissionFormMixin, forms.ModelForm):
DjangoForm : Inherit from basic django form
"""
selfpasswd = forms.CharField(
label=_("Current password"), max_length=255, widget=forms.PasswordInput
)
@ -222,12 +226,10 @@ class PassForm(FormRevMixin, FieldPermissionFormMixin, forms.ModelForm):
label=_("New password"),
max_length=255,
widget=forms.PasswordInput,
help_text=password_validators_help_text_html()
help_text=password_validators_help_text_html(),
)
passwd2 = forms.CharField(
label=_("New password confirmation"),
max_length=255,
widget=forms.PasswordInput,
label=_("New password confirmation"), max_length=255, widget=forms.PasswordInput
)
class Meta:
@ -296,9 +298,7 @@ class MassArchiveForm(forms.Form):
date = forms.DateTimeField(help_text="%d/%m/%y")
full_archive = forms.BooleanField(
label=_(
"Fully archive users? WARNING: CRITICAL OPERATION IF TRUE"
),
label=_("Fully archive users? WARNING: CRITICAL OPERATION IF TRUE"),
initial=False,
required=False,
)
@ -351,18 +351,14 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"room",
]
widgets = {
"school": AutocompleteModelMixin(
url="/users/school-autocomplete",
),
"school": AutocompleteModelMixin(url="/users/school-autocomplete"),
"room": AutocompleteModelMixin(
url="/topologie/room-autocomplete",
attrs = {
attrs={
"data-minimum-input-length": 3 # Only trigger autocompletion after 3 characters have been typed
}
},
),
"shell": AutocompleteModelMixin(
url="/users/shell-autocomplete",
)
"shell": AutocompleteModelMixin(url="/users/shell-autocomplete"),
}
force = forms.BooleanField(
@ -427,6 +423,7 @@ class AdherentCreationForm(AdherentForm):
Parameters:
DjangoForm : Inherit from basic django form
"""
# Champ pour choisir si un lien est envoyé par mail pour le mot de passe
init_password_by_mail_info = _(
"If this options is set, you will receive a link to set"
@ -439,9 +436,7 @@ class AdherentCreationForm(AdherentForm):
)
init_password_by_mail = forms.BooleanField(
help_text=init_password_by_mail_info,
required=False,
initial=True
help_text=init_password_by_mail_info, required=False, initial=True
)
init_password_by_mail.label = _("Send password reset link by email.")
@ -452,7 +447,7 @@ class AdherentCreationForm(AdherentForm):
label=_("Password"),
widget=forms.PasswordInput,
max_length=255,
help_text=password_validators_help_text_html()
help_text=password_validators_help_text_html(),
)
password2 = forms.CharField(
required=False,
@ -542,8 +537,12 @@ class AdherentCreationForm(AdherentForm):
# Save the provided password in hashed format
user = super(AdherentForm, self).save(commit=False)
is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation")
set_passwd = is_set_password_allowed and not self.cleaned_data.get("init_password_by_mail")
is_set_password_allowed = OptionalUser.get_cached_value(
"allow_set_password_during_user_creation"
)
set_passwd = is_set_password_allowed and not self.cleaned_data.get(
"init_password_by_mail"
)
if set_passwd:
user.set_password(self.cleaned_data["password1"])
@ -624,15 +623,9 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"mailing",
]
widgets = {
"school": AutocompleteModelMixin(
url="/users/school-autocomplete",
),
"room": AutocompleteModelMixin(
url="/topologie/room-autocomplete",
),
"shell": AutocompleteModelMixin(
url="/users/shell-autocomplete",
)
"school": AutocompleteModelMixin(url="/users/school-autocomplete"),
"room": AutocompleteModelMixin(url="/topologie/room-autocomplete"),
"shell": AutocompleteModelMixin(url="/users/shell-autocomplete"),
}
def clean_telephone(self):
@ -664,11 +657,11 @@ class ClubAdminandMembersForm(FormRevMixin, ModelForm):
fields = ["administrators", "members"]
widgets = {
"administrators": AutocompleteMultipleModelMixin(
url="/users/adherent-autocomplete",
url="/users/adherent-autocomplete"
),
"members": AutocompleteMultipleModelMixin(
url="/users/adherent-autocomplete",
)
url="/users/adherent-autocomplete"
),
}
def __init__(self, *args, **kwargs):
@ -1005,6 +998,7 @@ class InitialRegisterForm(forms.Form):
Parameters:
DjangoForm : Inherit from basic django form
"""
register_room = forms.BooleanField(required=False)
register_machine = forms.BooleanField(required=False)
@ -1085,8 +1079,8 @@ class ThemeForm(FormRevMixin, forms.Form):
theme = forms.ChoiceField(widget=forms.Select())
def __init__(self, *args, **kwargs):
_, _ ,themes = next(walk(path.join(settings.STATIC_ROOT, "css/themes")))
_, _, themes = next(walk(path.join(settings.STATIC_ROOT, "css/themes")))
if not themes:
themes = ["default.css"]
super(ThemeForm, self).__init__(*args, **kwargs)
self.fields['theme'].choices = [(theme, theme) for theme in themes]
self.fields["theme"].choices = [(theme, theme) for theme in themes]

View file

@ -31,22 +31,18 @@ Here are defined the autocomplete class based view.
"""
from __future__ import unicode_literals
from .models import (
User,
School,
Adherent,
Club,
ListShell,
)
from .models import User, School, Adherent, Club, ListShell
from re2o.views import AutocompleteViewMixin
from django.db.models import Q, Value, CharField
from django.db.models.functions import Concat
class SchoolAutocomplete(AutocompleteViewMixin):
obj_type = School
class UserAutocomplete(AutocompleteViewMixin):
obj_type = User
@ -54,8 +50,12 @@ class UserAutocomplete(AutocompleteViewMixin):
def filter_results(self):
# Comments explain what we try to match
self.query_set = self.query_set.annotate(
full_name=Concat("adherent__name", Value(" "), "surname"), # Match when the user searches "Toto Passoir"
full_name_reverse=Concat("surname", Value(" "), "adherent__name"), # Match when the user searches "Passoir Toto"
full_name=Concat(
"adherent__name", Value(" "), "surname"
), # Match when the user searches "Toto Passoir"
full_name_reverse=Concat(
"surname", Value(" "), "adherent__name"
), # Match when the user searches "Passoir Toto"
).all()
if self.q:
@ -65,6 +65,7 @@ class UserAutocomplete(AutocompleteViewMixin):
| Q(full_name_reverse__icontains=self.q)
)
class AdherentAutocomplete(AutocompleteViewMixin):
obj_type = Adherent
@ -72,8 +73,12 @@ class AdherentAutocomplete(AutocompleteViewMixin):
def filter_results(self):
# Comments explain what we try to match
self.query_set = self.query_set.annotate(
full_name=Concat("name", Value(" "), "surname"), # Match when the user searches "Toto Passoir"
full_name_reverse=Concat("surname", Value(" "), "name"), # Match when the user searches "Passoir Toto"
full_name=Concat(
"name", Value(" "), "surname"
), # Match when the user searches "Toto Passoir"
full_name_reverse=Concat(
"surname", Value(" "), "name"
), # Match when the user searches "Passoir Toto"
).all()
if self.q:
@ -83,9 +88,11 @@ class AdherentAutocomplete(AutocompleteViewMixin):
| Q(full_name_reverse__icontains=self.q)
)
class ClubAutocomplete(AutocompleteViewMixin):
obj_type = Club
class ShellAutocomplete(AutocompleteViewMixin):
obj_type = ListShell
query_filter = "shell__icontains"