本文整理汇总了Python中amo.utils.MenuItem.selected方法的典型用法代码示例。如果您正苦于以下问题:Python MenuItem.selected方法的具体用法?Python MenuItem.selected怎么用?Python MenuItem.selected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amo.utils.MenuItem
的用法示例。
在下文中一共展示了MenuItem.selected方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_sorts
# 需要导入模块: from amo.utils import MenuItem [as 别名]
# 或者: from amo.utils.MenuItem import selected [as 别名]
def _get_sorts(request, sort):
items = []
url = request.get_full_path()
sorts = forms.sort_by
item = MenuItem()
(item.text, item.url) = (_('Keyword Match'), urlparams(url, sort=None))
if not sort:
item.selected = True
items.append(item)
for key, val in sorts:
if key == '':
continue
item = MenuItem()
(item.text, item.url) = (val, urlparams(url, sort=key, page=None))
if sort == key:
item.selected = True
items.append(item)
return items
示例2: _get_sorts
# 需要导入模块: from amo.utils import MenuItem [as 别名]
# 或者: from amo.utils.MenuItem import selected [as 别名]
def _get_sorts(request, sort):
items = []
url = request.get_full_path()
sorts = forms.sort_by
item = MenuItem()
(item.text, item.url) = (_('Keyword Match'), urlparams(url, sort=None))
if not sort:
item.selected = True
items.append(item)
for key, val in sorts:
# TODO(davedash): Remove 'name' altogether if nobody complains.
if key == '' or key == 'name':
continue
item = MenuItem()
(item.text, item.url) = (val, urlparams(url, sort=key, page=None))
if sort == key:
item.selected = True
items.append(item)
return items
示例3: _get_versions
# 需要导入模块: from amo.utils import MenuItem [as 别名]
# 或者: from amo.utils.MenuItem import selected [as 别名]
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
示例4: _get_addons
# 需要导入模块: from amo.utils import MenuItem [as 别名]
# 或者: from amo.utils.MenuItem import selected [as 别名]
def _get_addons(request, addons, addon_id):
"""Create a list of ``MenuItem``s for the activity feed."""
items = []
a = MenuItem()
a.selected = (not addon_id)
(a.text, a.url) = (_('All My Add-ons'), reverse('devhub.feed_all'))
items.append(a)
for addon in addons:
item = MenuItem()
try:
item.selected = (addon_id and addon.id == int(addon_id))
except ValueError:
pass # We won't get here... EVER
url = reverse('devhub.feed', args=[addon.slug])
item.text, item.url = addon.name, url
items.append(item)
return items
示例5: _get_categories
# 需要导入模块: from amo.utils import MenuItem [as 别名]
# 或者: from amo.utils.MenuItem import selected [as 别名]
def _get_categories(request, categories, addon_type=None, category=None):
items = []
url = request.get_full_path()
i = MenuItem()
(i.text, i.url) = (_('All'), urlparams(url, atype=None, cat=None,
page=None))
if not addon_type and not category:
i.selected = True
items.append(i)
# Bucket the categories as addon_types so we can display them in a
# hierarchy.
bucket = defaultdict(list)
for cat in categories:
item = MenuItem()
(item.text, item.url) = (cat.name, urlparams(url, atype=None,
page=None, cat="%d,%d" % (cat.type, cat.id)))
if category == cat.id:
item.selected = True
bucket[cat.type].append(item)
for key in sorted(bucket):
children = bucket[key]
item = MenuItem()
item.children = children
(item.text, item.url) = (amo.ADDON_TYPES[key],
urlparams(url, atype=key, cat=None,
page=None))
if not category and addon_type == key:
item.selected = True
items.append(item)
return items
示例6: _get_tags
# 需要导入模块: from amo.utils import MenuItem [as 别名]
# 或者: from amo.utils.MenuItem import selected [as 别名]
def _get_tags(request, tags, selected):
items = []
url = request.get_full_path()
for tag in tags:
item = MenuItem()
(item.text, item.url) = (tag.tag_text.lower(),
urlparams(url, tag=tag.tag_text.encode('utf8').lower(),
page=None))
if tag.tag_text.lower() == selected:
item.selected = True
items.append(item)
return items
示例7: _get_platforms
# 需要导入模块: from amo.utils import MenuItem [as 别名]
# 或者: from amo.utils.MenuItem import selected [as 别名]
def _get_platforms(request, platforms, selected=None):
items = []
url = request.get_full_path()
if amo.PLATFORM_ALL.id in platforms:
platforms = amo.PLATFORMS.keys()
for platform in platforms:
if platform == amo.PLATFORM_ALL.id:
continue
item = MenuItem()
p = amo.PLATFORMS[platform]
(item.text, item.url) = (p.name, urlparams(url, pid=(p.id or None), page=None))
if p.id == selected:
item.selected = True
items.append(item)
return items