2015-01-24 16:15:42 +01:00
|
|
|
"""
|
|
|
|
This module defines operating system user related forms.
|
|
|
|
|
|
|
|
"""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django import forms
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
from crispy_forms.helper import FormHelper
|
|
|
|
from crispy_forms.layout import Submit
|
|
|
|
|
2015-01-25 12:02:31 +01:00
|
|
|
from gvawebcore.forms import PasswordModelFormMixin
|
2015-01-24 16:15:42 +01:00
|
|
|
|
2015-01-25 12:02:31 +01:00
|
|
|
from .models import User
|
2015-01-24 16:15:42 +01:00
|
|
|
|
|
|
|
|
2015-01-25 12:02:31 +01:00
|
|
|
class ChangeOsUserPasswordForm(PasswordModelFormMixin, forms.ModelForm):
|
2015-01-24 16:15:42 +01:00
|
|
|
"""
|
|
|
|
A form for setting an OS user's password.
|
|
|
|
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = []
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.helper = FormHelper()
|
|
|
|
super(ChangeOsUserPasswordForm, self).__init__(*args, **kwargs)
|
|
|
|
self.helper.form_action = reverse(
|
|
|
|
'set_osuser_password', kwargs={'slug': self.instance.username})
|
|
|
|
self.helper.add_input(Submit('submit', _('Set password')))
|
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
"""
|
|
|
|
Save the provided password in hashed format.
|
|
|
|
|
|
|
|
:param boolean commit: whether to save the created user
|
|
|
|
:return: user instance
|
|
|
|
:rtype: :py:class:`osusers.models.User`
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.instance.set_password(self.cleaned_data['password1'])
|
|
|
|
return super(ChangeOsUserPasswordForm, self).save(commit=commit)
|