コード例 #1
0
def version_sidebar(request, form_data, aggregations):
    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['key']) for f in aggregations['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
コード例 #2
0
ファイル: views.py プロジェクト: Alien426/addons-server
def version_sidebar(request, form_data, aggregations):
    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['key']) for f in aggregations['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
コード例 #3
0
def test_dict_from_int():
    d = dict_from_int(3050000001002)
    assert d['major'] == 3
    assert d['minor1'] == 5
    assert d['minor2'] == 0
    assert d['minor3'] == 0
    assert d['alpha'] == 'a'
    assert d['alpha_ver'] == 1
    assert d['pre'] == 'pre'
    assert d['pre_ver'] == 2
コード例 #4
0
ファイル: test_compare.py プロジェクト: bqbn/addons-server
def test_dict_from_int():
    d = dict_from_int(3050000001002)
    assert d['major'] == 3
    assert d['minor1'] == 5
    assert d['minor2'] == 0
    assert d['minor3'] == 0
    assert d['alpha'] == 'a'
    assert d['alpha_ver'] == 1
    assert d['pre'] == 'pre'
    assert d['pre_ver'] == 2