mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Added search and orderby features to people
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
|
||||
{% load widget_tweaks %}
|
||||
{% load paginator from filters %}
|
||||
{% load url_replace from filters %}
|
||||
{% load orderby from filters %}
|
||||
|
||||
{% block title %}People list{% endblock %}
|
||||
{% block title %}People{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
@@ -13,6 +15,13 @@
|
||||
<div class="col-sm-2">
|
||||
<a href="{% url 'person_add' %}" class="btn btn-default pull-right">New <span class="glyphicon glyphicon-plus"></span></a>
|
||||
</div>
|
||||
<div class="col-sm-3 col-sm-offset-9">
|
||||
<form class="form form-horizontal col-sm-12">
|
||||
<div class="form-group">
|
||||
<input type="search" name="q" placeholder="Search" value="{{ request.GET.q }}" class="form-control" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right">{% paginator %}</div>
|
||||
<div>
|
||||
@@ -20,7 +29,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>Name</td>
|
||||
<td>Name<a href="?{% orderby request 'orderBy' 'name' %}"><span class="caret"></span></a></td>
|
||||
<td>Email</td>
|
||||
<td>Phone</td>
|
||||
<td>Notes</td>
|
||||
|
||||
@@ -40,6 +40,7 @@ def paginator(context, adjacent_pages=3):
|
||||
if n > 0 and n <= paginator.num_pages]
|
||||
|
||||
dict = {
|
||||
'request': context['request'],
|
||||
'is_paginated': paginator.num_pages > 0,
|
||||
'page_obj': page,
|
||||
'paginator': paginator,
|
||||
@@ -59,4 +60,28 @@ def paginator(context, adjacent_pages=3):
|
||||
dict['previous'] = page.previous_page_number()
|
||||
|
||||
return dict
|
||||
register.inclusion_tag('pagination.html', takes_context=True)(paginator)
|
||||
register.inclusion_tag('pagination.html', takes_context=True)(paginator)
|
||||
|
||||
@register.simple_tag
|
||||
def url_replace(request, field, value):
|
||||
|
||||
dict_ = request.GET.copy()
|
||||
|
||||
dict_[field] = value
|
||||
|
||||
return dict_.urlencode()
|
||||
|
||||
@register.simple_tag
|
||||
def orderby(request, field, attr):
|
||||
|
||||
dict_ = request.GET.copy()
|
||||
|
||||
if dict_[field] == attr:
|
||||
if not dict_[field].startswith("-"):
|
||||
dict_[field] = "-" + attr
|
||||
else:
|
||||
dict_[field] = attr
|
||||
else:
|
||||
dict_[field] = attr
|
||||
|
||||
return dict_.urlencode()
|
||||
@@ -1,6 +1,8 @@
|
||||
from django.http.response import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.views import generic
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.db.models import Q
|
||||
from RIGS import models
|
||||
|
||||
# Create your views here.
|
||||
@@ -28,6 +30,17 @@ class PersonIndex(generic.ListView):
|
||||
model = models.Person
|
||||
paginate_by = 20
|
||||
|
||||
def get_queryset(self):
|
||||
q = self.request.GET.get('q', "")
|
||||
if len(q) >= 3:
|
||||
object_list = self.model.objects.filter(Q(name__icontains=q) | Q(email__icontains=q))
|
||||
else:
|
||||
object_list = self.model.objects.all()
|
||||
orderBy = self.request.GET.get('orderBy', None)
|
||||
if orderBy is not None:
|
||||
object_list = object_list.order_by(orderBy)
|
||||
return object_list
|
||||
|
||||
class PersonDetail(generic.DetailView):
|
||||
model = models.Person
|
||||
|
||||
|
||||
Reference in New Issue
Block a user