Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bug 802340 - sort product in the order they are received from current…

…versions service
  • Loading branch information...
commit 8a23b45b7198615ae0a5f8af232ee39b82ebba95 1 parent 0df8a3a
@rhelmer rhelmer authored
View
2  INSTALL.md
@@ -19,7 +19,7 @@ make sure it's available on your `PATH`.
Create virtualenv and populate it
---------------------------------
- virtualenv .virtualenv
+ virtualenv --python=python2.6 .virtualenv
source .virtualenv/bin/activate
pip install -r requirements/compiled.txt
pip install -r requirements/dev.txt
View
4 crashstats/base/templates/crashstats_base.html
@@ -68,8 +68,8 @@
<li>
Product:
<select id="products_select">
- {% for r in currentversions|groupby('product') %}
- <option value="{{ r[0] }}" {% if r[0] == product %}selected{% endif %}>{{ r[0] }}</option>
+ {% for p in releases %}
+ <option value="{{ p }}" {% if p == product %}selected{% endif %}>{{ p }}</option>
{% endfor %}
</select>
</li>
View
3  crashstats/crashstats/context_processors.py
@@ -9,8 +9,11 @@ def current_versions(request):
data['currentversions'] = request.currentversions
product = getattr(request, 'product', None)
version = getattr(request, 'version', None)
+ releases = getattr(request, 'releases', None)
if product:
data['product'] = product
if version:
data['version'] = version
+ if releases:
+ data['releases'] = releases
return data
View
108 crashstats/crashstats/tests/test_utils.py
@@ -3,6 +3,8 @@
from nose.tools import eq_, ok_
from crashstats.crashstats import utils
from unittest import TestCase
+from ordereddict import OrderedDict
+import json
class TestUtils(TestCase):
@@ -108,6 +110,112 @@ def test_parse_dump(self):
self.maxDiff = None
eq_(actual, expected)
+ def test_build_releases(self):
+ currentversions = json.loads("""
+ {"currentversions": [
+ {"product": "Firefox",
+ "throttle": "100.00",
+ "end_date": "2012-05-10T00:00:00",
+ "start_date": "2012-03-08T00:00:00",
+ "featured": true,
+ "version": "19.0",
+ "release": "Beta",
+ "id": 922},
+ {"product": "Firefox",
+ "throttle": "100.00",
+ "end_date": "2012-05-10T00:00:00",
+ "start_date": "2012-03-08T00:00:00",
+ "featured": true,
+ "version": "18.0",
+ "release": "Stable",
+ "id": 920},
+ {"product": "Firefox",
+ "throttle": "100.00",
+ "end_date": "2012-05-10T00:00:00",
+ "start_date": "2012-03-08T00:00:00",
+ "featured": true,
+ "version": "20.0",
+ "release": "Nightly",
+ "id": 923},
+ {"product": "Thunderbird",
+ "throttle": "100.00",
+ "end_date": "2012-05-10T00:00:00",
+ "start_date": "2012-03-08T00:00:00",
+ "featured": true,
+ "version": "18.0",
+ "release": "Aurora",
+ "id": 924},
+ {"product": "Thunderbird",
+ "throttle": "100.00",
+ "end_date": "2012-05-10T00:00:00",
+ "start_date": "2012-03-08T00:00:00",
+ "featured": true,
+ "version": "19.0",
+ "release": "Nightly",
+ "id": 925},
+ {"product": "Camino",
+ "throttle": "99.00",
+ "end_date": "2012-05-10T00:00:00",
+ "start_date": "2012-03-08T00:00:00",
+ "featured": true,
+ "version": "9.5",
+ "release": "Alpha",
+ "id": 921}]
+ }
+ """)['currentversions']
+
+ actual = utils.build_releases(currentversions)
+
+ expected = OrderedDict(
+ [(u'Firefox', [
+ {u'throttle': u'100.00',
+ u'end_date': u'2012-05-10T00:00:00',
+ u'start_date': u'2012-03-08T00:00:00',
+ u'featured': True,
+ u'version': u'19.0',
+ u'release': u'Beta',
+ u'id': 922},
+ {u'throttle': u'100.00',
+ u'end_date': u'2012-05-10T00:00:00',
+ u'start_date': u'2012-03-08T00:00:00',
+ u'featured': True,
+ u'version': u'18.0',
+ u'release': u'Stable',
+ u'id': 920},
+ {u'throttle': u'100.00',
+ u'end_date': u'2012-05-10T00:00:00',
+ u'start_date': u'2012-03-08T00:00:00',
+ u'featured': True,
+ u'version': u'20.0',
+ u'release': u'Nightly',
+ u'id': 923}]),
+ (u'Thunderbird',
+ [{u'throttle': u'100.00',
+ u'end_date': u'2012-05-10T00:00:00',
+ u'start_date': u'2012-03-08T00:00:00',
+ u'featured': True,
+ u'version': u'18.0',
+ u'release': u'Aurora',
+ u'id': 924},
+ {u'throttle': u'100.00',
+ u'end_date': u'2012-05-10T00:00:00',
+ u'start_date': u'2012-03-08T00:00:00',
+ u'featured': True,
+ u'version': u'19.0',
+ u'release': u'Nightly',
+ u'id': 925}]),
+ (u'Camino',
+ [{u'throttle': u'99.00',
+ u'end_date': u'2012-05-10T00:00:00',
+ u'start_date': u'2012-03-08T00:00:00',
+ u'featured': True,
+ u'version': u'9.5',
+ u'release': u'Alpha',
+ u'id': 921}])
+ ])
+
+ eq_(actual, expected)
+
def test_unicode_writer(self):
out = StringIO()
writer = utils.UnicodeWriter(out)
View
18 crashstats/crashstats/utils.py
@@ -6,7 +6,9 @@
import json
import time
import re
+import copy
from django import http
+from ordereddict import OrderedDict
def unixtime(value, millis=False, format='%Y-%m-%d'):
@@ -146,6 +148,22 @@ def parse_dump(dump, vcs_mappings):
return parsed_dump
+def build_releases(currentversions):
+ """
+ currentversions service returns a very unwieldy data structure.
+ make something more suitable for templates.
+ """
+ releases = OrderedDict()
+ for release in copy.deepcopy(currentversions):
+ product = release['product']
+ del release['product']
+ if product not in releases:
+ releases[product] = [release]
+ else:
+ releases[product].append(release)
+ return releases
+
+
class UnicodeWriter:
"""
A CSV writer which will write rows to CSV file "f",
View
2  crashstats/crashstats/views.py
@@ -190,6 +190,8 @@ def _basedata(product=None, versions=None):
if product and versions:
raise http.Http404("Not a recognized version for that product")
+ data['releases'] = utils.build_releases(data['currentversions'])
+
return data
@functools.wraps(view)
View
1  requirements/prod.txt
@@ -1,6 +1,7 @@
requests==0.13.0
python-memcached==1.48
isodate==0.4.7
+ordereddict==1.1
# for django-compressor
BeautifulSoup==3.2.1
Please sign in to comment.
Something went wrong with that request. Please try again.