Skip to content

Commit

Permalink
Merge pull request #1458 from kyoshino/bug-922373-footer-social
Browse files Browse the repository at this point in the history
Fix Bug 921833 and 922373, footer social links
  • Loading branch information
jgmize committed Dec 19, 2013
2 parents 5c482c8 + 73146db commit 7c58b1d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
6 changes: 4 additions & 2 deletions bedrock/base/templates/base-resp.html
Expand Up @@ -138,8 +138,10 @@ <h2><a href="{{ url('mozorg.home') }}"><img src="{{ MEDIA_URL }}img/sandstone/he
</ul>
{% block social %}
<ul class="footer-nav">
<li><a href="https://twitter.com/firefox">{{_('Twitter')}}</a></li>
<li><a href="https://facebook.com/Firefox">{{_('Facebook')}}</a></li>
<li><a href="https://twitter.com/mozilla">{{_('Mozilla on Twitter')}}</a></li>
<li><a href="{{ firefox_twitter_url() }}">{{_('Firefox on Twitter')}}</a></li>
<li><a href="https://www.facebook.com/mozilla">{{_('Mozilla on Facebook')}}</a></li>
<li><a href="https://www.facebook.com/Firefox">{{_('Firefox on Facebook')}}</a></li>
<li><a href="https://affiliates.mozilla.org/">{{_('Firefox Affiliates')}}</a></li>
</ul>
{% endblock %}
Expand Down
6 changes: 4 additions & 2 deletions bedrock/base/templates/base.html
Expand Up @@ -127,8 +127,10 @@ <h2><a href="{{ url('mozorg.home') }}"><img src="{{ MEDIA_URL }}img/sandstone/he

{% block social %}
<ul class="footer-nav">
<li><a href="https://twitter.com/firefox">{{_('Twitter')}}</a></li>
<li><a href="https://facebook.com/Firefox">{{_('Facebook')}}</a></li>
<li><a href="https://twitter.com/mozilla">{{_('Mozilla on Twitter')}}</a></li>
<li><a href="{{ firefox_twitter_url() }}">{{_('Firefox on Twitter')}}</a></li>
<li><a href="https://www.facebook.com/mozilla">{{_('Mozilla on Facebook')}}</a></li>
<li><a href="https://www.facebook.com/Firefox">{{_('Firefox on Facebook')}}</a></li>
<li><a href="https://affiliates.mozilla.org/">{{_('Firefox Affiliates')}}</a></li>
</ul>
{% endblock %}
Expand Down
37 changes: 37 additions & 0 deletions bedrock/mozorg/helpers/misc.py
Expand Up @@ -313,6 +313,43 @@ def donate_url(ctx):
return settings.DONATE_LOCALE_LINK[locale]


@jingo.register.function
@jinja2.contextfunction
def firefox_twitter_url(ctx):
"""Output a link to Twitter taking locales into account.
Uses the locale from the current request. Checks to see if we have
a Twitter account that match this locale, returns the localized account
url or falls back to the US account url if not.
Examples
========
In Template
-----------
{{ firefox_twitter_url() }}
For en-US this would output:
https://twitter.com/firefox
For es-ES this would output:
https://twitter.com/firefox_es
For pt-BR this would output:
https://twitter.com/firefoxbrasil
"""
locale = getattr(ctx['request'], 'locale', 'en-US')
if locale not in settings.FIREFOX_TWITTER_ACCOUNTS:
locale = 'en-US'

return settings.FIREFOX_TWITTER_ACCOUNTS[locale]


@jingo.register.filter
def absolute_url(url):
"""
Expand Down
39 changes: 39 additions & 0 deletions bedrock/mozorg/tests/test_helper_misc.py
Expand Up @@ -27,6 +27,12 @@
'pt-BR': 'https://sendto.mozilla.org/page/contribute/EOYFR2013-webPTBR',
}

TEST_FIREFOX_TWITTER_ACCOUNTS = {
'en-US': 'https://twitter.com/firefox',
'es-ES': 'https://twitter.com/firefox_es',
'pt-BR': 'https://twitter.com/firefoxbrasil',
}


# Where should this function go?
def render(s, context=None):
Expand Down Expand Up @@ -393,6 +399,39 @@ def test_donate_url_other_locale(self):
'https://sendto.mozilla.org/page/contribute/EOYFR2013-tabzilla')


@override_settings(FIREFOX_TWITTER_ACCOUNTS=TEST_FIREFOX_TWITTER_ACCOUNTS)
class TestFirefoxTwitterUrl(TestCase):
rf = RequestFactory()

def _render(self, locale):
req = self.rf.get('/')
req.locale = locale
return render('{{ firefox_twitter_url() }}', {'request': req})

def test_firefox_twitter_url_no_locale(self):
"""No locale, fallback to default account"""
eq_(self._render(''), 'https://twitter.com/firefox')

def test_firefox_twitter_url_english(self):
"""en-US locale, default account"""
eq_(self._render('en-US'), 'https://twitter.com/firefox')

def test_firefox_twitter_url_spanish(self):
"""es-ES locale, a local account"""
eq_(self._render('es-ES'), 'https://twitter.com/firefox_es')

def test_firefox_twitter_url_portuguese(self):
"""pt-BR locale, a local account"""
eq_(self._render('pt-BR'), 'https://twitter.com/firefoxbrasil')

def test_firefox_twitter_url_other_locale(self):
"""No account for locale, fallback to default account"""
eq_(self._render('es-AR'), 'https://twitter.com/firefox')
eq_(self._render('es-CL'), 'https://twitter.com/firefox')
eq_(self._render('es-MX'), 'https://twitter.com/firefox')
eq_(self._render('pt-PT'), 'https://twitter.com/firefox')


class TestHighResImg(TestCase):
rf = RequestFactory()

Expand Down
7 changes: 7 additions & 0 deletions bedrock/settings/base.py
Expand Up @@ -882,6 +882,13 @@ def facebook_tab_url_lazy():
'pt-BR': 'https://sendto.mozilla.org/page/contribute/EOYFR2013-webPTBR',
}

# Official Firefox Twitter accounts
FIREFOX_TWITTER_ACCOUNTS = {
'en-US': 'https://twitter.com/firefox',
'es-ES': 'https://twitter.com/firefox_es',
'pt-BR': 'https://twitter.com/firefoxbrasil',
}

# Mapbox token for spaces and communities pages
MAPBOX_TOKEN = 'examples.map-9ijuk24y'

Expand Down

0 comments on commit 7c58b1d

Please sign in to comment.