本文整理汇总了Python中tractags.api.TagSystem.replace_tag方法的典型用法代码示例。如果您正苦于以下问题:Python TagSystem.replace_tag方法的具体用法?Python TagSystem.replace_tag怎么用?Python TagSystem.replace_tag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tractags.api.TagSystem
的用法示例。
在下文中一共展示了TagSystem.replace_tag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_admin_panel
# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import replace_tag [as 别名]
def render_admin_panel(self, req, cat, page, version):
req.perm.require("TAGS_ADMIN")
data = {}
tag_system = TagSystem(self.env)
if req.method == "POST":
# Replace Tag
allow_delete = req.args.get("allow_delete")
new_tag = req.args.get("tag_new_name").strip()
new_tag = not new_tag == u"" and new_tag or None
if not (allow_delete or new_tag):
data["error"] = _(
"""Selected current tag(s) and either
new tag or delete approval are required"""
)
else:
comment = req.args.get("comment", u"")
old_tags = req.args.get("tag_name")
if old_tags:
# Provide list regardless of single or multiple selection.
old_tags = isinstance(old_tags, list) and old_tags or [old_tags]
tag_system.replace_tag(req, old_tags, new_tag, comment, allow_delete)
data["selected"] = new_tag
all_tags = sorted(tag_system.get_all_tags(req, "-dummy"))
data["tags"] = all_tags
try:
Chrome(self.env).add_textarea_grips(req)
except AttributeError:
# Element modifiers unavailable before Trac 0.12, skip gracefully.
pass
return "admin_tag_change.html", data
示例2: render_admin_panel
# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import replace_tag [as 别名]
def render_admin_panel(self, req, cat, page, version):
req.perm.require('TAGS_ADMIN')
tag_system = TagSystem(self.env)
all_realms = tag_system.get_taggable_realms(req.perm)
# Check request for enabled filters, or use default.
if not [r for r in all_realms if r in req.args]:
for realm in all_realms:
req.args[realm] = 'on'
checked_realms = [r for r in all_realms if r in req.args]
data = dict(checked_realms=checked_realms,
tag_realms=list(dict(name=realm,
checked=realm in checked_realms)
for realm in all_realms))
if req.method == 'POST':
# Replace Tag
allow_delete = req.args.get('allow_delete')
new_tag = req.args.get('tag_new_name').strip()
new_tag = not new_tag == u'' and new_tag or None
if not (allow_delete or new_tag):
data['error'] = _("Selected current tag(s) and either "
"new tag or delete approval are required")
else:
comment = req.args.get('comment', u'')
old_tags = req.args.get('tag_name')
if old_tags:
# Provide list regardless of single or multiple selection.
old_tags = isinstance(old_tags, list) and old_tags or \
[old_tags]
tag_system.replace_tag(req, old_tags, new_tag, comment,
allow_delete, filter=checked_realms)
data['selected'] = new_tag
query = ' or '.join(['realm:%s' % r for r in checked_realms])
all_tags = sorted(tag_system.get_all_tags(req, query))
data['tags'] = all_tags
try:
Chrome(self.env).add_textarea_grips(req)
except AttributeError:
# Element modifiers unavailable before Trac 0.12, skip gracefully.
pass
return 'admin_tag_change.html', data