Revision 836b9f76
Added by Serghei Mihai over 9 years ago
setup.py | ||
---|---|---|
76 | 76 |
'python-ldap', |
77 | 77 |
'gadjo', |
78 | 78 |
'requests', |
79 |
'django-tables2', |
|
79 | 80 |
], |
80 | 81 |
zip_safe=False, |
81 | 82 |
cmdclass={ |
uauth/organization/tables.py | ||
---|---|---|
1 |
from django.utils.translation import ugettext as _ |
|
2 |
|
|
3 |
import django_tables2 as tables |
|
4 |
|
|
5 |
from .models import LocalAccount |
|
6 |
|
|
7 |
class AccountTable(tables.Table): |
|
8 |
username = tables.TemplateColumn( |
|
9 |
'<a rel="popup" href="#" %}">{{ record.username }}</a>', |
|
10 |
verbose_name=_('Username')) |
|
11 |
|
|
12 |
class Meta: |
|
13 |
model = LocalAccount |
|
14 |
attrs = {'class': 'main', 'id': 'user-table'} |
|
15 |
fields = ('username', 'active', 'first_name', 'last_name') |
|
16 |
empty_text = _('None') |
uauth/organization/templates/organization/base.html | ||
---|---|---|
5 | 5 |
|
6 | 6 |
{% block more-user-links %} |
7 | 7 |
{{ block.super }} |
8 |
<a href="{% url "manage-users" %}">{% trans 'User management' %}</a> |
|
8 |
<a href="{% url "manage-users" organization.slug %}">{% trans 'User management' %}</a>
|
|
9 | 9 |
{% endblock %} |
uauth/organization/templates/organization/users.html | ||
---|---|---|
1 |
{% extends "organization/base.html" %} |
|
2 |
{% load i18n staticfiles django_tables2 %} |
|
3 |
|
|
4 |
{% block page-title %} |
|
5 |
{% trans 'Users management' %} |
|
6 |
{% endblock %} |
|
7 |
|
|
8 |
{% block appbar %} |
|
9 |
<h2>{% trans "Local users" %}</h2> |
|
10 |
{% endblock %} |
|
11 |
|
|
12 |
{% block content %} |
|
13 |
{% render_table table "organization/users_table.html" %} |
|
14 |
{% endblock %} |
|
15 |
|
uauth/organization/templates/organization/users_table.html | ||
---|---|---|
1 |
{% extends "django_tables2/table.html" %} |
|
2 |
|
|
3 |
{% load django_tables2 %} |
|
4 |
|
|
5 |
{% block table.thead %} |
|
6 |
<thead> |
|
7 |
<tr> |
|
8 |
{% for column in table.columns %} |
|
9 |
{% if column.orderable %} |
|
10 |
<th {{ column.attrs.th.as_html }}><a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}">{{ column.header }}</a></th> |
|
11 |
{% else %} |
|
12 |
<th {{ column.attrs.th.as_html }}>{{ column.header }}</th> |
|
13 |
{% endif %} |
|
14 |
{% endfor %} |
|
15 |
{% block table.head.last.column %} |
|
16 |
{% endblock %} |
|
17 |
</tr> |
|
18 |
</thead> |
|
19 |
{% endblock table.thead %} |
|
20 |
|
|
21 |
{% block table.tbody.row %} |
|
22 |
<tr data-ref="{{ row.record.id }}" class="{{ forloop.counter|divisibleby:2|yesno:"even,odd" }}"> {# avoid cycle for Django 1.2-1.6 compatibility #} |
|
23 |
{% for column, cell in row.items %} |
|
24 |
<td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td> |
|
25 |
{% endfor %} |
|
26 |
{% block table.tbody.last.column %} |
|
27 |
{% endblock %} |
|
28 |
</tr> |
|
29 |
{% endblock table.tbody.row %} |
|
30 |
|
|
31 |
{% block pagination %} |
|
32 |
<p class="paginator"> |
|
33 |
{% if table.page.number > 1 %} |
|
34 |
{% if table.page.previous_page_number != 1 %} |
|
35 |
<a href="{% querystring table.prefixed_page_field=1 %}">1</a> |
|
36 |
... |
|
37 |
{% endif %} |
|
38 |
{% endif %} |
|
39 |
|
|
40 |
{% if table.page.has_previous %} |
|
41 |
<a href="{% querystring table.prefixed_page_field=table.page.previous_page_number %}">{{ table.page.previous_page_number }}</a> |
|
42 |
{% endif %} |
|
43 |
|
|
44 |
<span class="this-page">{{ table.page.number }}</span> |
|
45 |
|
|
46 |
{% if table.page.has_next %} |
|
47 |
<a href="{% querystring table.prefixed_page_field=table.page.next_page_number %}">{{ table.page.next_page_number }}</a> |
|
48 |
{% endif %} |
|
49 |
{% if table.page.number != table.page.paginator.num_pages %} |
|
50 |
{% if table.page.paginator.num_pages > 1 %} |
|
51 |
{% if table.page.next_page_number != table.page.paginator.num_pages %} |
|
52 |
... |
|
53 |
<a href="{% querystring table.prefixed_page_field=table.page.paginator.num_pages %}">{{ table.page.paginator.num_pages }}</a> |
|
54 |
{% endif %} |
|
55 |
{% endif %} |
|
56 |
{% endif %} |
|
57 |
</p> |
|
58 |
{% endblock %} |
uauth/organization/urls.py | ||
---|---|---|
4 | 4 |
|
5 | 5 |
urlpatterns = patterns('', |
6 | 6 |
url(r'^$', manage, name='manage'), |
7 |
url(r'^users/?$', users, name='manage-users'), |
|
7 | 8 |
) |
uauth/organization/views.py | ||
---|---|---|
1 |
from django.utils.translation import ugettext as _ |
|
1 | 2 |
from django.core.urlresolvers import reverse_lazy |
3 |
|
|
2 | 4 |
from django.views.generic.base import TemplateView |
5 |
from django.views.generic.list import ListView |
|
6 |
|
|
7 |
from django_tables2 import RequestConfig |
|
8 |
|
|
9 |
from .models import LocalAccount, Organization |
|
10 |
from .tables import AccountTable |
|
3 | 11 |
|
4 | 12 |
|
5 | 13 |
class OrganizationMixin(object): |
... | ... | |
20 | 28 |
template_name = 'organization/manage.html' |
21 | 29 |
|
22 | 30 |
manage = ManageView.as_view() |
31 |
|
|
32 |
class UsersPageView(OrganizationMixin, ListView): |
|
33 |
template_name = 'organization/users.html' |
|
34 |
model = LocalAccount |
|
35 |
|
|
36 |
def get_context_data(self, *args, **kwargs): |
|
37 |
context = super(UsersPageView, self).get_context_data(*args, **kwargs) |
|
38 |
table = AccountTable(context['object_list']) |
|
39 |
RequestConfig(self.request).configure(table) |
|
40 |
context['table'] = table |
|
41 |
return context |
|
42 |
|
|
43 |
users = UsersPageView.as_view() |
uauth/settings.py | ||
---|---|---|
33 | 33 |
'gadjo', |
34 | 34 |
'uauth', |
35 | 35 |
'uauth.organization', |
36 |
'django_tables2', |
|
36 | 37 |
) |
37 | 38 |
|
38 | 39 |
METADATA_URIS = ( |
... | ... | |
53 | 54 |
'django.middleware.clickjacking.XFrameOptionsMiddleware', |
54 | 55 |
) |
55 | 56 |
|
57 |
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + ('django.core.context_processors.request',) |
|
58 |
|
|
56 | 59 |
ROOT_URLCONF = 'uauth.urls' |
57 | 60 |
|
58 | 61 |
WSGI_APPLICATION = 'uauth.wsgi.application' |
Also available in: Unified diff
users listing using django_tables