Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added default field to the browser versions namedtuple. Now default i…

…s independent of order \o/. [bug 661885]
  • Loading branch information...
commit 7db5404403d04f57b2cad8224fada5f2927fe404 1 parent e38803f
@rlr rlr authored
View
37 apps/wiki/models.py
@@ -13,7 +13,6 @@
from pyquery import PyQuery
from tidings.models import NotificationsMixin
from tower import ugettext_lazy as _lazy, ugettext as _
-import waffle
from sumo import ProgrammingError
from sumo_locales import LOCALES
@@ -63,43 +62,48 @@
# the default mobile browser still show. The reverse is true when a page is
# being viewed in a mobile browser.
VersionMetadata = namedtuple('VersionMetadata',
- 'id, name, long, slug, max_version, show_in_ui')
+ 'id, name, long, slug, max_version, show_in_ui, '
+ 'is_default')
GROUPED_FIREFOX_VERSIONS = (
((_lazy(u'Desktop:'), 'desktop'), (
# The first option is the default for {for} display. This should be the
# newest version.
VersionMetadata(6, _lazy(u'Firefox 6'),
- _lazy(u'Firefox 6'), 'fx6', 6.9999, False),
+ _lazy(u'Firefox 6'), 'fx6', 6.9999, False, False),
VersionMetadata(5, _lazy(u'Firefox 5'),
- _lazy(u'Firefox 5'), 'fx5', 5.9999, True),
+ _lazy(u'Firefox 5'), 'fx5', 5.9999, True, False),
VersionMetadata(1, _lazy(u'Firefox 4'),
- _lazy(u'Firefox 4'), 'fx4', 4.9999, True),
+ _lazy(u'Firefox 4'), 'fx4', 4.9999, True, True),
VersionMetadata(2, _lazy(u'Firefox 3.5-3.6'),
- _lazy(u'Firefox 3.5-3.6'), 'fx35', 3.9999, True),
+ _lazy(u'Firefox 3.5-3.6'), 'fx35', 3.9999, True,
+ False),
VersionMetadata(3, _lazy(u'Firefox 3.0'),
- _lazy(u'Firefox 3.0'), 'fx3', 3.4999, False))),
+ _lazy(u'Firefox 3.0'), 'fx3', 3.4999, False, False))),
((_lazy(u'Mobile:'), 'mobile'), (
VersionMetadata(8, _lazy(u'Firefox 6'),
- _lazy(u'Firefox 6 for Mobile'), 'm6', 6.9999, False),
+ _lazy(u'Firefox 6 for Mobile'), 'm6', 6.9999, False,
+ False),
VersionMetadata(7, _lazy(u'Firefox 5'),
- _lazy(u'Firefox 5 for Mobile'), 'm5', 5.9999, True),
+ _lazy(u'Firefox 5 for Mobile'), 'm5', 5.9999, True,
+ False),
VersionMetadata(4, _lazy(u'Firefox 4'),
- _lazy(u'Firefox 4 for Mobile'), 'm4', 4.9999, True),)))
+ _lazy(u'Firefox 4 for Mobile'), 'm4', 4.9999, True,
+ True),)))
# Flattened: # TODO: perhaps use optgroups everywhere instead
FIREFOX_VERSIONS = tuple(chain(*[options for label, options in
GROUPED_FIREFOX_VERSIONS]))
# OSes used to filter articles and declare {for} sections:
-OsMetaData = namedtuple('OsMetaData', 'id, name, slug')
+OsMetaData = namedtuple('OsMetaData', 'id, name, slug, is_default')
GROUPED_OPERATING_SYSTEMS = (
((_lazy(u'Desktop OS:'), 'desktop'), (
- OsMetaData(1, _lazy(u'Windows'), 'win'),
- OsMetaData(2, _lazy(u'Mac OS X'), 'mac'),
- OsMetaData(3, _lazy(u'Linux'), 'linux'))),
+ OsMetaData(1, _lazy(u'Windows'), 'win', True),
+ OsMetaData(2, _lazy(u'Mac OS X'), 'mac', False),
+ OsMetaData(3, _lazy(u'Linux'), 'linux', False))),
((_lazy(u'Mobile OS:'), 'mobile'), (
- OsMetaData(5, _lazy(u'Android'), 'android'),
- OsMetaData(4, _lazy(u'Maemo'), 'maemo'))))
+ OsMetaData(5, _lazy(u'Android'), 'android', True),
+ OsMetaData(4, _lazy(u'Maemo'), 'maemo', False))))
# Flattened
OPERATING_SYSTEMS = tuple(chain(*[options for label, options in
@@ -195,7 +199,6 @@ class Document(NotificationsMixin, ModelBase, BigVocabTaggableMixin):
'and dashboards. When viewed, the page will warn that it is no '
'longer maintained.'))
-
# firefox_versions,
# operating_systems:
# defined in the respective classes below. Use them as in
View
6 apps/wiki/templates/wiki/includes/support_for_selectors.html
@@ -4,8 +4,8 @@
<div>
<select id="os" data-oses="{{ oses_json }}" class="enable-if-js" disabled="disabled">
{% for label, options in oses %}
- {% for _, name, slug in options %}
- <option value="{{ slug }}" data-dependency="{{ label[1] }}">{{ name }}</option>
+ {% for _, name, slug, default in options %}
+ <option value="{{ slug }}" data-dependency="{{ label[1] }}"{% if default %} selected="selected" data-default="true"{% endif %}>{{ name }}</option>
{% endfor %}
{% endfor %}
</select>
@@ -15,7 +15,7 @@
{% for label, options in browsers %}
<optgroup label="{{ label[0] }}">
{% for option in options if option.show_in_ui %}
- <option value="{{ option.slug }}" data-dependency="{{ label[1] }}">{{ option.name }}</option>
+ <option value="{{ option.slug }}" data-dependency="{{ label[1] }}"{% if option.is_default %}{% if label[1] == 'desktop' %} selected="selected"{% endif %} data-default="true"{% endif %}>{{ option.name }}</option>
{% endfor %}
</optgroup>
{% endfor %}
View
7 apps/wiki/tests/test_views.py
@@ -18,11 +18,12 @@ class VersionGroupTests(TestCase):
def test_version_groups(self):
"""Make sure we correctly set up browser/version mappings for the JS"""
versions = [VersionMetadata(1, 'Firefox 4.0', 'Firefox 4.0', 'fx4',
- 5.0, False),
+ 5.0, False, True),
VersionMetadata(2, 'Firefox 3.5-3.6', 'Firefox 3.5-3.6',
- 'fx35', 4.0, False),
+ 'fx35', 4.0, False, False),
VersionMetadata(4, 'Firefox Mobile 1.1',
- 'Firefox Mobile 1.1', 'm11', 2.0, False)]
+ 'Firefox Mobile 1.1', 'm11', 2.0, False,
+ True)]
want = {'fx': [(4.0, '35'), (5.0, '4')],
'm': [(2.0, '11')]}
eq_(want, _version_groups(versions))
View
13 media/js/showfor.js
@@ -62,12 +62,12 @@ var ShowFor = {
$origBrowserOptions = $browserMenu.find('option').clone(),
defaults = {
mobile: {
- browser: $origBrowserOptions.filter('[data-dependency="mobile"]:first').val(),
- os: $osMenu.find('[data-dependency="mobile"]:first').val()
+ browser: $origBrowserOptions.filter('[data-dependency="mobile"][data-default]').val(),
+ os: $osMenu.find('[data-dependency="mobile"][data-default]').val()
},
desktop: {
- browser: $origBrowserOptions.filter('[data-dependency="desktop"]:first').val(),
- os: $osMenu.find('[data-dependency="desktop"]:first').val()
+ browser: $origBrowserOptions.filter('[data-dependency="desktop"][data-default]').val(),
+ os: $osMenu.find('[data-dependency="desktop"][data-default]').val()
}
},
$body = $('body'),
@@ -308,6 +308,9 @@ var ShowFor = {
'[data-dependency="' + currentDependency + '"]');
$browserMenu.empty().append(availableBrowsers);
+ // Set the browser to the default version
+ $browserMenu.val($browserMenu.find('option[data-default]').val());
+
// Set browser to same version (frex, m4->fx4), if possible.
var version = currentBrowser.replace(/^\D+/,'');
$browserMenu.find('option').each(function() {
@@ -345,7 +348,7 @@ var ShowFor = {
function setSelectorDefault($select, dependency) {
$select.val(
$select.find('option:not([data-dependency="' + dependency +
- '"]):first').attr('value'));
+ '"])[data-default]').attr('value'));
}
// If we are on mobile or desktop home page, make sure
View
19 media/js/tests/showfortests.js
@@ -47,7 +47,7 @@ test('windows fx4', function() {
equals(this.$o.val(), 'win', 'Windows is now selected');
equals(this.$b.val(), 'fx4', 'Firefox 4 is now selected');
assertNotHidden(this.$sandbox, ['win', 'not mac', 'android', 'fx35,fx4', 'fx4', 'm4', 'm5']);
- assertNotVisible(this.$sandbox, ['mac,linux', 'maemo', 'fx3', 'fx5']);
+ assertNotVisible(this.$sandbox, ['mac,linux', 'maemo', 'fx3', 'fx5', 'fx6']);
});
test('linux fx35', function() {
@@ -56,7 +56,7 @@ test('linux fx35', function() {
equals(this.$o.val(), 'linux', 'Linux is now selected');
equals(this.$b.val(), 'fx35', 'Firefox 3.5/6 is now selected');
assertNotHidden(this.$sandbox, ['not mac', 'mac,linux', 'android', 'fx35,fx4', 'm4', 'm5']);
- assertNotVisible(this.$sandbox, ['win', 'maemo', 'fx3', 'fx4', 'fx5']);
+ assertNotVisible(this.$sandbox, ['win', 'maemo', 'fx3', 'fx4', 'fx5', 'fx6']);
});
test('mac fx5', function() {
@@ -65,7 +65,16 @@ test('mac fx5', function() {
equals(this.$o.val(), 'mac', 'Mac is now selected');
equals(this.$b.val(), 'fx5', 'Firefox 5 is now selected');
assertNotHidden(this.$sandbox, ['mac,linux', 'android', 'm4', 'fx35,fx4', 'fx4', 'fx5', 'm5']);
- assertNotVisible(this.$sandbox, ['not mac', 'win', 'maemo', 'fx3']);
+ assertNotVisible(this.$sandbox, ['not mac', 'win', 'maemo', 'fx3', 'fx6']);
+});
+
+test('windows fx6', function() {
+ $('#_input_win').click();
+ $('#_input_fx6').click();
+ equals(this.$o.val(), 'win', 'Windows is now selected');
+ equals(this.$b.val(), 'fx6', 'Firefox 6 is now selected');
+ assertNotHidden(this.$sandbox, ['win', 'not mac', 'android', 'fx35,fx4', 'fx4', 'fx5', 'fx6', 'm4', 'm5']);
+ assertNotVisible(this.$sandbox, ['mac,linux', 'maemo', 'fx3']);
});
test('android m4', function() {
@@ -74,7 +83,7 @@ test('android m4', function() {
equals(this.$o.val(), 'android', 'Android is now selected');
equals(this.$b.val(), 'm4', 'Firefox 4 is now selected');
assertNotHidden(this.$sandbox, ['win', 'not mac', 'android', 'm4', 'fx35,fx4', 'fx4', 'fx5']);
- assertNotVisible(this.$sandbox, ['mac,linux', 'maemo', 'fx3', 'm5']);
+ assertNotVisible(this.$sandbox, ['mac,linux', 'maemo', 'fx3', 'm5', 'fx6']);
});
test('maemo m5', function() {
@@ -83,7 +92,7 @@ test('maemo m5', function() {
equals(this.$o.val(), 'maemo', 'Maemo is now selected');
equals(this.$b.val(), 'm5', 'Firefox 5 is now selected');
assertNotHidden(this.$sandbox, ['win', 'not mac', 'maemo', 'm4', 'm5', 'fx35,fx4', 'fx4', 'fx5']);
- assertNotVisible(this.$sandbox, ['mac,linux', 'android', 'fx3']);
+ assertNotVisible(this.$sandbox, ['mac,linux', 'android', 'fx3', 'fx6']);
});
});
View
9 templates/tests/qunit.html
@@ -46,20 +46,21 @@ <h2 id="qunit-userAgent"></h2>
<div id="showfor">
<div class="help-with-selects">
<select class="os" data-oses="{&#34;maemo&#34;: true, &#34;win&#34;: true, &#34;mac&#34;: true, &#34;android&#34;: true, &#34;linux&#34;: true}">
- <option value="win" data-dependency="desktop">Windows</option>
+ <option value="win" data-dependency="desktop" data-default="true">Windows</option>
<option value="mac" data-dependency="desktop">Mac OS X</option>
<option value="linux" data-dependency="desktop">Linux</option>
- <option value="android" data-dependency="mobile">Android</option>
+ <option value="android" data-dependency="mobile" data-default="true">Android</option>
<option value="maemo" data-dependency="mobile">Maemo</option>
</select>
<select class="browser" data-browsers="{&#34;fx5&#34;: {&#34;product&#34;: &#34;fx&#34;, &#34;maxFloatVersion&#34;: 5.9999000000000002}, &#34;fx4&#34;: {&#34;product&#34;: &#34;fx&#34;, &#34;maxFloatVersion&#34;: 4.9999000000000002}, &#34;fx6&#34;: {&#34;product&#34;: &#34;fx&#34;, &#34;maxFloatVersion&#34;: 6.9999000000000002}, &#34;fx3&#34;: {&#34;product&#34;: &#34;fx&#34;, &#34;maxFloatVersion&#34;: 3.4998999999999998}, &#34;m5&#34;: {&#34;product&#34;: &#34;m&#34;, &#34;maxFloatVersion&#34;: 5.9999000000000002}, &#34;m4&#34;: {&#34;product&#34;: &#34;m&#34;, &#34;maxFloatVersion&#34;: 4.9999000000000002}, &#34;m6&#34;: {&#34;product&#34;: &#34;m&#34;, &#34;maxFloatVersion&#34;: 6.9999000000000002}, &#34;fx35&#34;: {&#34;product&#34;: &#34;fx&#34;, &#34;maxFloatVersion&#34;: 3.9998999999999998}}" data-version-groups="{&#34;fx&#34;: [[3.4998999999999998, &#34;3&#34;], [3.9998999999999998, &#34;35&#34;], [4.9999000000000002, &#34;4&#34;], [5.9999000000000002, &#34;5&#34;], [6.9999000000000002, &#34;6&#34;]], &#34;m&#34;: [[4.9999000000000002, &#34;4&#34;], [5.9999000000000002, &#34;5&#34;], [6.9999000000000002, &#34;6&#34;]]}">
<optgroup label="Desktop:">
- <option value="fx5" data-dependency="desktop">Firefox 5</option>
+ <option value="fx6" data-dependency="desktop">Firefox 6</option>
+ <option value="fx5" data-dependency="desktop" selected="selected" data-default="true">Firefox 5</option>
<option value="fx4" data-dependency="desktop">Firefox 4</option>
<option value="fx35" data-dependency="desktop">Firefox 3.5-3.6</option>
</optgroup>
<optgroup label="Mobile:">
- <option value="m5" data-dependency="mobile">Firefox 5</option>
+ <option value="m5" data-dependency="mobile" data-default="true">Firefox 5</option>
<option value="m4" data-dependency="mobile">Firefox 4</option>
</optgroup>
</select>
Please sign in to comment.
Something went wrong with that request. Please try again.