зеркало из https://github.com/mozilla/kitsune.git
Merge branch '559095-search' into development
This commit is contained in:
Коммит
a5b850a05f
|
@ -193,6 +193,13 @@ class SearchTest(SphinxTestCase):
|
|||
results = wc.query('', filter)
|
||||
self.assertEquals(1, len(results))
|
||||
|
||||
def test_search_en_locale(self):
|
||||
"""Searches from the en-US locale should return documents from en."""
|
||||
c = client.Client()
|
||||
qs = {'q': 'contribute', 'w': 1, 'format': 'json', 'category': 23}
|
||||
response = c.get(reverse('search'), qs)
|
||||
self.assertNotEquals(0, json.loads(response.content)['total'])
|
||||
|
||||
|
||||
def test_sphinx_down():
|
||||
"""
|
||||
|
|
|
@ -18,6 +18,7 @@ from sumo.models import ForumThread, WikiPage, Forum, Category
|
|||
from .clients import ForumClient, WikiClient, SearchError
|
||||
from .utils import crc32
|
||||
import search as constants
|
||||
from sumo_locales import LOCALES
|
||||
|
||||
|
||||
def jsonp_is_valid(func):
|
||||
|
@ -32,8 +33,11 @@ def search(request):
|
|||
# set up query variables
|
||||
q = request.GET.get('q', '')
|
||||
|
||||
locale = request.GET.get('locale', request.locale)
|
||||
language = request.GET.get('language', locale)
|
||||
language = request.GET.get('language', request.locale)
|
||||
if language in LOCALES:
|
||||
language = LOCALES[language].internal
|
||||
else:
|
||||
language = LOCALES[settings.LANGUAGE_CODE].internal
|
||||
|
||||
search_locale = (crc32(language),)
|
||||
|
||||
|
|
|
@ -2,11 +2,17 @@ from django.db import models
|
|||
|
||||
import caching.base
|
||||
|
||||
from sumo.urlresolvers import get_url_prefix
|
||||
from sumo_locales import INTERNAL_MAP
|
||||
|
||||
# Our apps should subclass BaseManager instead of models.Manager or
|
||||
# caching.base.CachingManager directly.
|
||||
ManagerBase = caching.base.CachingManager
|
||||
|
||||
|
||||
reverse = lambda x: get_url_prefix().fix(x)
|
||||
|
||||
|
||||
class ModelBase(caching.base.CachingMixin, models.Model):
|
||||
"""
|
||||
Base class for SUMO models to abstract some common features.
|
||||
|
@ -89,7 +95,8 @@ class Forum(ModelBase):
|
|||
"""
|
||||
TODO: Once we can use reverse(), use reverse()
|
||||
"""
|
||||
return u'/en/forum/%s' % (self.forumId,)
|
||||
|
||||
return reverse(u'/forum/%s' % (self.forumId,))
|
||||
|
||||
|
||||
class ForumThread(ModelBase):
|
||||
|
@ -129,7 +136,8 @@ class ForumThread(ModelBase):
|
|||
"""
|
||||
TODO: Once we can use reverse(), use reverse()
|
||||
"""
|
||||
return u'/en/forum/%s/%s' % (self.object, self.threadId,)
|
||||
|
||||
return reverse(u'/forum/%s/%s' % (self.object, self.threadId,))
|
||||
|
||||
|
||||
class WikiPage(ModelBase):
|
||||
|
@ -174,7 +182,13 @@ class WikiPage(ModelBase):
|
|||
TODO: Once we can use reverse(), use reverse()
|
||||
"""
|
||||
name = self.pageName.replace(' ', '+')
|
||||
return u'/%s/kb/%s' % (self.lang, name,)
|
||||
|
||||
if self.lang in INTERNAL_MAP:
|
||||
lang = INTERNAL_MAP[self.lang]
|
||||
else:
|
||||
lang = self.lang
|
||||
|
||||
return u'/%s/kb/%s' % (lang, name,)
|
||||
|
||||
|
||||
class Category(ModelBase):
|
||||
|
|
|
@ -29,3 +29,8 @@ class TestLocaleMiddleware(TestCase):
|
|||
"""Requests for /fr-FR/search should end up on /fr/search"""
|
||||
reponse = self.client.get('/fr-FR/search', follow=True)
|
||||
self.assertRedirects(reponse, '/fr/search', status_code=301)
|
||||
|
||||
def test_partial_redirect(self):
|
||||
"""Ensure that /en/ gets directed to /en-US/."""
|
||||
response = self.client.get('/en/search', follow=True)
|
||||
self.assertRedirects(response, '/en-US/search', status_code=301)
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
from django import test
|
||||
|
||||
from nose.tools import eq_
|
||||
|
||||
from django import test
|
||||
|
||||
import jingo
|
||||
|
||||
from sumo.models import ForumThread, WikiPage, Forum
|
||||
|
||||
|
||||
def setup():
|
||||
jingo.load_helpers()
|
||||
test.Client().get('/')
|
||||
|
||||
|
||||
class TestForumThreadModel(test.TestCase):
|
||||
fixtures = ['threads.json']
|
||||
|
||||
def test_get_url(self):
|
||||
f = ForumThread.objects.create(pk=12345, object=1)
|
||||
eq_(f.get_url(), '/en/forum/1/12345')
|
||||
eq_(f.get_url(), '/en-US/forum/1/12345')
|
||||
|
||||
|
||||
class TestWikiPage(test.TestCase):
|
||||
|
@ -18,7 +25,7 @@ class TestWikiPage(test.TestCase):
|
|||
|
||||
def test_get_url(self):
|
||||
w = WikiPage.objects.create(pk=1, lang='en', pageName='My Test Page')
|
||||
eq_(w.get_url(), '/en/kb/My+Test+Page')
|
||||
eq_(w.get_url(), '/en-US/kb/My+Test+Page')
|
||||
|
||||
|
||||
class TestForumModel(test.TestCase):
|
||||
|
@ -26,5 +33,5 @@ class TestForumModel(test.TestCase):
|
|||
|
||||
def test_sanity(self):
|
||||
f = Forum.objects.create(pk=12, name='My Test Forum')
|
||||
eq_(f.get_url(), '/en/forum/12')
|
||||
eq_(f.get_url(), '/en-US/forum/12')
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None):
|
|||
|
||||
|
||||
def find_supported(test):
|
||||
return [x for x in settings.LANGUAGE_URL_MAP if
|
||||
return [settings.LANGUAGE_URL_MAP[x] for
|
||||
x in settings.LANGUAGE_URL_MAP if
|
||||
x.split('-', 1)[0] == test.lower().split('-', 1)[0]]
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from collections import namedtuple
|
|||
|
||||
Language = namedtuple(u'Language', u'external internal english native dictionary')
|
||||
|
||||
languages = {
|
||||
LOCALES = {
|
||||
u'af': Language(u'af', u'af', u'Afrikaans', u'Afrikaans', u'af-NA'),
|
||||
u'ak': Language(u'ak', u'ak', u'Akan', u'Akan', u'ak-GH'),
|
||||
u'ast-ES': Language(u'ast-ES', u'ast-ES', u'Asturian', u'Asturianu', u'ast-ES'),
|
||||
|
@ -104,3 +104,5 @@ languages = {
|
|||
u'zh-TW': Language(u'zh-TW', u'zh-TW', u'Chinese (Traditional)', u'正體中文 (繁體)', u'zh-TW'),
|
||||
u'zu': Language(u'zu', u'zu', u'Zulu', u'isiZulu', u'zu'),
|
||||
}
|
||||
|
||||
INTERNAL_MAP = dict([(LOCALES[k].internal, k) for k in LOCALES])
|
||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
|||
|
||||
from tower import ugettext_lazy as _lazy
|
||||
|
||||
import sumo_locales
|
||||
from sumo_locales import LOCALES
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
@ -63,7 +63,7 @@ SUMO_LANGUAGES = (
|
|||
'uk', 'vi', 'zh-CN', 'zh-TW',
|
||||
)
|
||||
|
||||
LANGUAGES = dict([(i.lower(), sumo_locales.languages[i].native)
|
||||
LANGUAGES = dict([(i.lower(), LOCALES[i].native)
|
||||
for i in SUMO_LANGUAGES])
|
||||
|
||||
LANGUAGE_URL_MAP = dict([(i.lower(), i) for i in SUMO_LANGUAGES])
|
||||
|
|
Загрузка…
Ссылка в новой задаче