Revision 836b9f76
Added by Serghei Mihai over 10 years ago
| setup.py | ||
|---|---|---|
|
'python-ldap',
|
||
|
'gadjo',
|
||
|
'requests',
|
||
|
'django-tables2',
|
||
|
],
|
||
|
zip_safe=False,
|
||
|
cmdclass={
|
||
| uauth/organization/tables.py | ||
|---|---|---|
|
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')
|
||
| uauth/organization/templates/organization/base.html | ||
|---|---|---|
|
|
||
|
{% 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 %}
|
||
| uauth/organization/templates/organization/users.html | ||
|---|---|---|
|
{% 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 %}
|
||
|
|
||
| uauth/organization/templates/organization/users_table.html | ||
|---|---|---|
|
{% 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 %}
|
||
| uauth/organization/urls.py | ||
|---|---|---|
|
|
||
|
urlpatterns = patterns('',
|
||
|
url(r'^$', manage, name='manage'),
|
||
|
url(r'^users/?$', users, name='manage-users'),
|
||
|
)
|
||
| uauth/organization/views.py | ||
|---|---|---|
|
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):
|
||
| ... | ... | |
|
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()
|
||
| uauth/settings.py | ||
|---|---|---|
|
'gadjo',
|
||
|
'uauth',
|
||
|
'uauth.organization',
|
||
|
'django_tables2',
|
||
|
)
|
||
|
|
||
|
METADATA_URIS = (
|
||
| ... | ... | |
|
'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'
|
||
Also available in: Unified diff
users listing using django_tables