diff --git a/setup.py b/setup.py index ddee862..1f99dee 100644 --- a/setup.py +++ b/setup.py @@ -76,6 +76,7 @@ setup( 'python-ldap', 'gadjo', 'requests', + 'django-tables2', ], zip_safe=False, cmdclass={ diff --git a/uauth/organization/tables.py b/uauth/organization/tables.py new file mode 100644 index 0000000..bcd03ab --- /dev/null +++ b/uauth/organization/tables.py @@ -0,0 +1,16 @@ +from django.utils.translation import ugettext as _ + +import django_tables2 as tables + +from .models import LocalAccount + +class AccountTable(tables.Table): + username = tables.TemplateColumn( + '{{ record.username }}', + verbose_name=_('Username')) + + class Meta: + model = LocalAccount + attrs = {'class': 'main', 'id': 'user-table'} + fields = ('username', 'active', 'first_name', 'last_name') + empty_text = _('None') diff --git a/uauth/organization/templates/organization/base.html b/uauth/organization/templates/organization/base.html index ab869c6..3131ae6 100644 --- a/uauth/organization/templates/organization/base.html +++ b/uauth/organization/templates/organization/base.html @@ -5,5 +5,5 @@ {% block more-user-links %} {{ block.super }} - {% trans 'User management' %} + {% trans 'User management' %} {% endblock %} diff --git a/uauth/organization/templates/organization/users.html b/uauth/organization/templates/organization/users.html new file mode 100644 index 0000000..33aae88 --- /dev/null +++ b/uauth/organization/templates/organization/users.html @@ -0,0 +1,15 @@ +{% extends "organization/base.html" %} +{% load i18n staticfiles django_tables2 %} + +{% block page-title %} +{% trans 'Users management' %} +{% endblock %} + +{% block appbar %} +

{% trans "Local users" %}

+{% endblock %} + +{% block content %} +{% render_table table "organization/users_table.html" %} +{% endblock %} + diff --git a/uauth/organization/templates/organization/users_table.html b/uauth/organization/templates/organization/users_table.html new file mode 100644 index 0000000..34f0479 --- /dev/null +++ b/uauth/organization/templates/organization/users_table.html @@ -0,0 +1,58 @@ +{% extends "django_tables2/table.html" %} + +{% load django_tables2 %} + +{% block table.thead %} + + + {% for column in table.columns %} + {% if column.orderable %} + {{ column.header }} + {% else %} + {{ column.header }} + {% endif %} + {% endfor %} + {% block table.head.last.column %} + {% endblock %} + + +{% endblock table.thead %} + +{% block table.tbody.row %} + {# avoid cycle for Django 1.2-1.6 compatibility #} + {% for column, cell in row.items %} + {% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %} + {% endfor %} + {% block table.tbody.last.column %} + {% endblock %} + +{% endblock table.tbody.row %} + +{% block pagination %} +

+ {% if table.page.number > 1 %} + {% if table.page.previous_page_number != 1 %} + 1 + ... + {% endif %} + {% endif %} + + {% if table.page.has_previous %} + {{ table.page.previous_page_number }} + {% endif %} + + {{ table.page.number }} + + {% if table.page.has_next %} + {{ table.page.next_page_number }} + {% endif %} + {% if table.page.number != table.page.paginator.num_pages %} + {% if table.page.paginator.num_pages > 1 %} + {% if table.page.next_page_number != table.page.paginator.num_pages %} + ... + {{ table.page.paginator.num_pages }} + {% endif %} + {% endif %} + {% endif %} +

+{% endblock %} diff --git a/uauth/organization/urls.py b/uauth/organization/urls.py index 5b5dfb5..6cf4dfd 100644 --- a/uauth/organization/urls.py +++ b/uauth/organization/urls.py @@ -4,4 +4,5 @@ from .views import * urlpatterns = patterns('', url(r'^$', manage, name='manage'), + url(r'^users/?$', users, name='manage-users'), ) diff --git a/uauth/organization/views.py b/uauth/organization/views.py index 61bb002..e940311 100644 --- a/uauth/organization/views.py +++ b/uauth/organization/views.py @@ -1,5 +1,13 @@ +from django.utils.translation import ugettext as _ from django.core.urlresolvers import reverse_lazy + from django.views.generic.base import TemplateView +from django.views.generic.list import ListView + +from django_tables2 import RequestConfig + +from .models import LocalAccount, Organization +from .tables import AccountTable class OrganizationMixin(object): @@ -20,3 +28,16 @@ class ManageView(TemplateView): template_name = 'organization/manage.html' manage = ManageView.as_view() + +class UsersPageView(OrganizationMixin, ListView): + template_name = 'organization/users.html' + model = LocalAccount + + def get_context_data(self, *args, **kwargs): + context = super(UsersPageView, self).get_context_data(*args, **kwargs) + table = AccountTable(context['object_list']) + RequestConfig(self.request).configure(table) + context['table'] = table + return context + +users = UsersPageView.as_view() diff --git a/uauth/settings.py b/uauth/settings.py index b559467..d3ffa8c 100644 --- a/uauth/settings.py +++ b/uauth/settings.py @@ -33,6 +33,7 @@ INSTALLED_APPS = ( 'gadjo', 'uauth', 'uauth.organization', + 'django_tables2', ) METADATA_URIS = ( @@ -53,6 +54,8 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) +TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + ('django.core.context_processors.request',) + ROOT_URLCONF = 'uauth.urls' WSGI_APPLICATION = 'uauth.wsgi.application'