From 7260a51c24fb479d1f18f049bca81c6371c4c27d Mon Sep 17 00:00:00 2001 From: Jeff Balogh Date: Fri, 27 Aug 2010 16:56:53 -0700 Subject: [PATCH] clean up search pages --- apps/browse/views.py | 15 +++++--- apps/search/templates/search/personas.html | 44 ++++++---------------- apps/search/templates/search/results.html | 9 ++++- apps/search/views.py | 21 +++-------- media/css/main-mozilla.css | 2 +- 5 files changed, 36 insertions(+), 55 deletions(-) diff --git a/apps/browse/views.py b/apps/browse/views.py index 663026e0c7..3913a49160 100644 --- a/apps/browse/views.py +++ b/apps/browse/views.py @@ -247,7 +247,8 @@ class PersonasFilter(BaseFilter): .with_index(personas='personas_movers_idx')) -def personas(request, category=None): +def personas_listing(request, category=None): + # Common pieces using by browse and search. TYPE = amo.ADDON_PERSONA q = Category.objects.filter(application=request.APP.id, type=TYPE) @@ -255,15 +256,17 @@ def personas(request, category=None): base = (Addon.objects.public().filter(type=TYPE) .extra(select={'_app': request.APP.id})) - featured = base & Addon.objects.featured(request.APP) - is_homepage = category is None and 'sort' not in request.GET if category is not None: category = get_object_or_404(q, slug=category) base = base.filter(categories__id=category.id) filter = PersonasFilter(request, base, key='sort', default='up-and-coming') + return categories, filter + +def personas(request, category=None): + categories, filter = personas_listing(request, category) if 'sort' in request.GET: template = 'grid.html' else: @@ -277,13 +280,13 @@ def personas(request, category=None): count = base.with_index(addons='type_status_inactive_idx').count() addons = amo.utils.paginate(request, filter.qs, 30, count=count) - search_cat = 'personas' - + featured = base & Addon.objects.featured(request.APP) + is_homepage = category is None and 'sort' not in request.GET return jingo.render(request, 'browse/personas/' + template, {'categories': categories, 'category': category, 'filter': filter, 'addons': addons, 'featured': featured, 'is_homepage': is_homepage, - 'search_cat': search_cat}) + 'search_cat': 'personas'}) @cache_page(60 * 60 * 24 * 365) diff --git a/apps/search/templates/search/personas.html b/apps/search/templates/search/personas.html index 3833e478f3..6d906d64d2 100644 --- a/apps/search/templates/search/personas.html +++ b/apps/search/templates/search/personas.html @@ -1,34 +1,28 @@ {% extends "base.html" %} +{% from "browse/macros.html" import secondary_categories %} {% block title %} {% if query %} -{{ page_title(_('Personas Search Results for {0}')|f(query)) }} + {{ page_title(_('Personas Search Results for {0}')|f(query)) }} {% else %} -{{ page_title(_('Personas Search Results')) }} + {{ page_title(_('Personas Search Results')) }} {% endif %} {% endblock title %} {% block content %}
-

{{ _('Browse Personas') }}

+
+ {{ breadcrumbs([(None, _('Search'))]) }} +
+

{{ _('Browse Personas') }}

+

{{ showing(query, tag, pager) }}

+
+
-

- {% trans plural=pager.paginator.count, count=pager.paginator.count|numberfmt %} - {{ count }} Persona {% pluralize %} {{ count }} Personas - {% endtrans %} -

- +{{ secondary_categories(_('Personas'), 'browse.personas', categories, filter) }} {% endblock %} diff --git a/apps/search/templates/search/results.html b/apps/search/templates/search/results.html index 87cc2f40e8..0a6c2ee789 100644 --- a/apps/search/templates/search/results.html +++ b/apps/search/templates/search/results.html @@ -1,10 +1,17 @@ {% extends "base.html" %} -{% block title %}{{ page_title(title) }}{% endblock %} +{% block title %} +{% if query %} + {{ page_title(_('Add-on Search Results for {0}')|f(query)) }} +{% else %} + {{ page_title(_('Add-on Search Results')) }} +{% endif %} +{% endblock %} {% block content %}
+ {{ breadcrumbs([(None, _('Search'))]) }}

{{ _('Search Results') }}

{{ showing(query, tag, pager) }}

{% if sort == 'name' %} diff --git a/apps/search/views.py b/apps/search/views.py index 5e1df4aa88..b820fe2295 100644 --- a/apps/search/views.py +++ b/apps/search/views.py @@ -10,6 +10,7 @@ from tower import ugettext as _ import amo import bandwagon.views +import browse.views from amo.decorators import json_view from amo.helpers import urlparams from amo import urlresolvers @@ -172,20 +173,15 @@ def _personas(request): page = form.cleaned_data.get('page') or 1 search_opts['offset'] = (page - 1) * search_opts['limit'] - client = PersonasClient() - - q = Category.objects.filter(application=request.APP.id, - type=amo.ADDON_PERSONA) - categories = order_by_translation(q, 'name') - try: - results = client.query(query, **search_opts) + results = PersonasClient().query(query, **search_opts) except SearchError: return jingo.render(request, 'search/down.html', {}, status=503) pager = amo.utils.paginate(request, results, search_opts['limit']) - - c = dict(pager=pager, form=form, categories=categories) + categories, filter = browse.views.personas_listing(request) + c = dict(pager=pager, form=form, categories=categories, query=query, + filter=filter) return jingo.render(request, 'search/personas.html', c) @@ -238,8 +234,6 @@ def ajax_search(request): def search(request, tag_name=None): - title = _('Search Add-ons') - # If the form is invalid we still want to have a query. query = request.REQUEST.get('q', '') @@ -273,9 +267,6 @@ def search(request, tag_name=None): # Remora dies in a fire. query = form.cleaned_data['q'] - if query: - title = _('Search for %s' % query) - addon_type = form.cleaned_data.get('atype', 0) tag = tag_name if tag_name is not None else form.cleaned_data.get('tag') page = form.cleaned_data['page'] @@ -337,6 +328,6 @@ def search(request, tag_name=None): pager = amo.utils.paginate(request, results, search_opts['limit']) return jingo.render(request, 'search/results.html', { - 'pager': pager, 'title': title, 'query': query, 'tag': tag, + 'pager': pager, 'query': query, 'tag': tag, 'versions': versions, 'categories': categories, 'tags': tags, 'sort_tabs': sort_tabs, 'sort': sort}) diff --git a/media/css/main-mozilla.css b/media/css/main-mozilla.css index 208eed5482..aa7f1cd51b 100644 --- a/media/css/main-mozilla.css +++ b/media/css/main-mozilla.css @@ -2564,7 +2564,7 @@ html[xmlns] .clearfix { } .results-head {width: 100%;} -.results-head h2 { margin-bottom: 0;} +.results-head h2 { margin-bottom: 0; margin-top: 0;} .results-head h3 {margin-top: 0; font-family: "helvetica neue", arial, helvetica, sans-serif; font-weight: normal; color: #444;} .results .item .item-info .downloads {display: block; margin-left: 0px;}