Change le formulaire de account_update

On fait un formulaire d'info non-éditable pour pas que les gens mettent des noms troll
This commit is contained in:
Ludovic Stephan 2019-06-03 19:34:41 +02:00 committed by Ludovic Stephan
parent 4598abc721
commit baa3826a42
3 changed files with 12 additions and 25 deletions

View file

@ -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):

View file

@ -30,8 +30,7 @@
<form action="" method="post" class="form-horizontal">
{% 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 %}

View file

@ -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,