From a57f814d636e57820fed1f4d07098fc761a28a99 Mon Sep 17 00:00:00 2001 From: Fred Wenzel Date: Tue, 9 Nov 2010 15:02:57 -0800 Subject: [PATCH] Keep mobile dashboard from crashing on nameless locale. Bug 609339. --- .../templates/dashboard/mobile/locales.html | 2 +- apps/dashboard/tests.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/templates/dashboard/mobile/locales.html b/apps/dashboard/templates/dashboard/mobile/locales.html index 96842baf..48aae7a5 100644 --- a/apps/dashboard/templates/dashboard/mobile/locales.html +++ b/apps/dashboard/templates/dashboard/mobile/locales.html @@ -1,5 +1,5 @@ {% macro locale_item(locale, count=0, selected=False) %} - {{ mobile_bar(name='locale', id='loc_'+locale, + {{ mobile_bar(name='locale', id='loc_%s' % locale, value=locale|default('unknown', True), selected=selected, count=count, total=opinion_count, label=locale_name(locale)) }} diff --git a/apps/dashboard/tests.py b/apps/dashboard/tests.py index 7ce9c916..8914c7bc 100644 --- a/apps/dashboard/tests.py +++ b/apps/dashboard/tests.py @@ -48,3 +48,21 @@ class TestOS(object): # No error, please. tpl = render_template('dashboard/mobile/platforms.html', ctx) assert tpl.find('id="os_None"') >= 0 + + def test_locale_none(self): + """Test that locale with no name does not crash locale helper.""" + + class TestLocale(object): + """Test locale with no name.""" + locale = None + count = 10 + + ctx = { + 'defaults': {'locale': None}, + 'locales': (TestLocale(),), + 'opinion_count': 20 + } + + # No error, please. + tpl = render_template('dashboard/mobile/locales.html', ctx) + assert tpl.find('id="loc_None"') >= 0