def version_sidebar(request, form_data, facets): appver = '' # If appver is in the request, we read it cleaned via form_data. if 'appver' in request.GET or form_data.get('appver'): appver = form_data.get('appver') app = unicode(request.APP.pretty) exclude_versions = getattr(request.APP, 'exclude_versions', []) # L10n: {0} is an application, such as Firefox. This means "any version of # Firefox." rv = [FacetLink(_(u'Any {0}').format(app), dict(appver='any'), not appver)] vs = [dict_from_int(f['term']) for f in facets['appversions']] # Insert the filtered app version even if it's not a facet. av_dict = version_dict(appver) if av_dict and av_dict not in vs and av_dict['major']: vs.append(av_dict) # Valid versions must be in the form of `major.minor`. vs = set((v['major'], v['minor1'] if v['minor1'] not in (None, 99) else 0) for v in vs) versions = ['%s.%s' % v for v in sorted(vs, reverse=True)] for version, floated in zip(versions, map(float, versions)): if (floated not in exclude_versions and floated > request.APP.min_display_version): rv.append(FacetLink('%s %s' % (app, version), dict(appver=version), appver == version)) return rv
def version_sidebar(request, form_data, facets): appver = "" # If appver is in the request, we read it cleaned via form_data. if "appver" in request.GET or form_data.get("appver"): appver = form_data.get("appver") app = unicode(request.APP.pretty) exclude_versions = getattr(request.APP, "exclude_versions", []) # L10n: {0} is an application, such as Firefox. This means "any version of # Firefox." rv = [FacetLink(_(u"Any {0}").format(app), dict(appver="any"), not appver)] vs = [dict_from_int(f["term"]) for f in facets["appversions"]] # Insert the filtered app version even if it's not a facet. av_dict = version_dict(appver) if av_dict and av_dict not in vs and av_dict["major"]: vs.append(av_dict) # Valid versions must be in the form of `major.minor`. vs = set((v["major"], v["minor1"] if v["minor1"] not in (None, 99) else 0) for v in vs) versions = ["%s.%s" % v for v in sorted(vs, reverse=True)] for version, floated in zip(versions, map(float, versions)): if floated not in exclude_versions and floated > request.APP.min_display_version: rv.append(FacetLink("%s %s" % (app, version), dict(appver=version), appver == version)) return rv
def version_sidebar(request, form_data, facets): appver = '' # If appver is in the request, we read it cleaned via form_data. if 'appver' in request.GET or form_data.get('appver'): appver = form_data.get('appver') app = unicode(request.APP.pretty) exclude_versions = getattr(request.APP, 'exclude_versions', []) # L10n: {0} is an application, such as Firefox. This means "any version of # Firefox." rv = [FacetLink(_(u'Any {0}').format(app), dict(appver='any'), not appver)] vs = [dict_from_int(f['term']) for f in facets['appversions']] # Insert the filtered app version even if it's not a facet. av_dict = version_dict(appver) if av_dict and av_dict not in vs and av_dict['major']: vs.append(av_dict) # Valid versions must be in the form of `major.minor`. vs = set((v['major'], v['minor1'] if v['minor1'] not in (None, 99) else 0) for v in vs) versions = ['%s.%s' % v for v in sorted(vs, reverse=True)] for version, floated in zip(versions, map(float, versions)): if (floated not in exclude_versions and floated > request.APP.min_display_version): rv.append( FacetLink('%s %s' % (app, version), dict(appver=version), appver == version)) return rv
def test_dict_from_int(): d = dict_from_int(3050000001002) eq_(d['major'], 3) eq_(d['minor1'], 5) eq_(d['minor2'], 0) eq_(d['minor3'], 0) eq_(d['alpha'], 'a') eq_(d['alpha_ver'], 1) eq_(d['pre'], 'pre') eq_(d['pre_ver'], 2)
def test_dict_from_int(): d = dict_from_int(3050000001002) eq_(d["major"], 3) eq_(d["minor1"], 5) eq_(d["minor2"], 0) eq_(d["minor3"], 0) eq_(d["alpha"], "a") eq_(d["alpha_ver"], 1) eq_(d["pre"], "pre") eq_(d["pre_ver"], 2)
def version_sidebar(request, query, facets): appver = query.get("appver") app = unicode(request.APP.pretty) exclude_versions = getattr(request.APP, "exclude_versions", []) # L10n: {0} is an application, such as Firefox. This means "any version of # Firefox." rv = [FacetLink(_(u"Any {0}").format(app), dict(appver=None), not appver)] vs = [dict_from_int(f["term"]) for f in facets["appversions"]] vs = set((v["major"], v["minor1"] if v["minor1"] != 99 else 0) for v in vs) versions = ["%s.%s" % v for v in sorted(vs, reverse=True)] for version, floated in zip(versions, map(float, versions)): if floated not in exclude_versions and floated > request.APP.min_display_version: rv.append(FacetLink("%s %s" % (app, version), dict(appver=version), appver == version)) return rv
def version_sidebar(request, query, facets): appver = query.get('appver') exclude_versions = getattr(request.APP, 'exclude_versions', []) rv = [FacetLink(_('All Versions'), dict(appver=None), not appver)] vs = [dict_from_int(f['term']) for f in facets['appversions']] vs = set((v['major'], v['minor1'] if v['minor1'] != 99 else 0) for v in vs) versions = ['%s.%s' % v for v in sorted(vs, reverse=True)] for version, floated in zip(versions, map(float, versions)): if (floated not in exclude_versions and floated > request.APP.min_display_version): rv.append(FacetLink(version, dict(appver=version), appver == version)) return rv
def version_sidebar(request, query, facets): appver = query.get('appver') app = unicode(request.APP.pretty) exclude_versions = getattr(request.APP, 'exclude_versions', []) # L10n: {0} is an application, such as Firefox. This means "any version of # Firefox." rv = [FacetLink(_(u'Any {0}').format(app), dict(appver=None), not appver)] vs = [dict_from_int(f['term']) for f in facets['appversions']] vs = set((v['major'], v['minor1'] if v['minor1'] != 99 else 0) for v in vs) versions = ['%s.%s' % v for v in sorted(vs, reverse=True)] for version, floated in zip(versions, map(float, versions)): if (floated not in exclude_versions and floated > request.APP.min_display_version): rv.append(FacetLink('%s %s' % (app, version), dict(appver=version), appver == version)) return rv
def version_sidebar(request, query, facets): appver = query.get('appver') app = unicode(request.APP.pretty) exclude_versions = getattr(request.APP, 'exclude_versions', []) # L10n: {0} is an application, such as Firefox. This means "any version of # Firefox." rv = [FacetLink(_(u'Any {0}').format(app), dict(appver=None), not appver)] vs = [dict_from_int(f['term']) for f in facets['appversions']] vs = set((v['major'], v['minor1'] if v['minor1'] != 99 else 0) for v in vs) versions = ['%s.%s' % v for v in sorted(vs, reverse=True)] for version, floated in zip(versions, map(float, versions)): if (floated not in exclude_versions and floated > request.APP.min_display_version): rv.append( FacetLink('%s %s' % (app, version), dict(appver=version), appver == version)) return rv
def _get_versions(request, versions, version): compats = [] url = request.get_full_path() c = MenuItem() (c.text, c.url) = (_('All Versions'), urlparams(url, lver=None, page=None)) if not version or version == 'any': c.selected = True compats.append(c) seen = {} exclude = request.APP.__dict__.get('exclude_versions', []) versions.sort(reverse=True) for v in versions: # v is a version_int so we can get the major and minor: v = dict_from_int(v) if v['minor1'] == 99: text = '%s.*' % v['major'] v_float = float('%s.99' % v['major']) else: text = '%s.%s' % (v['major'], v['minor1']) v_float = float(text) if seen.get(text): continue seen[text] = 1 if v_float < request.APP.min_display_version or v_float in exclude: continue c = MenuItem() c.text = text c.url = urlparams(url, lver=c.text, page=None) if c.text == version: c.selected = True compats.append(c) return compats
def _get_versions(request, versions, version): compats = [] url = request.get_full_path() c = MenuItem() (c.text, c.url) = (_('All Versions'), urlparams(url, lver=None)) if not version or version == 'any': c.selected = True compats.append(c) seen = {} exclude = request.APP.__dict__.get('exclude_versions', []) versions.sort(reverse=True) for v in versions: # v is a version_int so we can get the major and minor: v = dict_from_int(v) v_float = v['major'] + v['minor1'] / 10.0 text = "%0.1f" % v_float if seen.get(text): #pragma: no cover continue seen[text] = 1 if v_float < request.APP.min_display_version or v_float in exclude: continue c = MenuItem() c.text = text c.url = urlparams(url, lver=c.text) if c.text == version: c.selected = True compats.append(c) return compats