Project

General

Profile

« Previous | Next » 

Revision 7b499930

Added by Serghei Mihai almost 9 years ago

user credentials and edit views(#7065)

View differences:

uauth/organization/forms.py
14 14
            'password': forms.PasswordInput
15 15
        }
16 16

  
17
    def save(self):
18
        # save previous password
19
        old_password = self.initial.get('password')
20
        obj = super(LocalAccountForm, self).save(commit=False)
21
        if not self.cleaned_data.get('password'):
22
            obj.password = old_password
23
        obj.save()
24
        return obj
25

  
17 26

  
18 27
class LocalAccountCreateForm(LocalAccountForm):
19 28
    accounts_number = forms.IntegerField(_('Number of accounts to create'), required=False)
uauth/organization/tables.py
6 6

  
7 7
class AccountTable(tables.Table):
8 8
    username = tables.TemplateColumn(
9
        '<a rel="popup" href="#" %}">{{ record.username }}</a>',
9
        '<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>',
10 10
        verbose_name=_('Username'))
11 11

  
12 12
    class Meta:
uauth/organization/templates/organization/edit_user.html
1
{% extends "organization/base.html" %}
2
{% load i18n %}
3

  
4
{% block content %}
5
<form method="post" autocomplete="off">
6
	{% csrf_token %}
7
	<table>
8
	  {{ form.as_table }}
9
	</table>
10
	<div class="form-actions">
11
	  <input type="submit" value="{% trans "Update" %}" class="btn btn-primary" />
12
          <button name="delete" class="ui-state-default delete-button icon-delete">{% trans "Delete" %}</button>
13
	</div>
14
        <script>
15
          $('input.datepicker').datepicker({dateFormat: "yy-mm-dd", weekStart: 1 });
16
        </script>
17
</form>
18
{% endblock %}
uauth/organization/templates/organization/user.html
1
{% load i18n %}
2

  
3
<div class="user">
4
  <h3>{% trans "Login" %} {{ user.username }} {% if user.get_fullname %}({{ user.get_fullname }}){% endif %}</h3>
5
  <h4>{% trans "Password:" %} {{ user.password }}</h4>
6
  <p class="expire">{% trans "Expiring:" %} {% if user.expiration_date %}{{ user.expiration_date|date:"DATETIME_FORMAT" }}{% else %}{% trans "never" %}{% endif %}</p>
7
  <p><strong>{% trans "Description" %}</strong></p>
8
  <p>{{ user.description }}</p>
9
</div>
uauth/organization/templates/organization/view_user.html
1
{% extends "organization/base.html" %}
2
{% load i18n %}
3

  
4
{% block page-title %}
5
{% trans 'User details' %}
6
{% endblock %}
7

  
8
{% block appbar %}
9
<h2>{% trans "User details" %}</h2>
10
{% endblock %}
11

  
12
{% block content %}
13
{% include "organization/user.html" with user=object %}
14
{% endblock %}
15

  
uauth/organization/urls.py
6 6
    url(r'^$', manage, name='manage'),
7 7
    url(r'^users/?$', users, name='manage-users'),
8 8
    url(r'^users/create$', create_users, name='create-users'),
9
    url(r'^users/(?P<pk>[\w]+)/$', view_user, name='view-user'),
10
    url(r'^users/(?P<pk>[\w]+)/edit$', edit_user, name='edit-user'),
9 11
)
uauth/organization/views.py
1 1
from django.utils.translation import ugettext as _
2 2
from django.core.urlresolvers import reverse_lazy
3
from django.http import HttpResponseRedirect
3 4

  
4 5
from django.views.generic.base import TemplateView
5 6
from django.views.generic.list import ListView
6
from django.views.generic.edit import FormView
7
from django.views.generic.edit import FormView, UpdateView
8
from django.views.generic import DetailView
7 9
from django.contrib import messages
8 10

  
9 11
from django_tables2 import RequestConfig
10 12

  
11 13
from .utils import create_user
12 14
from .models import LocalAccount, Organization
13
from .forms import LocalAccountCreateForm
15
from .forms import LocalAccountCreateForm, LocalAccountForm
14 16
from .tables import AccountTable
15 17

  
16 18

  
......
75 77
        return super(UsersCreateView, self).form_valid(form)
76 78

  
77 79
create_users = UsersCreateView.as_view()
80

  
81

  
82
class ShowUserView(OrganizationMixin, DetailView):
83
    model = LocalAccount
84
    template_name = 'organization/view_user.html'
85

  
86
view_user = ShowUserView.as_view()
87

  
88

  
89
class UserEditView(OrganizationMixin, UpdateView):
90
    template_name = 'organization/edit_user.html'
91
    model = LocalAccount
92
    form_class = LocalAccountForm
93

  
94
    def form_valid(self, form):
95
        username = self.object.username
96
        if 'delete' in self.request.POST:
97
            self.object.delete()
98
            messages.info(self.request, _('Account "%s" successfully deleted' % username))
99
            return HttpResponseRedirect(self.get_success_url())
100
        else:
101
            messages.info(self.request, _('Account "%s" successfully updated' % username))
102
            return super(UserEditView, self).form_valid(form)
103

  
104
edit_user = UserEditView.as_view()
uauth/static/css/style.css
46 46
    padding: 5px;
47 47
    color: #fff;
48 48
    background: #999;
49
}
50

  
51
.user {
52
    border: 2px solid #aaa;
53
    padding: 5px;
54
}
55

  
56
.icon-edit:before {
57
    content: '\f044';
58
    margin: 0 3px;
59
}
60

  
61
.icon-delete:before {
62
    content: '\f1f8';
63
    margin: 0 3px;
49 64
}

Also available in: Unified diff