summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--setup.py1
-rw-r--r--uauth/organization/tables.py16
-rw-r--r--uauth/organization/templates/organization/base.html2
-rw-r--r--uauth/organization/templates/organization/users.html15
-rw-r--r--uauth/organization/templates/organization/users_table.html58
-rw-r--r--uauth/organization/urls.py1
-rw-r--r--uauth/organization/views.py21
-rw-r--r--uauth/settings.py3
8 files changed, 116 insertions, 1 deletions
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(
+ '<a rel="popup" href="#" %}">{{ record.username }}</a>',
+ 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 }}
- <a href="{% url "manage-users" %}">{% trans 'User management' %}</a>
+ <a href="{% url "manage-users" organization.slug %}">{% trans 'User management' %}</a>
{% 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 %}
+<h2>{% trans "Local users" %}</h2>
+{% 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 %}
+<thead>
+ <tr>
+ {% for column in table.columns %}
+ {% if column.orderable %}
+ <th {{ column.attrs.th.as_html }}><a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}">{{ column.header }}</a></th>
+ {% else %}
+ <th {{ column.attrs.th.as_html }}>{{ column.header }}</th>
+ {% endif %}
+ {% endfor %}
+ {% block table.head.last.column %}
+ {% endblock %}
+ </tr>
+</thead>
+{% endblock table.thead %}
+
+{% block table.tbody.row %}
+ <tr data-ref="{{ row.record.id }}" class="{{ forloop.counter|divisibleby:2|yesno:"even,odd" }}"> {# avoid cycle for Django 1.2-1.6 compatibility #}
+ {% for column, cell in row.items %}
+ <td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
+ {% endfor %}
+ {% block table.tbody.last.column %}
+ {% endblock %}
+ </tr>
+{% endblock table.tbody.row %}
+
+{% block pagination %}
+ <p class="paginator">
+ {% if table.page.number > 1 %}
+ {% if table.page.previous_page_number != 1 %}
+ <a href="{% querystring table.prefixed_page_field=1 %}">1</a>
+ ...
+ {% endif %}
+ {% endif %}
+
+ {% if table.page.has_previous %}
+ <a href="{% querystring table.prefixed_page_field=table.page.previous_page_number %}">{{ table.page.previous_page_number }}</a>
+ {% endif %}
+
+ <span class="this-page">{{ table.page.number }}</span>
+
+ {% if table.page.has_next %}
+ <a href="{% querystring table.prefixed_page_field=table.page.next_page_number %}">{{ table.page.next_page_number }}</a>
+ {% 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 %}
+ ...
+ <a href="{% querystring table.prefixed_page_field=table.page.paginator.num_pages %}">{{ table.page.paginator.num_pages }}</a>
+ {% endif %}
+ {% endif %}
+ {% endif %}
+ </p>
+{% 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'