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)
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):
from nose import SkipTest
raise SkipTest
@ -742,6 +739,9 @@ class TestSearchSuggestions(TestAjaxSearch):
self.search_addons('q=add', 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):
personas = (Addon.objects.reviewed()
.filter(type=amo.ADDON_PERSONA, disabled_by_user=False))

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

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