mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 03:43:12 +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:
|
class Meta:
|
||||||
model = ServiceUser
|
model = ServiceUser
|
||||||
fields = ('pseudo', 'access_group')
|
fields = ('pseudo', 'access_group','comment')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(ServiceUserForm, self).__init__(*args, prefix=prefix, **kwargs)
|
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):
|
class EditServiceUserForm(ServiceUserForm):
|
||||||
"""Formulaire d'edition de base d'un service user. Ne permet
|
"""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"""
|
""" Vue de création d'un nouvel utilisateur service"""
|
||||||
user = ServiceUserForm(request.POST or None)
|
user = ServiceUserForm(request.POST or None)
|
||||||
if user.is_valid():
|
if user.is_valid():
|
||||||
user_object = user.save(commit=False)
|
user.save()
|
||||||
user_object.set_password(user.cleaned_data['password'])
|
|
||||||
user_object.save()
|
|
||||||
messages.success(
|
messages.success(
|
||||||
request,
|
request,
|
||||||
"L'utilisateur %s a été crée" % user_object.pseudo
|
"L'utilisateur a été crée"
|
||||||
)
|
)
|
||||||
return redirect(reverse('users:index-serviceusers'))
|
return redirect(reverse('users:index-serviceusers'))
|
||||||
return form(
|
return form(
|
||||||
|
@ -324,11 +322,8 @@ def edit_serviceuser(request, serviceuser, **_kwargs):
|
||||||
instance=serviceuser
|
instance=serviceuser
|
||||||
)
|
)
|
||||||
if serviceuser.is_valid():
|
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:
|
if serviceuser.changed_data:
|
||||||
user_object.save()
|
serviceuser.save()
|
||||||
messages.success(request, "L'user a bien été modifié")
|
messages.success(request, "L'user a bien été modifié")
|
||||||
return redirect(reverse('users:index-serviceusers'))
|
return redirect(reverse('users:index-serviceusers'))
|
||||||
return form(
|
return form(
|
||||||
|
@ -344,7 +339,7 @@ def del_serviceuser(request, serviceuser, **_kwargs):
|
||||||
"""Suppression d'un ou plusieurs serviceusers"""
|
"""Suppression d'un ou plusieurs serviceusers"""
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
serviceuser.delete()
|
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 redirect(reverse('users:index-serviceusers'))
|
||||||
return form(
|
return form(
|
||||||
{'objet': serviceuser, 'objet_name': 'serviceuser'},
|
{'objet': serviceuser, 'objet_name': 'serviceuser'},
|
||||||
|
|
Loading…
Reference in a new issue