From 898a354c2d419de3a9887a8eb2ed9b438f296b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 5 Aug 2018 18:11:10 +0200 Subject: [PATCH 1/5] Members can change their registration email --- gestioncof/forms.py | 22 ++++------- gestioncof/templates/gestioncof/profile.html | 41 +++++++++----------- gestioncof/tests/test_views.py | 6 +-- gestioncof/views.py | 24 +++++++----- 4 files changed, 44 insertions(+), 49 deletions(-) diff --git a/gestioncof/forms.py b/gestioncof/forms.py index 4a9087fd..1fcc6ea6 100644 --- a/gestioncof/forms.py +++ b/gestioncof/forms.py @@ -170,25 +170,16 @@ class EventStatusFilterForm(forms.Form): yield ("has_paid", None, value) -class UserProfileForm(forms.ModelForm): - first_name = forms.CharField(label=_('Prénom'), max_length=30) - last_name = forms.CharField(label=_('Nom'), max_length=30) +class UserForm(forms.ModelForm): + class Meta: + 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: model = CofProfile - fields = ["first_name", "last_name", "phone", "mailing_cof", - "mailing_bda", "mailing_bda_revente"] + fields = ["phone", "mailing_cof", "mailing_bda", "mailing_bda_revente"] class RegistrationUserForm(forms.ModelForm): @@ -252,6 +243,7 @@ class RegistrationProfileForm(forms.ModelForm): "departement", "is_cof", "type_cotiz", "mailing_cof", "mailing_bda", "mailing_bda_revente", "comments") + STATUS_CHOICES = (('no', 'Non'), ('wait', 'Oui mais attente paiement'), ('paid', 'Oui payé'),) diff --git a/gestioncof/templates/gestioncof/profile.html b/gestioncof/templates/gestioncof/profile.html index 5decdfb3..9d418ef6 100644 --- a/gestioncof/templates/gestioncof/profile.html +++ b/gestioncof/templates/gestioncof/profile.html @@ -4,26 +4,23 @@ {% block page_size %}col-sm-8{%endblock%} {% block realcontent %} -

Modifier mon profil

-
-
- {% csrf_token %} - - {% for field in form %} - {{ field | bootstrap }} - {% endfor %} - -
- {% if user.profile.comments %} -
-

Commentaires

-

- {{ user.profile.comments }} -

-
- {% endif %} -
- -
-
+

Modifier mon profil

+
+
+ {% csrf_token %} + {{ user_form | bootstrap }} + {{ profile_form | bootstrap }} +
+ + {% if user.profile.comments %} +
+

Commentaires

+

{{ user.profile.comments }}

+
+ {% endif %} + +
+ +
+
{% endblock %} diff --git a/gestioncof/tests/test_views.py b/gestioncof/tests/test_views.py index 47139327..1067e586 100644 --- a/gestioncof/tests/test_views.py +++ b/gestioncof/tests/test_views.py @@ -46,9 +46,9 @@ class ProfileViewTests(ViewTestCaseMixin, TestCase): u = self.users['member'] r = self.client.post(self.url, { - 'first_name': 'First', - 'last_name': 'Last', - 'phone': '', + 'u-first_name': 'First', + 'u-last_name': 'Last', + 'p-phone': '', # 'mailing_cof': '1', # 'mailing_bda': '1', # 'mailing_bda_revente': '1', diff --git a/gestioncof/views.py b/gestioncof/views.py index 6126eb10..64fe89a0 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -32,7 +32,8 @@ from gestioncof.models import EventCommentField, EventCommentValue, \ from gestioncof.models import CofProfile, Club from gestioncof.decorators import buro_required, cof_required from gestioncof.forms import ( - UserProfileForm, EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm, + UserForm, ProfileForm, + EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm, RegistrationUserForm, RegistrationProfileForm, EventForm, CalendarForm, EventFormset, RegistrationPassUserForm, ClubsForm, GestioncofConfigForm ) @@ -334,15 +335,20 @@ def survey_status(request, survey_id): @cof_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") if request.method == "POST": - form = UserProfileForm(request.POST, instance=request.user.profile) - if form.is_valid(): - form.save() - messages.success(request, - "Votre profil a été mis à jour avec succès !") - else: - form = UserProfileForm(instance=request.user.profile) - return render(request, "gestioncof/profile.html", {"form": form}) + if user_form.is_valid() and profile_form.is_valid(): + user_form.save() + profile_form.save() + messages.success( + request, + _("Votre profil a été mis à jour avec succès !") + ) + 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): From 66184fbee649a3eefc7ab6673f05b5814ee74721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 5 Aug 2018 18:34:05 +0200 Subject: [PATCH 2/5] CI: set python version to 3.5 --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 19bcc736..e0ced08d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,5 @@ +image: "python:3.5" + services: - postgres:latest - redis:latest @@ -34,6 +36,7 @@ before_script: # Remove the old test database if it has not been done yet - psql --username=$POSTGRES_USER --host=$DBHOST -c "DROP DATABASE IF EXISTS test_$POSTGRES_DB" - pip install --upgrade --cache-dir vendor/pip -t vendor/python -r requirements.txt + - python --version test: stage: test From 91393dcea7caf4da586a66390c55ae88daed3272 Mon Sep 17 00:00:00 2001 From: Theo Delemazure Date: Sun, 2 Sep 2018 20:34:09 +0200 Subject: [PATCH 3/5] Update models.py --- gestioncof/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gestioncof/models.py b/gestioncof/models.py index 0d816155..8a5b6a53 100644 --- a/gestioncof/models.py +++ b/gestioncof/models.py @@ -72,6 +72,7 @@ class CofProfile(models.Model): TYPE_COTIZ_CHOICES)) mailing_cof = models.BooleanField("Recevoir les mails COF", default=False) mailing_bda = models.BooleanField("Recevoir les mails BdA", default=False) + mailing_unernestaparis = models.BooleanField("Recevoir les mails unErnestAParis", default=False) mailing_bda_revente = models.BooleanField( "Recevoir les mails de revente de places BdA", default=False) comments = models.TextField( From 73cf39baa81ae39c4f70192e2a6ac160c4e31fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 2 Sep 2018 23:25:58 +0200 Subject: [PATCH 4/5] missing migration --- .../0014_cofprofile_mailing_unernestaparis.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 gestioncof/migrations/0014_cofprofile_mailing_unernestaparis.py diff --git a/gestioncof/migrations/0014_cofprofile_mailing_unernestaparis.py b/gestioncof/migrations/0014_cofprofile_mailing_unernestaparis.py new file mode 100644 index 00000000..1d842329 --- /dev/null +++ b/gestioncof/migrations/0014_cofprofile_mailing_unernestaparis.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.15 on 2018-09-02 21:13 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gestioncof', '0013_pei'), + ] + + operations = [ + migrations.AddField( + model_name='cofprofile', + name='mailing_unernestaparis', + field=models.BooleanField(default=False, verbose_name='Recevoir les mails unErnestAParis'), + ), + ] From 327ef210dbc0e74f2b6c1968cebcee2c08c1beb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 2 Sep 2018 23:26:18 +0200 Subject: [PATCH 5/5] make unernestaparis visible in forms --- gestioncof/forms.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gestioncof/forms.py b/gestioncof/forms.py index 1fcc6ea6..4ad9b058 100644 --- a/gestioncof/forms.py +++ b/gestioncof/forms.py @@ -179,7 +179,13 @@ class UserForm(forms.ModelForm): class ProfileForm(forms.ModelForm): class Meta: model = CofProfile - fields = ["phone", "mailing_cof", "mailing_bda", "mailing_bda_revente"] + fields = [ + "phone", + "mailing_cof", + "mailing_bda", + "mailing_bda_revente", + "mailing_unernestaparis" + ] class RegistrationUserForm(forms.ModelForm): @@ -223,6 +229,7 @@ class RegistrationProfileForm(forms.ModelForm): self.fields['mailing_cof'].initial = True self.fields['mailing_bda'].initial = True self.fields['mailing_bda_revente'].initial = True + self.fields['mailing_unernestaparis'].initial = True self.fields.keyOrder = [ 'login_clipper', @@ -234,14 +241,16 @@ class RegistrationProfileForm(forms.ModelForm): 'mailing_cof', 'mailing_bda', 'mailing_bda_revente', + "mailing_unernestaparis", 'comments' - ] + ] class Meta: model = CofProfile fields = ("login_clipper", "phone", "occupation", "departement", "is_cof", "type_cotiz", "mailing_cof", - "mailing_bda", "mailing_bda_revente", "comments") + "mailing_bda", "mailing_bda_revente", + "mailing_unernestaparis", "comments") STATUS_CHOICES = (('no', 'Non'),