mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Major improvements to pagination, modals and people listing
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
|
||||
{% load widget_tweaks %}
|
||||
{% load paginator from filters %}
|
||||
|
||||
{% block title %}People list{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
<h3>People</h3>
|
||||
<a href="{% url 'person_add' %}" class="btn btn-default pull-right">New <span class="glyphicon glyphicon-plus"></span></a>
|
||||
<div class="align-right">{% include 'pagination.html' %}</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-10">
|
||||
<h3>People</h3>
|
||||
</div>
|
||||
<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>
|
||||
<div class="pull-right">{% paginator %}</div>
|
||||
<div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
@@ -29,7 +36,7 @@
|
||||
<td>{{ person.phone }}</td>
|
||||
<td>{{ person.notes|yesno|capfirst }}</td>
|
||||
<td>
|
||||
<a href="{% url 'person_detail' person.pk %}" class="btn btn-default" data-toggle="modal" data-target="#modal">
|
||||
<a href="{% url 'person_detail' person.pk %}" class="btn btn-default modal-href">
|
||||
<span class="glyphicon glyphicon-eye-open"></span>
|
||||
</a>
|
||||
<a href="{% url 'person_update' person.pk %}" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
|
||||
@@ -44,6 +51,6 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="align-right">{% include 'pagination.html' %}</div>
|
||||
<div class="align-right">{% paginator %}</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -19,4 +19,45 @@ def nice_errors(form, non_field_msg='General form errors'):
|
||||
else:
|
||||
key = form.fields[field].label
|
||||
nice_errors[key] = errors
|
||||
return nice_errors
|
||||
return nice_errors
|
||||
|
||||
def paginator(context, adjacent_pages=3):
|
||||
"""
|
||||
To be used in conjunction with the object_list generic view.
|
||||
|
||||
Adds pagination context variables for use in displaying first, adjacent and
|
||||
last page links in addition to those created by the object_list generic
|
||||
view.
|
||||
|
||||
"""
|
||||
page = context['page_obj']
|
||||
paginator = context['paginator']
|
||||
startPage = max(page.number - adjacent_pages, 1)
|
||||
if startPage <= 3: startPage = 1
|
||||
endPage = page.number + adjacent_pages + 1
|
||||
if endPage >= paginator.num_pages - 1: endPage = paginator.num_pages + 1
|
||||
page_numbers = [n for n in range(startPage, endPage) \
|
||||
if n > 0 and n <= paginator.num_pages]
|
||||
|
||||
dict = {
|
||||
'is_paginated': paginator.num_pages > 0,
|
||||
'page_obj': page,
|
||||
'paginator': paginator,
|
||||
'results': paginator.per_page,
|
||||
'page_numbers': page_numbers,
|
||||
'show_first': 1 not in page_numbers,
|
||||
'show_last': paginator.num_pages not in page_numbers,
|
||||
'first': 1,
|
||||
'last': paginator.num_pages,
|
||||
'has_next': page.has_next(),
|
||||
'has_previous': page.has_previous(),
|
||||
}
|
||||
|
||||
if page.has_next():
|
||||
dict['next'] = page.next_page_number()
|
||||
if page.has_previous():
|
||||
dict['previous'] = page.previous_page_number()
|
||||
|
||||
return dict
|
||||
|
||||
register.inclusion_tag('pagination.html', takes_context=True)(paginator)
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.http.response import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.views import generic
|
||||
import models
|
||||
from RIGS import models
|
||||
|
||||
# Create your views here.
|
||||
def login(request, **kwargs):
|
||||
@@ -26,6 +26,7 @@ class CloseModal(generic.TemplateView):
|
||||
|
||||
class PersonIndex(generic.ListView):
|
||||
model = models.Person
|
||||
paginate_by = 20
|
||||
|
||||
class PersonDetail(generic.DetailView):
|
||||
model = models.Person
|
||||
|
||||
Reference in New Issue
Block a user