diff --git a/apps/amo/__init__.py b/apps/amo/__init__.py index 9b2d5f90db..89e39b7452 100644 --- a/apps/amo/__init__.py +++ b/apps/amo/__init__.py @@ -222,6 +222,8 @@ class MOZILLA: ADDON_LPAPP, ADDON_PLUGIN] guid = '{86c18b42-e466-45a9-ae7a-9b95ba6f5640}' +# UAs will attempt to match in this order +APP_DETECT = (MOBILE, FIREFOX, THUNDERBIRD, SEAMONKEY, SUNBIRD) APP_USAGE = _apps = (FIREFOX, THUNDERBIRD, MOBILE, SEAMONKEY, SUNBIRD) APPS = dict((app.short, app) for app in _apps) APP_IDS = dict((app.id, app) for app in _apps) diff --git a/apps/amo/tests/test_url_prefix.py b/apps/amo/tests/test_url_prefix.py index 60e28c7253..48f2b93b76 100644 --- a/apps/amo/tests/test_url_prefix.py +++ b/apps/amo/tests/test_url_prefix.py @@ -72,6 +72,9 @@ class MiddlewareTest(test.TestCase): check('/en-US/', '/en-US/firefox/', 'Firefox') check('/de/', '/de/mobile/', 'Fennec') + # Mobile gets priority because it has both strings in its UA... + check('/de/', '/de/mobile/', 'Firefox Fennec') + def test_get_lang(self): def check(url, expected): response = self.process(url) diff --git a/apps/amo/urlresolvers.py b/apps/amo/urlresolvers.py index 9c15d5b652..eb2d693db8 100644 --- a/apps/amo/urlresolvers.py +++ b/apps/amo/urlresolvers.py @@ -100,14 +100,13 @@ class Prefixer(object): Return a valid application string using the User Agent to guess. Falls back to settings.DEFAULT_APP. """ - app = settings.DEFAULT_APP ua = self.request.META.get('HTTP_USER_AGENT') if ua: - for i in amo.APPS.values(): - if i.user_agent_string in ua: - app = i.short + for app in amo.APP_DETECT: + if app.user_agent_string in ua: + return app.short - return app + return settings.DEFAULT_APP def get_language(self): """