From baa3826a426d8886d4c60c4de1db174064bb00d6 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Jun 2019 19:34:41 +0200 Subject: [PATCH 1/6] Change le formulaire de `account_update` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On fait un formulaire d'info non-éditable pour pas que les gens mettent des noms troll --- kfet/forms.py | 7 +++++-- kfet/templates/kfet/account_update.html | 3 +-- kfet/views.py | 27 ++++++------------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/kfet/forms.py b/kfet/forms.py index e314d80c..cb775308 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -136,9 +136,12 @@ class UserRestrictForm(UserForm): fields = ["first_name", "last_name"] -class UserRestrictTeamForm(UserForm): +class UserInfoForm(UserForm): + first_name = forms.CharField(label="Prénom", disabled=True) + last_name = forms.CharField(label="Nom de famille", disabled=True) + class Meta(UserForm.Meta): - fields = ["first_name", "last_name", "email"] + fields = ["first_name", "last_name"] class AccountNegativeForm(forms.ModelForm): diff --git a/kfet/templates/kfet/account_update.html b/kfet/templates/kfet/account_update.html index 2fa1cec2..36b3d75d 100644 --- a/kfet/templates/kfet/account_update.html +++ b/kfet/templates/kfet/account_update.html @@ -30,8 +30,7 @@
{% csrf_token %} - {% include 'kfet/form_snippet.html' with form=user_form %} - {% include 'kfet/form_snippet.html' with form=cof_form %} + {% include 'kfet/form_snippet.html' with form=user_info_form %} {% include 'kfet/form_snippet.html' with form=account_form %} {% include 'kfet/form_snippet.html' with form=group_form %} {% include 'kfet/form_snippet.html' with form=pwd_form %} diff --git a/kfet/views.py b/kfet/views.py index ff71f1e0..a5eeba68 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -43,7 +43,6 @@ from kfet.forms import ( CheckoutStatementCreateForm, CheckoutStatementUpdateForm, CofForm, - CofRestrictForm, FilterHistoryForm, InventoryArticleForm, KFetConfigForm, @@ -56,8 +55,8 @@ from kfet.forms import ( TransferFormSet, UserForm, UserGroupForm, + UserInfoForm, UserRestrictForm, - UserRestrictTeamForm, ) from kfet.models import ( Account, @@ -331,10 +330,9 @@ def account_update(request, trigramme): raise PermissionDenied if request.user.has_perm("kfet.is_team"): - user_form = UserRestrictTeamForm(instance=account.user) + user_info_form = UserInfoForm(instance=account.user) group_form = UserGroupForm(instance=account.user) account_form = AccountForm(instance=account) - cof_form = CofRestrictForm(instance=account.cofprofile) pwd_form = AccountPwdForm() if account.balance < 0 and not hasattr(account, "negative"): AccountNegative.objects.create(account=account, start=timezone.now()) @@ -344,9 +342,8 @@ def account_update(request, trigramme): else: negative_form = None else: - user_form = UserRestrictForm(instance=account.user) + user_info_form = None account_form = AccountRestrictForm(instance=account) - cof_form = None group_form = None negative_form = None pwd_form = None @@ -358,8 +355,6 @@ def account_update(request, trigramme): if request.user.has_perm("kfet.is_team"): account_form = AccountForm(request.POST, instance=account) - cof_form = CofRestrictForm(request.POST, instance=account.cofprofile) - user_form = UserRestrictTeamForm(request.POST, instance=account.user) group_form = UserGroupForm(request.POST, instance=account.user) pwd_form = AccountPwdForm(request.POST) if hasattr(account, "negative"): @@ -367,20 +362,11 @@ def account_update(request, trigramme): request.POST, instance=account.negative ) - if ( - request.user.has_perm("kfet.change_account") - and account_form.is_valid() - and cof_form.is_valid() - and user_form.is_valid() - ): + if request.user.has_perm("kfet.change_account") and account_form.is_valid(): missing_perm = False - data = {} - # Fill data for Account.save() - put_cleaned_data_in_dict(data, user_form) - put_cleaned_data_in_dict(data, cof_form) # Updating - account_form.save(data=data) + account_form.save(data={}) # Checking perm to update password if ( @@ -459,10 +445,9 @@ def account_update(request, trigramme): request, "kfet/account_update.html", { + "user_info_form": user_info_form, "account": account, "account_form": account_form, - "cof_form": cof_form, - "user_form": user_form, "group_form": group_form, "negative_form": negative_form, "pwd_form": pwd_form, From fb5629327374e5e1b7260a936e1e158e31e12785 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Jun 2019 19:35:15 +0200 Subject: [PATCH 2/6] =?UTF-8?q?Supprime=20un=20formulaire=20inutilis=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/forms.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/kfet/forms.py b/kfet/forms.py index cb775308..b8d670c1 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -119,11 +119,6 @@ class CofForm(forms.ModelForm): fields = ["login_clipper", "is_cof", "departement"] -class CofRestrictForm(CofForm): - class Meta(CofForm.Meta): - fields = ["departement"] - - class UserForm(forms.ModelForm): class Meta: model = User From 8d30c5c7e5da567cca2bdc514251f2345bcff0fd Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Jun 2019 20:19:58 +0200 Subject: [PATCH 3/6] Fix tests --- kfet/tests/test_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/tests/test_views.py b/kfet/tests/test_views.py index ec6565d7..cb6c9a0c 100644 --- a/kfet/tests/test_views.py +++ b/kfet/tests/test_views.py @@ -318,7 +318,7 @@ class AccountUpdateViewTests(ViewTestCaseMixin, TestCase): self.assertInstanceExpected( self.accounts["user1"], - {"first_name": "The first", "last_name": "The last", "trigramme": "051"}, + {"first_name": "first", "last_name": "last", "trigramme": "051"}, ) def test_post_ok_self(self): From fc8c8fdf29c5c45294e632eca86e73417aaa49c7 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Jun 2019 20:34:25 +0200 Subject: [PATCH 4/6] =?UTF-8?q?Montre=20les=20infos=20=C3=A0=20tout=20le?= =?UTF-8?q?=20monde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index a5eeba68..b700e713 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -329,8 +329,9 @@ def account_update(request, trigramme): if not request.user.has_perm("kfet.is_team") and request.user != account.user: raise PermissionDenied + user_info_form = UserInfoForm(instance=account.user) + if request.user.has_perm("kfet.is_team"): - user_info_form = UserInfoForm(instance=account.user) group_form = UserGroupForm(instance=account.user) account_form = AccountForm(instance=account) pwd_form = AccountPwdForm() @@ -342,7 +343,6 @@ def account_update(request, trigramme): else: negative_form = None else: - user_info_form = None account_form = AccountRestrictForm(instance=account) group_form = None negative_form = None From 96430d852cd6910a0e13a30bae8fc8ff901e3316 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Jun 2019 20:40:37 +0200 Subject: [PATCH 5/6] Do not repeat default argument --- kfet/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/views.py b/kfet/views.py index b700e713..4c8c6f47 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -366,7 +366,7 @@ def account_update(request, trigramme): missing_perm = False # Updating - account_form.save(data={}) + account_form.save() # Checking perm to update password if ( From bf372a1ce2ad81211753004b1b7629ce71e804e8 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 17 Jun 2019 22:03:11 +0200 Subject: [PATCH 6/6] CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 66a06dc0..af129af3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +- On ne peut plus modifier des comptes COF depuis l'interface K-Fêt - Le champ de paiement BdA se fait au niveau des attributions - On peut supprimer des comptes et des articles K-Fêt - Passage à Django2