fix search within personas/collections (bug 617038)
This commit is contained in:
Родитель
a947215b4b
Коммит
277cda97c6
|
@ -111,14 +111,10 @@ def language_tools(request, category=None):
|
|||
addons = (Addon.objects.public()
|
||||
.filter(appsupport__app=request.APP.id, type__in=types,
|
||||
target_locale__isnull=False).exclude(target_locale=''))
|
||||
|
||||
locales = _get_locales(addons)
|
||||
|
||||
search_cat = '%s,0' % amo.ADDON_DICT
|
||||
|
||||
return jingo.render(request, 'browse/language_tools.html',
|
||||
{'locales': locales, 'addons': addons,
|
||||
'search_cat': search_cat})
|
||||
'search_cat': '%s,0' % amo.ADDON_DICT})
|
||||
|
||||
|
||||
def themes(request, category=None):
|
||||
|
@ -137,16 +133,12 @@ def themes(request, category=None):
|
|||
|
||||
count = addons.with_index(addons='type_status_inactive_idx').count()
|
||||
themes = amo.utils.paginate(request, addons, count=count)
|
||||
|
||||
# Pre-selected category for search form
|
||||
search_cat = '%s,0' % amo.ADDON_THEME
|
||||
|
||||
return jingo.render(request, 'browse/themes.html',
|
||||
{'categories': categories,
|
||||
'themes': themes, 'category': category,
|
||||
'sorting': filter.field,
|
||||
'sort_opts': filter.opts,
|
||||
'search_cat': search_cat})
|
||||
'search_cat': '%s,0' % amo.ADDON_THEME})
|
||||
|
||||
|
||||
def extensions(request, category=None):
|
||||
|
@ -166,9 +158,7 @@ def extensions(request, category=None):
|
|||
|
||||
count = addons.with_index(addons='type_status_inactive_idx').count()
|
||||
addons = amo.utils.paginate(request, addons, count=count)
|
||||
|
||||
search_cat = '%s,%s' % (TYPE, category.id if category else 0)
|
||||
|
||||
return jingo.render(request, 'browse/extensions.html',
|
||||
{'category': category, 'addons': addons,
|
||||
'sorting': filter.field,
|
||||
|
@ -198,12 +188,9 @@ def category_landing(request, category):
|
|||
.filter(categories__id=category.id))
|
||||
filter = CategoryLandingFilter(request, base, category,
|
||||
key='browse', default='featured')
|
||||
|
||||
search_cat = '%s,%s' % (category.type, category.id)
|
||||
|
||||
return jingo.render(request, 'browse/category_landing.html',
|
||||
{'category': category, 'filter': filter,
|
||||
'search_cat': search_cat})
|
||||
'search_cat': '%s,%s' % (category.type, category.id)})
|
||||
|
||||
|
||||
def creatured(request, category):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{% set search_form = SearchForm(request) %}
|
||||
{% set search_form = SimpleSearchForm(request, None) %}
|
||||
<form action="{{ remora_url('/developers/search') }}" method="get">
|
||||
<span class="wrap">
|
||||
<input type="text" name="q"
|
||||
<input type="text" name="q" required
|
||||
class="text {% if not search_form.q.data %}placeholder{% endif %}"
|
||||
value="{{ search_form.q.data or '' }}" required="required"
|
||||
value="{{ search_form.q.data or '' }}"
|
||||
placeholder="{{ _('Search developer documentation') }}">
|
||||
</span> {# search-query #}
|
||||
<input type="image" class="submit go-button" src="{{ settings.MEDIA_URL }}img/zamboni/global/btn-search.png" title="{{ _('Search') }}" alt="{{ _('Search') }}" />
|
||||
<input type="image" class="submit go-button" src="{{ settings.MEDIA_URL }}img/zamboni/global/btn-search.png" title="{{ _('Search') }}">
|
||||
</form>
|
|
@ -92,13 +92,33 @@ def get_search_groups(app):
|
|||
return top_level[:1] + sub + top_level[1:], top_level
|
||||
|
||||
|
||||
SEARCH_CHOICES = (
|
||||
('all', _lazy('search for add-ons')),
|
||||
('collections', _lazy('search for collections')),
|
||||
('personas', _lazy('search for personas')))
|
||||
|
||||
|
||||
class SimpleSearchForm(forms.Form):
|
||||
"""Powers the search box on every page."""
|
||||
q = forms.CharField(required=False)
|
||||
cat = forms.CharField(required=False, widget=forms.HiddenInput)
|
||||
choices = dict(SEARCH_CHOICES)
|
||||
|
||||
def clean_cat(self):
|
||||
self.data = dict(self.data.items())
|
||||
return self.data.setdefault('cat', 'all')
|
||||
|
||||
def placeholder(self):
|
||||
val = self.clean_cat()
|
||||
return self.choices.get(val, self.choices['all'])
|
||||
|
||||
|
||||
def SearchForm(request):
|
||||
|
||||
current_app = request.APP or amo.FIREFOX
|
||||
search_groups, top_level = get_search_groups(current_app)
|
||||
|
||||
class _SearchForm(forms.Form):
|
||||
q = forms.CharField(required=False)
|
||||
class _SearchForm(SimpleSearchForm):
|
||||
|
||||
cat = forms.ChoiceField(choices=search_groups, required=False)
|
||||
|
||||
|
|
|
@ -8,8 +8,11 @@ from . import forms
|
|||
|
||||
|
||||
@jingo.register.function
|
||||
def SearchForm(request):
|
||||
return forms.SearchForm(request)
|
||||
def SimpleSearchForm(request, search_cat):
|
||||
data = request.GET
|
||||
if search_cat and 'cat' not in request.GET:
|
||||
data = dict(request.GET, cat=search_cat)
|
||||
return forms.SimpleSearchForm(data)
|
||||
|
||||
|
||||
@jingo.register.function
|
||||
|
|
|
@ -309,3 +309,27 @@ class TagTest(SphinxTestCase):
|
|||
r = self.client.get(url, follow=True)
|
||||
new_related_tags = pq(r.content)('#refine-tags li a').text()
|
||||
assert old_related_tags != new_related_tags
|
||||
|
||||
|
||||
class TestSearchboxTarget(test_utils.TestCase):
|
||||
# Check that we search within addons/personas/collections as appropriate.
|
||||
|
||||
def check(self, url, placeholder, cat):
|
||||
doc = pq(self.client.get(url).content)('.header-search form')
|
||||
eq_(doc('input[name=q]').attr('placeholder'), placeholder)
|
||||
eq_(doc('input[name=cat]').val(), cat)
|
||||
|
||||
def test_addons_is_default(self):
|
||||
self.check(reverse('home'), 'search for add-ons', 'all')
|
||||
|
||||
def test_themes(self):
|
||||
self.check(reverse('browse.themes'), 'search for add-ons',
|
||||
'%s,0' % amo.ADDON_THEME)
|
||||
|
||||
def test_collections(self):
|
||||
self.check(reverse('collections.list'), 'search for collections',
|
||||
'collections')
|
||||
|
||||
def test_personas(self):
|
||||
self.check(reverse('browse.personas'), 'search for personas',
|
||||
'personas')
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
{% set search_form = SearchForm(request) %}
|
||||
<form action="{{ url('search.search') }}" method="get">
|
||||
{% set search_form = SimpleSearchForm(request, search_cat) %}
|
||||
<form action="{{ url('search.search') }}">
|
||||
<span class="wrap">
|
||||
<input type="text" name="q"
|
||||
<input type="text" name="q" required
|
||||
class="text {% if not search_form.q.data %}placeholder{% endif %}"
|
||||
placeholder="{{ _('search for add-ons') }}"
|
||||
value="{{ search_form.q.data or '' }}" required="required">
|
||||
placeholder="{{ search_form.placeholder() }}"
|
||||
value="{{ search_form.q.data or '' }}">
|
||||
{{ search_form.cat|safe }}
|
||||
</span>
|
||||
<input type="image" class="submit" src="{{ settings.MEDIA_URL }}img/zamboni/global/btn-search.png" title="{{ _('Search') }}" alt="{{ _('Search') }}" />
|
||||
<input type="image" class="submit" src="{{ settings.MEDIA_URL }}img/zamboni/global/btn-search.png" title="{{ _('Search') }}">
|
||||
</form>
|
Загрузка…
Ссылка в новой задаче