From ac8298b3e5401449aa7a9cff56d7db4722df1f52 Mon Sep 17 00:00:00 2001 From: Jeff Balogh Date: Tue, 3 Aug 2010 16:45:33 -0700 Subject: [PATCH] collections directory (bug 574292) --- apps/bandwagon/helpers.py | 8 +++ .../bandwagon/collection_listing.html | 72 +++++++++++++++++++ .../bandwagon/collection_listing_items.html | 29 ++++++++ apps/bandwagon/views.py | 26 ++++++- migrations/62-collections-idx.sql | 4 ++ 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 apps/bandwagon/templates/bandwagon/collection_listing.html create mode 100644 apps/bandwagon/templates/bandwagon/collection_listing_items.html create mode 100644 migrations/62-collections-idx.sql diff --git a/apps/bandwagon/helpers.py b/apps/bandwagon/helpers.py index c89845911c..0a7e09982d 100644 --- a/apps/bandwagon/helpers.py +++ b/apps/bandwagon/helpers.py @@ -8,6 +8,14 @@ from amo.helpers import login_link from cake.urlresolvers import remora_url +@register.inclusion_tag('bandwagon/collection_listing_items.html') +@jinja2.contextfunction +def collection_listing_items(context, collections): + c = dict(context.items()) + c['collections'] = collections + return c + + @register.function def user_collection_list(collections=[], heading=''): """list of collections, as used on the user profile page""" diff --git a/apps/bandwagon/templates/bandwagon/collection_listing.html b/apps/bandwagon/templates/bandwagon/collection_listing.html new file mode 100644 index 0000000000..3671a15cd8 --- /dev/null +++ b/apps/bandwagon/templates/bandwagon/collection_listing.html @@ -0,0 +1,72 @@ +{% extends "base.html" %} + +{% set titles = { + 'featured': _('Featured Collections'), + 'popular': _('Popular Collections'), + 'rating': _('Highest Rated Collections'), + 'created': _('Recently Added Collections'), +} %} +{% set base_url = url('collections.list') %} + +{% block title %}{{ page_title(titles[filter.field]) }}{% endblock %} + +{% block extrahead %}{{ category_arrow(filter.field, prefix='p') }}{% endblock %} + +{% block content %} +
+
+ {{ breadcrumbs([(base_url, _('Collections')), + (None, filter.title)]) }} +

{{ titles[filter.field] }}

+
+ +
+ +
+
+

{{ _('Collections') }}

+
    + {% for key, title in filter.opts %} +
  • + {{ title }} +
  • + {% endfor %} +
+ {% if request.user.is_authenticated() %} + + {% endif %} +
+ +
+

{{ _('Create a New Collection') }}

+

{% trans %} + Collections make it easy to keep track of favorite add-ons and share your + perfectly customized browser with others. + {% endtrans %}

+ + {{ _('Create a Collection') }} +
+ +
+

{{ _('Add-on Collector') }}

+

{% trans app=request.APP.pretty %} + Get updates on watched collections or manage your own collections directly + from {{ app }} with this add-on. + {% endtrans %}

+ + {{ _('Check out Add-on Collector') }} +
+
+{% endblock %} diff --git a/apps/bandwagon/templates/bandwagon/collection_listing_items.html b/apps/bandwagon/templates/bandwagon/collection_listing_items.html new file mode 100644 index 0000000000..33e2d52323 --- /dev/null +++ b/apps/bandwagon/templates/bandwagon/collection_listing_items.html @@ -0,0 +1,29 @@ +{% for c in collections %} +
+
+
    +
  • {{ barometer(c) }}
  • +
  • + {# L10n: People "watch" collections to get notified of updates. + Like Twitter followers. #} + {% trans cnt=c.subscribers, num=c.subscribers|numberfmt %} + {{ num }} watcher + {% pluralize %} + {{ num }} watchers + {% endtrans %} +
  • +
  • + {{ _('Updated {0}')|f(c.modified|datetime) }} +
  • +
+
+

+ + + {{ c.name }} + + {{ _('by {0}')|f(c.author|user_link)|safe }} +

+
{{ c.description }}
+
+{% endfor %} diff --git a/apps/bandwagon/views.py b/apps/bandwagon/views.py index e85698bfa5..e3566f6cd6 100644 --- a/apps/bandwagon/views.py +++ b/apps/bandwagon/views.py @@ -1,4 +1,5 @@ from django import http +from django.db.models import Q from django.shortcuts import get_object_or_404, redirect import jingo @@ -23,8 +24,31 @@ def legacy_redirect(self, uuid): return redirect(c.get_url_path()) +class CollectionFilter(BaseFilter): + opts = (('featured', _lazy('Featured')), + ('popular', _lazy('Popular')), + ('rating', _lazy('Highest Rated')), + ('created', _lazy('Recently Added'))) + + def filter(self, field): + qs = self.base_queryset + if field == 'featured': + return qs.filter(type=amo.COLLECTION_FEATURED) + elif field == 'followers': + return qs.order_by('-weekly_subscribers') + elif field == 'rating': + return qs.order_by('-rating') + else: + return qs.order_by('-created') + + def collection_listing(request): - return http.HttpResponse() + app = Q(application=request.APP.id) | Q(application=None) + base = Collection.objects.listed().filter(app) + filter = CollectionFilter(request, base, key='sort', default='popular') + collections = amo.utils.paginate(request, filter.qs) + return jingo.render(request, 'bandwagon/collection_listing.html', + {'collections': collections, 'filter': filter}) def user_listing(request, username): diff --git a/migrations/62-collections-idx.sql b/migrations/62-collections-idx.sql new file mode 100644 index 0000000000..44a80b6599 --- /dev/null +++ b/migrations/62-collections-idx.sql @@ -0,0 +1,4 @@ +CREATE INDEX type_idx ON collections (collection_type); +CREATE INDEX watcher_idx ON collections (weekly_subscribers); +CREATE INDEX rating_idx ON collections (rating); +CREATE INDEX created_idx ON collections (created);