diff --git a/users/forms.py b/users/forms.py index 7af2fc7..6c7d454 100644 --- a/users/forms.py +++ b/users/forms.py @@ -89,15 +89,29 @@ class ProfileForm(Validation): } class UserForm(Validation): - password = forms.CharField(label=_('Password'), widget = forms.PasswordInput, required = False) - password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput, required = False) - is_edit = False + def __init__(self, *args, **kwargs): + is_update = kwargs.pop('is_edit', False) + + super(UserForm, self).__init__(*args, **kwargs) + + self.is_edit = is_update + + if self.is_edit: + del self.fields['password'] + del self.fields['password2'] + + if not is_edit: + password = forms.CharField(label=_('Password'), widget = forms.PasswordInput, required = False) + password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput, required = False) + + def save(self, commit=True): super(UserForm, self).save(commit=False) - self.instance.set_password(self.cleaned_data['password']) + if not self.is_edit: + self.instance.set_password(self.cleaned_data['password']) self.instance.save() diff --git a/users/templates/users/_form.html b/users/templates/users/_form.html new file mode 100644 index 0000000..6b1aad4 --- /dev/null +++ b/users/templates/users/_form.html @@ -0,0 +1,62 @@ +{% load static i18n %} +{% load widget_tweaks %} + +
\ No newline at end of file diff --git a/users/templates/users/create.html b/users/templates/users/create.html index 5c9dec7..4d40956 100644 --- a/users/templates/users/create.html +++ b/users/templates/users/create.html @@ -1,8 +1,5 @@ {% extends 'users/list.html' %} -{% load static i18n %} -{% load widget_tweaks %} - {% load django_bootstrap_breadcrumbs %} {% block breadcrumbs %} @@ -14,65 +11,7 @@