user credentials and edit views(#7065)
This commit is contained in:
parent
d9dfbd19d7
commit
7b4999305a
|
@ -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)
|
||||
|
|
|
@ -6,7 +6,7 @@ from .models import LocalAccount
|
|||
|
||||
class AccountTable(tables.Table):
|
||||
username = tables.TemplateColumn(
|
||||
'<a rel="popup" href="#" %}">{{ record.username }}</a>',
|
||||
'<a href="{% url "edit-user" organization.slug record.pk %}" rel="popup"><i class="icon-edit"></i></a><a href="{% url "view-user" organization.slug record.pk %}">{{ record.username }}</a>',
|
||||
verbose_name=_('Username'))
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{% extends "organization/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post" autocomplete="off">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="{% trans "Update" %}" class="btn btn-primary" />
|
||||
<button name="delete" class="ui-state-default delete-button icon-delete">{% trans "Delete" %}</button>
|
||||
</div>
|
||||
<script>
|
||||
$('input.datepicker').datepicker({dateFormat: "yy-mm-dd", weekStart: 1 });
|
||||
</script>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -0,0 +1,9 @@
|
|||
{% load i18n %}
|
||||
|
||||
<div class="user">
|
||||
<h3>{% trans "Login" %} {{ user.username }} {% if user.get_fullname %}({{ user.get_fullname }}){% endif %}</h3>
|
||||
<h4>{% trans "Password:" %} {{ user.password }}</h4>
|
||||
<p class="expire">{% trans "Expiring:" %} {% if user.expiration_date %}{{ user.expiration_date|date:"DATETIME_FORMAT" }}{% else %}{% trans "never" %}{% endif %}</p>
|
||||
<p><strong>{% trans "Description" %}</strong></p>
|
||||
<p>{{ user.description }}</p>
|
||||
</div>
|
|
@ -0,0 +1,15 @@
|
|||
{% extends "organization/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block page-title %}
|
||||
{% trans 'User details' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{% trans "User details" %}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include "organization/user.html" with user=object %}
|
||||
{% endblock %}
|
||||
|
|
@ -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<pk>[\w]+)/$', view_user, name='view-user'),
|
||||
url(r'^users/(?P<pk>[\w]+)/edit$', edit_user, name='edit-user'),
|
||||
)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
Reference in New Issue