From 7b4999305a50facacf03e494da27071539d9b401 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Tue, 28 Apr 2015 14:38:04 +0200 Subject: [PATCH] user credentials and edit views(#7065) --- uauth/organization/forms.py | 9 ++++++ uauth/organization/tables.py | 2 +- .../templates/organization/edit_user.html | 18 +++++++++++ .../templates/organization/user.html | 9 ++++++ .../templates/organization/view_user.html | 15 +++++++++ uauth/organization/urls.py | 2 ++ uauth/organization/views.py | 31 +++++++++++++++++-- uauth/static/css/style.css | 15 +++++++++ 8 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 uauth/organization/templates/organization/edit_user.html create mode 100644 uauth/organization/templates/organization/user.html create mode 100644 uauth/organization/templates/organization/view_user.html diff --git a/uauth/organization/forms.py b/uauth/organization/forms.py index 661283e..90c13e2 100644 --- a/uauth/organization/forms.py +++ b/uauth/organization/forms.py @@ -14,6 +14,15 @@ class LocalAccountForm(forms.ModelForm): 'password': forms.PasswordInput } + def save(self): + # save previous password + old_password = self.initial.get('password') + obj = super(LocalAccountForm, self).save(commit=False) + if not self.cleaned_data.get('password'): + obj.password = old_password + obj.save() + return obj + class LocalAccountCreateForm(LocalAccountForm): accounts_number = forms.IntegerField(_('Number of accounts to create'), required=False) diff --git a/uauth/organization/tables.py b/uauth/organization/tables.py index bcd03ab..611e41c 100644 --- a/uauth/organization/tables.py +++ b/uauth/organization/tables.py @@ -6,7 +6,7 @@ from .models import LocalAccount class AccountTable(tables.Table): username = tables.TemplateColumn( - '{{ record.username }}', + '{{ record.username }}', verbose_name=_('Username')) class Meta: diff --git a/uauth/organization/templates/organization/edit_user.html b/uauth/organization/templates/organization/edit_user.html new file mode 100644 index 0000000..6e4e264 --- /dev/null +++ b/uauth/organization/templates/organization/edit_user.html @@ -0,0 +1,18 @@ +{% extends "organization/base.html" %} +{% load i18n %} + +{% block content %} +
+ {% csrf_token %} + + {{ form.as_table }} +
+
+ + +
+ +
+{% endblock %} diff --git a/uauth/organization/templates/organization/user.html b/uauth/organization/templates/organization/user.html new file mode 100644 index 0000000..465fd27 --- /dev/null +++ b/uauth/organization/templates/organization/user.html @@ -0,0 +1,9 @@ +{% load i18n %} + +
+

{% trans "Login" %} {{ user.username }} {% if user.get_fullname %}({{ user.get_fullname }}){% endif %}

+

{% trans "Password:" %} {{ user.password }}

+

{% trans "Expiring:" %} {% if user.expiration_date %}{{ user.expiration_date|date:"DATETIME_FORMAT" }}{% else %}{% trans "never" %}{% endif %}

+

{% trans "Description" %}

+

{{ user.description }}

+
diff --git a/uauth/organization/templates/organization/view_user.html b/uauth/organization/templates/organization/view_user.html new file mode 100644 index 0000000..31dd32f --- /dev/null +++ b/uauth/organization/templates/organization/view_user.html @@ -0,0 +1,15 @@ +{% extends "organization/base.html" %} +{% load i18n %} + +{% block page-title %} +{% trans 'User details' %} +{% endblock %} + +{% block appbar %} +

{% trans "User details" %}

+{% endblock %} + +{% block content %} +{% include "organization/user.html" with user=object %} +{% endblock %} + diff --git a/uauth/organization/urls.py b/uauth/organization/urls.py index ed4d1d8..9697a1f 100644 --- a/uauth/organization/urls.py +++ b/uauth/organization/urls.py @@ -6,4 +6,6 @@ urlpatterns = patterns('', url(r'^$', manage, name='manage'), url(r'^users/?$', users, name='manage-users'), url(r'^users/create$', create_users, name='create-users'), + url(r'^users/(?P[\w]+)/$', view_user, name='view-user'), + url(r'^users/(?P[\w]+)/edit$', edit_user, name='edit-user'), ) diff --git a/uauth/organization/views.py b/uauth/organization/views.py index 3175cd6..adae5e7 100644 --- a/uauth/organization/views.py +++ b/uauth/organization/views.py @@ -1,16 +1,18 @@ from django.utils.translation import ugettext as _ from django.core.urlresolvers import reverse_lazy +from django.http import HttpResponseRedirect from django.views.generic.base import TemplateView from django.views.generic.list import ListView -from django.views.generic.edit import FormView +from django.views.generic.edit import FormView, UpdateView +from django.views.generic import DetailView from django.contrib import messages from django_tables2 import RequestConfig from .utils import create_user from .models import LocalAccount, Organization -from .forms import LocalAccountCreateForm +from .forms import LocalAccountCreateForm, LocalAccountForm from .tables import AccountTable @@ -75,3 +77,28 @@ class UsersCreateView(OrganizationMixin, FormView): return super(UsersCreateView, self).form_valid(form) create_users = UsersCreateView.as_view() + + +class ShowUserView(OrganizationMixin, DetailView): + model = LocalAccount + template_name = 'organization/view_user.html' + +view_user = ShowUserView.as_view() + + +class UserEditView(OrganizationMixin, UpdateView): + template_name = 'organization/edit_user.html' + model = LocalAccount + form_class = LocalAccountForm + + def form_valid(self, form): + username = self.object.username + if 'delete' in self.request.POST: + self.object.delete() + messages.info(self.request, _('Account "%s" successfully deleted' % username)) + return HttpResponseRedirect(self.get_success_url()) + else: + messages.info(self.request, _('Account "%s" successfully updated' % username)) + return super(UserEditView, self).form_valid(form) + +edit_user = UserEditView.as_view() diff --git a/uauth/static/css/style.css b/uauth/static/css/style.css index e3b1b46..de28ea0 100644 --- a/uauth/static/css/style.css +++ b/uauth/static/css/style.css @@ -46,4 +46,19 @@ ul.login li, #guest-login ul li, #voucher-login ul li, .loginbox li { padding: 5px; color: #fff; background: #999; +} + +.user { + border: 2px solid #aaa; + padding: 5px; +} + +.icon-edit:before { + content: '\f044'; + margin: 0 3px; +} + +.icon-delete:before { + content: '\f1f8'; + margin: 0 3px; } \ No newline at end of file