[extensions-web] Add secret list view sorting capability
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Add secret list view sorting capability
- Date: Tue, 6 Dec 2011 03:26:42 +0000 (UTC)
commit 11971fd27d03c4c78ba7189e910b534d867ad000
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Dec 5 22:26:29 2011 -0500
Add secret list view sorting capability
sweettooth/extensions/urls.py | 6 +-----
sweettooth/extensions/views.py | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/sweettooth/extensions/urls.py b/sweettooth/extensions/urls.py
index 46ec7db..ff55693 100644
--- a/sweettooth/extensions/urls.py
+++ b/sweettooth/extensions/urls.py
@@ -35,11 +35,7 @@ shell_patterns = patterns('',
)
urlpatterns = patterns('',
- url(r'^$', object_list, dict(queryset=models.Extension.objects.visible().order_by('name'),
- paginate_by=10,
- template_object_name='extension',
- template_name='extensions/list.html'),
- name='extensions-index'),
+ url(r'^$', views.extensions_list, name='extensions-index'),
url(r'^about/$', direct_to_template, dict(template='extensions/about.html'), name='extensions-about'),
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index cccd50d..e4b5de3 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -1,4 +1,5 @@
+from django.core.paginator import Paginator, InvalidPage
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from django.contrib import messages
@@ -89,6 +90,36 @@ def build_shell_version_map(versions):
return shell_version_map
+def extensions_list(request):
+ queryset = models.Extension.objects.visible()
+ if request.GET.get('sort', '') == 'recent':
+ queryset = queryset.order_by('-pk')
+ else:
+ queryset = queryset.order_by('name')
+
+ paginator = Paginator(queryset, 10)
+ if not page:
+ page = request.GET.get('page', 1)
+ try:
+ page_number = int(page)
+ except ValueError:
+ if page == 'last':
+ page_number = paginator.num_pages
+ else:
+ # Page is not 'last', nor can it be converted to an int.
+ raise Http404()
+ try:
+ page_obj = paginator.page(page_number)
+ except InvalidPage:
+ raise Http404()
+
+ context = dict(paginator=paginator,
+ page_obj=page_obj,
+ is_paginated=page_obj.has_other_pages(),
+ extension_list=page_obj.object_list)
+
+ return render(request, 'extensions/list.html', context)
+
@model_view(models.Extension)
def extension_view(request, obj, **kwargs):
extension, versions = obj, obj.visible_versions
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]