add in android APP (bug 719592)

This commit is contained in:
Andy McKay 2012-01-23 14:03:44 -08:00
Родитель 40c76bead2
Коммит a4aa153d41
7 изменённых файлов: 59 добавлений и 12 удалений

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

@ -12,11 +12,11 @@
{% endif %}
<hgroup>
<h1 class="site-title">
{% set appicon = 'firefox' if request.APP == amo.MOBILE else request.APP.short %}
{% set appicon = 'firefox' if request.APP in (amo.MOBILE, amo.ANDROID) else request.APP.short %}
<a href="{{ url('home') }}"
title="{{ _('Return to the {0} Add-ons homepage')|f(request.APP.pretty) }}">
<img alt="{{ request.APP.pretty }}" src="{{ media('img/zamboni/app_icons/' + appicon + '.png') }}">
{{ _('Mobile Add-ons') }}
{{ _('{0} Add-ons')|f(request.APP.pretty) }}
</a>
</h1>
<h2>{{ _('Easy ways to personalize.') }}</h2>

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

@ -32,6 +32,8 @@ class MiddlewareTest(test.TestCase):
# /admin doesn't get an app.
'/developers': '/en-US/developers',
'/android': '/en-US/android/',
}
for path, location in redirections.items():
@ -93,6 +95,11 @@ class MiddlewareTest(test.TestCase):
# SeaMonkey gets priority because it has both strings in its UA...
check('/en-US/', '/en-US/seamonkey/', 'Firefox SeaMonkey')
# Android can found by its user agent.
check('/en-US/', '/en-US/android/', 'Fennec/12')
check('/en-US/', '/en-US/android/', 'Fennec/11.0')
check('/en-US/', '/en-US/mobile/', 'Fennec/10.9')
def test_get_lang(self):
def check(url, expected):
response = self.process(url)

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

@ -222,6 +222,7 @@ class TestCommon(amo.tests.TestCase):
title_eq('/firefox', 'Firefox', 'Add-ons')
title_eq('/thunderbird', 'Thunderbird', 'Add-ons')
title_eq('/mobile', 'Mobile', 'Mobile Add-ons')
title_eq('/android', 'Android', 'Android Add-ons')
def test_xenophobia(self):
r = self.client.get(self.url, follow=True)

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

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
#-*- coding: utf-8 -*-
import hashlib
import urllib
from threading import local
@ -106,7 +106,7 @@ class Prefixer(object):
ua = self.request.META.get('HTTP_USER_AGENT')
if ua:
for app in amo.APP_DETECT:
if app.user_agent_string in ua:
if app.matches_user_agent(ua):
return app.short
return settings.DEFAULT_APP

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

@ -4,8 +4,14 @@ from tower import ugettext_lazy as _
from base import *
class App:
@classmethod
def matches_user_agent(cls, user_agent):
return cls.user_agent_string in user_agent
# Applications
class FIREFOX:
class FIREFOX(App):
id = 1
shortername = 'fx'
short = 'firefox'
@ -22,7 +28,7 @@ class FIREFOX:
platforms = 'desktop' # DESKTOP_PLATFORMS (set in constants.platforms)
class THUNDERBIRD:
class THUNDERBIRD(App):
id = 18
short = 'thunderbird'
shortername = 'tb'
@ -36,7 +42,7 @@ class THUNDERBIRD:
platforms = 'desktop' # DESKTOP_PLATFORMS (set in constants.platforms)
class SEAMONKEY:
class SEAMONKEY(App):
id = 59
short = 'seamonkey'
shortername = 'sm'
@ -52,7 +58,7 @@ class SEAMONKEY:
platforms = 'desktop' # DESKTOP_PLATFORMS (set in constants.platforms)
class SUNBIRD:
class SUNBIRD(App):
id = 52
short = 'sunbird'
shortername = 'sb'
@ -66,7 +72,7 @@ class SUNBIRD:
platforms = 'desktop' # DESKTOP_PLATFORMS (set in constants.platforms)
class MOBILE:
class MOBILE(App):
id = 60
short = 'mobile'
shortername = 'fn'
@ -80,7 +86,31 @@ class MOBILE:
platforms = 'mobile' # DESKTOP_PLATFORMS (set in constants.platforms)
class MOZILLA:
class ANDROID(App):
# This is for the Android native Firefox.
id = 61
short = 'android'
shortername = 'an'
pretty = _(u'Android')
browser = True
types = [ADDON_EXTENSION, ADDON_DICT, ADDON_SEARCH,
ADDON_LPAPP, ADDON_PERSONA]
guid = '{aa3c5121-dab2-40e2-81ca-7ea25febc110}'
min_display_version = 11.0
user_agent_string = 'Fennec'
# Mobile and Android have the same user agent. The only way to distinguish
# is by the version number.
user_agent_re = re.compile('Fennec/([\d.]+)')
platforms = 'mobile'
@classmethod
def matches_user_agent(cls, user_agent):
match = cls.user_agent_re.search(user_agent)
if match:
return cls.min_display_version <= float(match.groups()[0])
class MOZILLA(App):
"""Mozilla exists for completeness and historical purposes.
Stats and other modules may reference this for history.
@ -97,8 +127,9 @@ class MOZILLA:
platforms = 'desktop' # DESKTOP_PLATFORMS (set in constants.platforms)
# UAs will attempt to match in this order
APP_DETECT = (MOBILE, THUNDERBIRD, SEAMONKEY, SUNBIRD, FIREFOX)
APP_USAGE = _apps = (FIREFOX, THUNDERBIRD, MOBILE, SEAMONKEY, SUNBIRD)
APP_DETECT = (ANDROID, MOBILE, THUNDERBIRD, SEAMONKEY, SUNBIRD, FIREFOX)
APP_USAGE = _apps = (FIREFOX, THUNDERBIRD, ANDROID,
MOBILE, SEAMONKEY, SUNBIRD)
APPS = dict((app.short, app) for app in _apps)
APP_IDS = dict((app.id, app) for app in _apps)
APP_GUIDS = dict((app.guid, app) for app in _apps)

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

@ -0,0 +1,6 @@
from applications.models import Application
def run():
Application.objects.create(id=61,
guid='{aa3c5121-dab2-40e2-81ca-7ea25febc110}')

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

@ -15,6 +15,8 @@
{{ heading('SeaMonkey', _('Add-ons'), 'seamonkey') }}
{% elif request.APP == amo.SUNBIRD %}
{{ heading('Sunbird', _('Add-ons'), 'sunbird') }}
{% elif request.APP == amo.ANDROID %}
{{ heading('Android', _('Android Add-ons'), 'firefox') }}
{% else %}
{{ heading('', _('Add-ons'), 'generic') }}
{% endif %}