diff --git a/apps/member/forms.py b/apps/member/forms.py index c4940bf6..8735dc8e 100644 --- a/apps/member/forms.py +++ b/apps/member/forms.py @@ -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 diff --git a/apps/member/templates/member/profile_update.html b/apps/member/templates/member/profile_update.html index 2f018381..e0975c22 100644 --- a/apps/member/templates/member/profile_update.html +++ b/apps/member/templates/member/profile_update.html @@ -10,7 +10,7 @@ SPDX-License-Identifier: GPL-3.0-or-later {{ title }}