mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-11 10:30:58 +00:00
added user searching
This commit is contained in:
parent
ddd4b8a9c1
commit
8daf6b3407
7 changed files with 123 additions and 57 deletions
|
|
@ -63,6 +63,7 @@ h2{
|
|||
}
|
||||
}
|
||||
a{
|
||||
outline:none;
|
||||
color:@color-link;
|
||||
text-decoration:none;
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ form{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@media screen and (min-width: @breakpoint-mobile){
|
||||
.content-wrapper{
|
||||
float:none;
|
||||
|
|
@ -154,10 +153,11 @@ form{
|
|||
|
||||
&:before {
|
||||
content: '';
|
||||
width:0px;
|
||||
display: inline-block;
|
||||
height: 100%;
|
||||
vertical-align: middle;
|
||||
margin-left:-0.3em;
|
||||
margin-left:-0.4em;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@
|
|||
var wait = setTimeout(search, 200);
|
||||
$(this).data('timer', wait);
|
||||
});
|
||||
// $('a.suggested-tag').click(function() {
|
||||
// $('#id_q').val($(this).text());
|
||||
// search();
|
||||
// return false;
|
||||
// })
|
||||
|
||||
var search_current_index = 0;
|
||||
var search_next_index = 0;
|
||||
|
|
|
|||
|
|
@ -2,51 +2,40 @@
|
|||
{% load gravatar %}
|
||||
{% block titletag %}Users{% endblock %}
|
||||
{% block bodyclass %}menu-users{% endblock %}
|
||||
{% block content %}
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
$('#id_q').on('input', function() {
|
||||
clearTimeout($.data(this, 'timer'));
|
||||
var wait = setTimeout(search, 200);
|
||||
$(this).data('timer', wait);
|
||||
});
|
||||
|
||||
{% include "wagtailadmin/shared/header.html" with title="Users" add_link="wagtailusers_create" add_text="Add a user" %}
|
||||
var search_current_index = 0;
|
||||
var search_next_index = 0;
|
||||
|
||||
function search () {
|
||||
search_next_index++;
|
||||
var index = search_next_index;
|
||||
$.ajax({
|
||||
url: "{% url 'wagtailusers_index' %}",
|
||||
data: {q: $('#id_q').val()},
|
||||
success: function(data, status) {
|
||||
if (index > search_current_index) {
|
||||
search_current_index = index;
|
||||
$('#user-results').html(data);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include "wagtailadmin/shared/header.html" with title="Users" add_link="wagtailusers_create" add_text="Add a user" search_url="wagtailusers_index" %}
|
||||
|
||||
<div class="nice-padding">
|
||||
<table class="listing">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="name">
|
||||
Name
|
||||
{% if ordering == "name" %}
|
||||
<a href="{% url 'wagtailusers_index' %}" class="icon icon-arrow-down-after teal"></a>
|
||||
{% else %}
|
||||
<a href="{% url 'wagtailusers_index' %}?ordering=name" class="icon icon-arrow-down-after"></a>
|
||||
{% endif %}
|
||||
</th>
|
||||
<th class="username">
|
||||
Username
|
||||
{% if ordering == "username" %}
|
||||
<a href="{% url 'wagtailusers_index' %}" class="icon icon-arrow-down-after teal"></a>
|
||||
{% else %}
|
||||
<a href="{% url 'wagtailusers_index' %}?ordering=username" class="icon icon-arrow-down-after"></a>
|
||||
{% endif %}
|
||||
</th>
|
||||
<th class="level">Level</th>
|
||||
<th class="status">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td class="title">
|
||||
<h2>
|
||||
<span class="avatar small icon icon-user"><img src="{% gravatar_url user.email 25 %}" /></span>
|
||||
<a href="{% url 'wagtailusers_edit' user.id %}">{{ user.get_full_name|default:user.username }}</a>
|
||||
</h2>
|
||||
</td>
|
||||
<td class="username">{{ user.username }}</td>
|
||||
<td class="level">{% if user.is_superuser %}Admin{% endif %}</td>
|
||||
<td class="status"><div class="status-tag {% if user.is_active %}primary{% endif %}">{% if user.is_active %}Active{% else %}Inactive{% endif %}</div></td>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% include "wagtailadmin/shared/pagination_nav.html" with items=users linkurl="wagtailusers_index" %}
|
||||
<div id="user-results" class="users">
|
||||
{% include "wagtailusers/results.html" %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
|||
40
wagtail/wagtailusers/templates/wagtailusers/list.html
Normal file
40
wagtail/wagtailusers/templates/wagtailusers/list.html
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{% load gravatar %}
|
||||
<table class="listing">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="name">
|
||||
Name
|
||||
{% if ordering == "name" %}
|
||||
<a href="{% url 'wagtailusers_index' %}" class="icon icon-arrow-down-after teal"></a>
|
||||
{% else %}
|
||||
<a href="{% url 'wagtailusers_index' %}?ordering=name" class="icon icon-arrow-down-after"></a>
|
||||
{% endif %}
|
||||
</th>
|
||||
<th class="username">
|
||||
Username
|
||||
{% if ordering == "username" %}
|
||||
<a href="{% url 'wagtailusers_index' %}" class="icon icon-arrow-down-after teal"></a>
|
||||
{% else %}
|
||||
<a href="{% url 'wagtailusers_index' %}?ordering=username" class="icon icon-arrow-down-after"></a>
|
||||
{% endif %}
|
||||
</th>
|
||||
<th class="level">Level</th>
|
||||
<th class="status">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td class="title">
|
||||
<h2>
|
||||
<span class="avatar small icon icon-user"><img src="{% gravatar_url user.email 25 %}" /></span>
|
||||
<a href="{% url 'wagtailusers_edit' user.id %}">{{ user.get_full_name|default:user.username }}</a>
|
||||
</h2>
|
||||
</td>
|
||||
<td class="username">{{ user.username }}</td>
|
||||
<td class="level">{% if user.is_superuser %}Admin{% endif %}</td>
|
||||
<td class="status"><div class="status-tag {% if user.is_active %}primary{% endif %}">{% if user.is_active %}Active{% else %}Inactive{% endif %}</div></td>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
15
wagtail/wagtailusers/templates/wagtailusers/results.html
Normal file
15
wagtail/wagtailusers/templates/wagtailusers/results.html
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{% if users %}
|
||||
{% if is_searching %}
|
||||
<h2>{{ users|length }} match{{ users|pluralize:"es" }}</h2>
|
||||
{% endif %}
|
||||
|
||||
{% include "wagtailusers/list.html" %}
|
||||
|
||||
{% include "wagtailadmin/shared/pagination_nav.html" with items=users is_searching=is_searching linkurl="wagtailusers_index" %}
|
||||
{% else %}
|
||||
{% if is_searching %}
|
||||
<p>Sorry, no users match "<em>{{ search_query }}</em>"
|
||||
{% else %}
|
||||
<p>There are no users configured. Why not <a href="{% url 'wagtailusers_create' %}">add some</a>?</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
@ -3,15 +3,31 @@ from django.contrib.auth.models import User
|
|||
from django.contrib.auth.decorators import permission_required
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.contrib import messages
|
||||
from django.db.models import Q
|
||||
|
||||
from wagtail.wagtailadmin.forms import SearchForm
|
||||
from wagtail.wagtailusers.forms import UserCreationForm, UserEditForm
|
||||
|
||||
|
||||
@permission_required('auth.change_user')
|
||||
def index(request):
|
||||
q = None
|
||||
p = request.GET.get("p", 1)
|
||||
is_searching = False
|
||||
|
||||
users = User.objects.order_by('last_name', 'first_name')
|
||||
if 'q' in request.GET:
|
||||
form = SearchForm(request.GET, placeholder_suffix="users")
|
||||
if form.is_valid():
|
||||
q = form.cleaned_data['q']
|
||||
|
||||
is_searching = True
|
||||
users = User.objects.filter(Q(username__icontains=q) | Q(first_name__icontains=q) | Q(last_name__icontains=q) | Q(email__icontains=q))
|
||||
else:
|
||||
form = SearchForm(placeholder_suffix="users")
|
||||
|
||||
if not is_searching:
|
||||
users = User.objects
|
||||
|
||||
users = users.order_by('last_name', 'first_name')
|
||||
|
||||
if 'ordering' in request.GET:
|
||||
ordering = request.GET['ordering']
|
||||
|
|
@ -31,11 +47,21 @@ def index(request):
|
|||
except EmptyPage:
|
||||
users = paginator.page(paginator.num_pages)
|
||||
|
||||
return render(request, 'wagtailusers/index.html', {
|
||||
'users': users,
|
||||
'ordering': ordering,
|
||||
})
|
||||
|
||||
if request.is_ajax():
|
||||
return render(request, "wagtailusers/results.html", {
|
||||
'users': users,
|
||||
'is_searching': is_searching,
|
||||
'search_query': q,
|
||||
'ordering': ordering,
|
||||
})
|
||||
else:
|
||||
return render(request, "wagtailusers/index.html", {
|
||||
'search_form': form,
|
||||
'users': users,
|
||||
'is_searching': is_searching,
|
||||
'ordering': ordering,
|
||||
'search_query': q,
|
||||
})
|
||||
|
||||
@permission_required('auth.change_user')
|
||||
def create(request):
|
||||
|
|
|
|||
Loading…
Reference in a new issue