本文整理汇总了Python中versions.compare.dict_from_int函数的典型用法代码示例。如果您正苦于以下问题:Python dict_from_int函数的具体用法?Python dict_from_int怎么用?Python dict_from_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dict_from_int函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: version_sidebar
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
示例2: version_sidebar
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
示例3: test_dict_from_int
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)
示例4: version_sidebar
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
示例5: version_sidebar
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
示例6: version_sidebar
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
示例7: _get_versions
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
示例8: _get_versions
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