mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-09-12 01:03:09 +00:00
Merge branch 'fixe_comment' into 'master'
Ajout du champ comment dans le ServiceUserForm See merge request federez/re2o!148
This commit is contained in:
commit
cae97a385d
2 changed files with 12 additions and 10 deletions
|
@ -422,12 +422,19 @@ class ServiceUserForm(FormRevMixin, ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = ServiceUser
|
||||
fields = ('pseudo', 'access_group')
|
||||
fields = ('pseudo', 'access_group','comment')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
super(ServiceUserForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
"""Changement du mot de passe"""
|
||||
user = super(ServiceUserForm, self).save(commit=False)
|
||||
if self.cleaned_data['password']:
|
||||
user.set_password(self.cleaned_data.get("password"))
|
||||
user.save()
|
||||
|
||||
|
||||
class EditServiceUserForm(ServiceUserForm):
|
||||
"""Formulaire d'edition de base d'un service user. Ne permet
|
||||
|
|
|
@ -300,12 +300,10 @@ def new_serviceuser(request):
|
|||
""" Vue de création d'un nouvel utilisateur service"""
|
||||
user = ServiceUserForm(request.POST or None)
|
||||
if user.is_valid():
|
||||
user_object = user.save(commit=False)
|
||||
user_object.set_password(user.cleaned_data['password'])
|
||||
user_object.save()
|
||||
user.save()
|
||||
messages.success(
|
||||
request,
|
||||
"L'utilisateur %s a été crée" % user_object.pseudo
|
||||
"L'utilisateur a été crée"
|
||||
)
|
||||
return redirect(reverse('users:index-serviceusers'))
|
||||
return form(
|
||||
|
@ -324,11 +322,8 @@ def edit_serviceuser(request, serviceuser, **_kwargs):
|
|||
instance=serviceuser
|
||||
)
|
||||
if serviceuser.is_valid():
|
||||
user_object = serviceuser.save(commit=False)
|
||||
if serviceuser.cleaned_data['password']:
|
||||
user_object.set_password(serviceuser.cleaned_data['password'])
|
||||
if serviceuser.changed_data:
|
||||
user_object.save()
|
||||
serviceuser.save()
|
||||
messages.success(request, "L'user a bien été modifié")
|
||||
return redirect(reverse('users:index-serviceusers'))
|
||||
return form(
|
||||
|
@ -344,7 +339,7 @@ def del_serviceuser(request, serviceuser, **_kwargs):
|
|||
"""Suppression d'un ou plusieurs serviceusers"""
|
||||
if request.method == "POST":
|
||||
serviceuser.delete()
|
||||
messages.success(request, "L'user a été détruite")
|
||||
messages.success(request, "L'user a été détruit")
|
||||
return redirect(reverse('users:index-serviceusers'))
|
||||
return form(
|
||||
{'objet': serviceuser, 'objet_name': 'serviceuser'},
|
||||
|
|
Loading…
Reference in a new issue