forked from DGNum/gestioCOF
Merge branch 'Kerl/changeemail' into 'master'
Les membres peuvent changer leur adresse email See merge request cof-geek/gestioCOF!305
This commit is contained in:
commit
92ca838601
4 changed files with 44 additions and 49 deletions
|
@ -170,25 +170,16 @@ class EventStatusFilterForm(forms.Form):
|
||||||
yield ("has_paid", None, value)
|
yield ("has_paid", None, value)
|
||||||
|
|
||||||
|
|
||||||
class UserProfileForm(forms.ModelForm):
|
class UserForm(forms.ModelForm):
|
||||||
first_name = forms.CharField(label=_('Prénom'), max_length=30)
|
class Meta:
|
||||||
last_name = forms.CharField(label=_('Nom'), max_length=30)
|
model = User
|
||||||
|
fields = ["first_name", "last_name", "email"]
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
|
||||||
super().__init__(*args, **kw)
|
|
||||||
self.fields['first_name'].initial = self.instance.user.first_name
|
|
||||||
self.fields['last_name'].initial = self.instance.user.last_name
|
|
||||||
|
|
||||||
def save(self, *args, **kw):
|
|
||||||
super().save(*args, **kw)
|
|
||||||
self.instance.user.first_name = self.cleaned_data.get('first_name')
|
|
||||||
self.instance.user.last_name = self.cleaned_data.get('last_name')
|
|
||||||
self.instance.user.save()
|
|
||||||
|
|
||||||
|
class ProfileForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CofProfile
|
model = CofProfile
|
||||||
fields = ["first_name", "last_name", "phone", "mailing_cof",
|
fields = ["phone", "mailing_cof", "mailing_bda", "mailing_bda_revente"]
|
||||||
"mailing_bda", "mailing_bda_revente"]
|
|
||||||
|
|
||||||
|
|
||||||
class RegistrationUserForm(forms.ModelForm):
|
class RegistrationUserForm(forms.ModelForm):
|
||||||
|
@ -252,6 +243,7 @@ class RegistrationProfileForm(forms.ModelForm):
|
||||||
"departement", "is_cof", "type_cotiz", "mailing_cof",
|
"departement", "is_cof", "type_cotiz", "mailing_cof",
|
||||||
"mailing_bda", "mailing_bda_revente", "comments")
|
"mailing_bda", "mailing_bda_revente", "comments")
|
||||||
|
|
||||||
|
|
||||||
STATUS_CHOICES = (('no', 'Non'),
|
STATUS_CHOICES = (('no', 'Non'),
|
||||||
('wait', 'Oui mais attente paiement'),
|
('wait', 'Oui mais attente paiement'),
|
||||||
('paid', 'Oui payé'),)
|
('paid', 'Oui payé'),)
|
||||||
|
|
|
@ -5,23 +5,20 @@
|
||||||
|
|
||||||
{% block realcontent %}
|
{% block realcontent %}
|
||||||
<h2>Modifier mon profil</h2>
|
<h2>Modifier mon profil</h2>
|
||||||
<form id="profile form-horizontal" method="post" action="{% url 'profile' %}">
|
<form id="profile form-horizontal" method="post" action="">
|
||||||
<div class="row" style="margin: 0 15%;">
|
<div class="row" style="margin: 0 15%;">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<fieldset"center-block">
|
{{ user_form | bootstrap }}
|
||||||
{% for field in form %}
|
{{ profile_form | bootstrap }}
|
||||||
{{ field | bootstrap }}
|
|
||||||
{% endfor %}
|
|
||||||
</fieldset>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if user.profile.comments %}
|
{% if user.profile.comments %}
|
||||||
<div class="row" style="margin: 0 15%;">
|
<div class="row" style="margin: 0 15%;">
|
||||||
<h4>Commentaires</h4>
|
<h4>Commentaires</h4>
|
||||||
<p>
|
<p>{{ user.profile.comments }}</p>
|
||||||
{{ user.profile.comments }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<input type="submit" class="btn btn-primary pull-right" value="Enregistrer" />
|
<input type="submit" class="btn btn-primary pull-right" value="Enregistrer" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -46,9 +46,9 @@ class ProfileViewTests(ViewTestCaseMixin, TestCase):
|
||||||
u = self.users['member']
|
u = self.users['member']
|
||||||
|
|
||||||
r = self.client.post(self.url, {
|
r = self.client.post(self.url, {
|
||||||
'first_name': 'First',
|
'u-first_name': 'First',
|
||||||
'last_name': 'Last',
|
'u-last_name': 'Last',
|
||||||
'phone': '',
|
'p-phone': '',
|
||||||
# 'mailing_cof': '1',
|
# 'mailing_cof': '1',
|
||||||
# 'mailing_bda': '1',
|
# 'mailing_bda': '1',
|
||||||
# 'mailing_bda_revente': '1',
|
# 'mailing_bda_revente': '1',
|
||||||
|
|
|
@ -32,7 +32,8 @@ from gestioncof.models import EventCommentField, EventCommentValue, \
|
||||||
from gestioncof.models import CofProfile, Club
|
from gestioncof.models import CofProfile, Club
|
||||||
from gestioncof.decorators import buro_required, cof_required
|
from gestioncof.decorators import buro_required, cof_required
|
||||||
from gestioncof.forms import (
|
from gestioncof.forms import (
|
||||||
UserProfileForm, EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm,
|
UserForm, ProfileForm,
|
||||||
|
EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm,
|
||||||
RegistrationUserForm, RegistrationProfileForm, EventForm, CalendarForm,
|
RegistrationUserForm, RegistrationProfileForm, EventForm, CalendarForm,
|
||||||
EventFormset, RegistrationPassUserForm, ClubsForm, GestioncofConfigForm
|
EventFormset, RegistrationPassUserForm, ClubsForm, GestioncofConfigForm
|
||||||
)
|
)
|
||||||
|
@ -334,15 +335,20 @@ def survey_status(request, survey_id):
|
||||||
|
|
||||||
@cof_required
|
@cof_required
|
||||||
def profile(request):
|
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")
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = UserProfileForm(request.POST, instance=request.user.profile)
|
if user_form.is_valid() and profile_form.is_valid():
|
||||||
if form.is_valid():
|
user_form.save()
|
||||||
form.save()
|
profile_form.save()
|
||||||
messages.success(request,
|
messages.success(
|
||||||
"Votre profil a été mis à jour avec succès !")
|
request,
|
||||||
else:
|
_("Votre profil a été mis à jour avec succès !")
|
||||||
form = UserProfileForm(instance=request.user.profile)
|
)
|
||||||
return render(request, "gestioncof/profile.html", {"form": form})
|
context = {"user_form": user_form, "profile_form": profile_form}
|
||||||
|
return render(request, "gestioncof/profile.html", context)
|
||||||
|
|
||||||
|
|
||||||
def registration_set_ro_fields(user_form, profile_form):
|
def registration_set_ro_fields(user_form, profile_form):
|
||||||
|
|
Loading…
Reference in a new issue