Make profile editable for non-COF user

Non-COF users can now edit their own profile
Contrary to COF users they cannot change their mailing list settings
This commit is contained in:
Martin Pépin 2019-10-06 00:01:41 +02:00
parent 0814cfe1ef
commit 41256154ad
No known key found for this signature in database
GPG key ID: E7520278B1774448
2 changed files with 10 additions and 2 deletions

View file

@ -214,6 +214,12 @@ class UserForm(forms.ModelForm):
fields = ["first_name", "last_name", "email"]
class PhoneForm(forms.ModelForm):
class Meta:
model = CofProfile
fields = ["phone"]
class ProfileForm(forms.ModelForm):
class Meta:
model = CofProfile

View file

@ -33,6 +33,7 @@ from gestioncof.forms import (
EventStatusFilterForm,
ExteAuthenticationForm,
GestioncofConfigForm,
PhoneForm,
ProfileForm,
RegistrationPassUserForm,
RegistrationProfileForm,
@ -355,12 +356,13 @@ def survey_status(request, survey_id):
)
@cof_required
@login_required
def profile(request):
user = request.user
data = request.POST if request.method == "POST" else None
user_form = UserForm(data=data, instance=user, prefix="u")
profile_form = ProfileForm(data=data, instance=user.profile, prefix="p")
profile_form_klass = ProfileForm if user.profile.is_cof else PhoneForm
profile_form = profile_form_klass(data=data, instance=user.profile, prefix="p")
if request.method == "POST":
if user_form.is_valid() and profile_form.is_valid():
user_form.save()