Fix handling of 512RE bitrate
authorGu1 <gu1@cafai.fr>
Mon, 9 Sep 2013 07:56:26 +0000 (09:56 +0200)
committerGu1 <gu1@cafai.fr>
Mon, 9 Sep 2013 08:01:45 +0000 (10:01 +0200)
fdneligibility/views.py

index aa7abec..69c53fe 100644 (file)
@@ -109,10 +109,11 @@ def test_eligibility(phone_number, zip_code, customize_plan=None, sort_plans=Non
 
 
 def sort_plans_default(plans):
-    unit_table={'k': 1000, 'm': 1000000, 'g': 1000000000}
+    unit_table={'k': 1000, 're': 1000, 'm': 1000000, 'g': 1000000000}
+    pattern=re.compile('^([0-9]+)([a-zA-Z]+)$')
     def _key(o):
-        unit=o['download'][-1].lower()
-        return int(o['download'][:-1])*unit_table[unit]
+        bitrate, unit=re.search(pattern, o['download']).groups()
+        return int(bitrate)*unit_table[unit.lower()]
     tmp=sorted(plans, key=lambda o: 0 if o['plan_id'].endswith('opt1') or o['plan_id'].endswith('opt0') else 1)
     return sorted(tmp, key=_key, reverse=True)