control panel: add user list
This commit is contained in:
parent
5acf994c1a
commit
e501b49026
5 changed files with 81 additions and 3 deletions
24
src/c3nav/control/templates/control/fragment_pagination.html
Normal file
24
src/c3nav/control/templates/control/fragment_pagination.html
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{% load i18n %}
|
||||||
|
<p>
|
||||||
|
{% if objects.has_previous %}
|
||||||
|
<a href="?{% if request.GET.s %}s={{ request.GET.s | urlencode }}&{% endif %}page=1">
|
||||||
|
« {% trans 'first' %}
|
||||||
|
</a> ·
|
||||||
|
<a href="?{% if request.GET.s %}s={{ request.GET.s | urlencode }}&{% endif %}page={{ objects.previous_page_number }}">
|
||||||
|
‹ {% trans 'previous' %}
|
||||||
|
</a> ·
|
||||||
|
{% endif %}
|
||||||
|
{% with page_number=objects.number num_pages=objects.paginator.num_pages %}
|
||||||
|
{% blocktrans %}
|
||||||
|
Page {{ page_number }} of {{ num_pages }}
|
||||||
|
{% endblocktrans %}
|
||||||
|
{% endwith %}
|
||||||
|
{% if objects.has_next %}
|
||||||
|
· <a href="?{% if request.GET.s %}s={{ request.GET.s | urlencode }}&{% endif %}page={{ objects.next_page_number }}">
|
||||||
|
{% trans 'next' %} ›
|
||||||
|
</a>
|
||||||
|
· <a href="?{% if request.GET.s %}s={{ request.GET.s | urlencode }}&{% endif %}page={{ objects.paginator.num_pages }}">
|
||||||
|
{% trans 'last' %} »
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
27
src/c3nav/control/templates/control/users.html
Normal file
27
src/c3nav/control/templates/control/users.html
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{% extends 'control/base.html' %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block subcontent %}
|
||||||
|
<h2>{% trans 'Users' %}</h2>
|
||||||
|
|
||||||
|
<form class="search-form">
|
||||||
|
<input type="text" name="s" value="{{ request.GET.s }}"> <button type="submit">{% trans 'Search' %}</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% include 'control/fragment_pagination.html' with objects=users %}
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans 'ID' %}</th>
|
||||||
|
<th>{% trans 'Username' %}</th>
|
||||||
|
</tr>
|
||||||
|
{% for user in users %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ user.id }}</td>
|
||||||
|
<td>{{ user.username }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% include 'control/fragment_pagination.html' with objects=users %}
|
||||||
|
{% endblock %}
|
|
@ -1,7 +1,8 @@
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from c3nav.control.views import main_index
|
from c3nav.control.views import main_index, user_list
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
url(r'^users/$', user_list, name='control.users'),
|
||||||
url(r'^$', main_index, name='control.index'),
|
url(r'^$', main_index, name='control.index'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,19 +1,40 @@
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
from django.core.paginator import Paginator
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
|
||||||
def control_panel_view(func):
|
def control_panel_view(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapped_func(self, request, *args, **kwargs):
|
def wrapped_func(request, *args, **kwargs):
|
||||||
if not request.user_permissions.control_panel:
|
if not request.user_permissions.control_panel:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
return func(self, request, *args, **kwargs)
|
return func(request, *args, **kwargs)
|
||||||
return login_required(login_url='site.login')(wrapped_func)
|
return login_required(login_url='site.login')(wrapped_func)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
@control_panel_view
|
@control_panel_view
|
||||||
def main_index(request):
|
def main_index(request):
|
||||||
return render(request, 'control/index.html', {})
|
return render(request, 'control/index.html', {})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@control_panel_view
|
||||||
|
def user_list(request):
|
||||||
|
search = request.GET.get('s')
|
||||||
|
page = request.GET.get('page', 1)
|
||||||
|
|
||||||
|
queryset = User.objects.order_by('id')
|
||||||
|
if search:
|
||||||
|
queryset = queryset.filter(username__icontains=search.strip())
|
||||||
|
|
||||||
|
paginator = Paginator(queryset, 20)
|
||||||
|
users = paginator.page(page)
|
||||||
|
|
||||||
|
return render(request, 'control/users.html', {
|
||||||
|
'users': users,
|
||||||
|
})
|
||||||
|
|
|
@ -685,3 +685,8 @@ ul.messages li.alert-danger {
|
||||||
border-color: #CC0000;
|
border-color: #CC0000;
|
||||||
background-color:#FFEEEE;
|
background-color:#FFEEEE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.search-form input {
|
||||||
|
max-width: 400px;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue