[extensions-web] Paginate the extensions list
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Paginate the extensions list
- Date: Mon, 24 Oct 2011 23:28:25 +0000 (UTC)
commit be6674dc9d3f9f8cd3d35673102863a7c0b0bfaa
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Oct 24 19:23:30 2011 -0400
Paginate the extensions list
.../extensions/templates/extensions/list.html | 5 +++
sweettooth/extensions/templatetags/paginator.py | 29 ++++++++++++++++++++
sweettooth/extensions/urls.py | 1 +
sweettooth/static/css/sweettooth.css | 27 ++++++++++++++++++
4 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/sweettooth/extensions/templates/extensions/list.html b/sweettooth/extensions/templates/extensions/list.html
index 326cea4..301fea8 100644
--- a/sweettooth/extensions/templates/extensions/list.html
+++ b/sweettooth/extensions/templates/extensions/list.html
@@ -17,6 +17,11 @@
{% endwith %}
{% endfor %}
</ul>
+
+ {% load paginator %}
+ <div id="paginator">
+ {% paginator page_obj %}
+ </div>
{% endblock %}
{% block navclass %}main{% endblock %}
diff --git a/sweettooth/extensions/templatetags/paginator.py b/sweettooth/extensions/templatetags/paginator.py
new file mode 100644
index 0000000..de5cba1
--- /dev/null
+++ b/sweettooth/extensions/templatetags/paginator.py
@@ -0,0 +1,29 @@
+
+from django import template
+from django.utils.safestring import mark_safe
+
+register = template.Library()
+
+ register simple_tag
+def paginator(page_obj, context=3):
+ number = page_obj.number
+ context_left = range(max(number-context, 2), number)
+ context_right = range(number+1, min(number+context+1, page_obj.paginator.num_pages+1))
+
+ lines = []
+
+ if page_obj.has_previous():
+ lines.append(u'<a class="number first" href="?page=1">1</a>')
+ if number-context > 2:
+ lines.append(u'<span class="ellipses">...</span>')
+
+ for i in context_left:
+ lines.append(u'<a class="prev number" href="?page=%d">%d</a>' % (i, i))
+
+ lines.append(u'<span class="current number">%d</span>' % (number,))
+
+ if page_obj.has_next():
+ for i in context_right:
+ lines.append(u'<a class="next number" href="?page=%d">%d</a>' % (i, i))
+
+ return mark_safe(u'\n'.join(lines))
diff --git a/sweettooth/extensions/urls.py b/sweettooth/extensions/urls.py
index 218d289..b3db280 100644
--- a/sweettooth/extensions/urls.py
+++ b/sweettooth/extensions/urls.py
@@ -27,6 +27,7 @@ shell_patterns = patterns('',
urlpatterns = patterns('',
url(r'^$', object_list, dict(queryset=models.Extension.objects.visible(),
+ paginate_by=10,
template_object_name='extension',
template_name='extensions/list.html'),
name='extensions-index'),
diff --git a/sweettooth/static/css/sweettooth.css b/sweettooth/static/css/sweettooth.css
index 30842a8..3f0ab7c 100644
--- a/sweettooth/static/css/sweettooth.css
+++ b/sweettooth/static/css/sweettooth.css
@@ -146,6 +146,33 @@ hr.bottom_shadow {
transform: rotate(180deg);
}
+#paginator {
+ display: block;
+ background-color: #ddd;
+ border-radius: 8px;
+ padding: 2px;
+}
+
+#paginator .number {
+ display: inline-block;
+ width: 1.5em;
+ text-align: center;
+ margin: 0 4px;
+}
+
+#paginator .number:first-child {
+ margin-left: 0;
+}
+
+#paginator .number:last-child {
+ margin-right: 0;
+}
+
+#paginator .number.current {
+ background-color: white;
+ border-radius: 6px;
+}
+
/* Extension view */
/* ==================================================================== */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]