fix unicode error in search suggestions (bug 705706)

This commit is contained in:
Chris Van 2011-11-28 09:06:34 -08:00
Родитель 5fb84f41cb
Коммит 40bd7d2cfc
2 изменённых файлов: 18 добавлений и 13 удалений

Просмотреть файл

@ -689,9 +689,6 @@ class TestBaseAjaxSearch(TestAjaxSearch):
Persona.objects.create(persona_id=addon.id, addon_id=addon.id) Persona.objects.create(persona_id=addon.id, addon_id=addon.id)
self.search_addons('q=%s' % addon.id, [addon]) self.search_addons('q=%s' % addon.id, [addon])
def test_ajax_search_char_limit(self):
self.search_addons('q=ad', [])
def test_ajax_search_by_name(self): def test_ajax_search_by_name(self):
from nose import SkipTest from nose import SkipTest
raise SkipTest raise SkipTest
@ -742,6 +739,9 @@ class TestSearchSuggestions(TestAjaxSearch):
self.search_addons('q=add', list(addons)) self.search_addons('q=add', list(addons))
self.search_addons('q=add&cat=all', list(addons)) self.search_addons('q=add&cat=all', list(addons))
def test_unicode(self):
self.search_addons('q=%C2%B2%C2%B2', [])
def test_personas(self): def test_personas(self):
personas = (Addon.objects.reviewed() personas = (Addon.objects.reviewed()
.filter(type=amo.ADDON_PERSONA, disabled_by_user=False)) .filter(type=amo.ADDON_PERSONA, disabled_by_user=False))

Просмотреть файл

@ -286,16 +286,21 @@ class BaseAjaxSearch(object):
def queryset(self): def queryset(self):
"""Get items based on ID or search by name.""" """Get items based on ID or search by name."""
results = [] results = []
if self.key in self.request.GET: q = self.request.GET.get(self.key)
q = self.request.GET[self.key] if q:
if q.isdigit() or (not q.isdigit() and len(q) > 2): pk = None
if q.isdigit(): try:
qs = Addon.objects.filter(id=int(q), pk = int(q)
disabled_by_user=False) except ValueError:
else: pass
# Oh, how I wish I could elastically exclude terms. qs = None
qs = (Addon.search().query(or_=name_only_query(q.lower())) if pk:
.filter(is_disabled=False)) qs = Addon.objects.filter(id=int(q), disabled_by_user=False)
elif len(q) > 2:
# Oh, how I wish I could elastically exclude terms.
qs = (Addon.search().query(or_=name_only_query(q.lower()))
.filter(is_disabled=False))
if qs:
results = qs.filter(type__in=self.types, results = qs.filter(type__in=self.types,
status__in=amo.REVIEWED_STATUSES) status__in=amo.REVIEWED_STATUSES)
return results return results