mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-08-30 16:41:17 +02:00
Better phone input (no invalid number)
This commit is contained in:
@@ -10,6 +10,7 @@ from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import transaction
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from phonenumber_field.formfields import PhoneNumberField
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from note.models import NoteSpecial, Alias
|
||||
@@ -45,6 +46,11 @@ class ProfileForm(forms.ModelForm):
|
||||
A form for the extras field provided by the :model:`member.Profile` model.
|
||||
"""
|
||||
# Remove widget=forms.HiddenInput() if you want to use report frequency.
|
||||
phone_number = PhoneNumberField(
|
||||
widget=forms.TextInput(attrs={"type": "tel", "class": "form-control"}),
|
||||
required=False
|
||||
)
|
||||
|
||||
report_frequency = forms.IntegerField(required=False, initial=0, label=_("Report frequency"))
|
||||
|
||||
last_report = forms.DateTimeField(required=False, disabled=True, label=_("Last report date"))
|
||||
@@ -72,7 +78,12 @@ class ProfileForm(forms.ModelForm):
|
||||
if not self.instance.section or (("department" in self.changed_data
|
||||
or "promotion" in self.changed_data) and "section" not in self.changed_data):
|
||||
self.instance.section = self.instance.section_generated
|
||||
return super().save(commit)
|
||||
instance = super().save(commit=False)
|
||||
if instance.phone_number:
|
||||
instance.phone_number = instance.phone_number.as_e164
|
||||
if commit:
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
class Meta:
|
||||
model = Profile
|
||||
|
Reference in New Issue
Block a user