本文整理汇总了Python中models.Page.by_revision方法的典型用法代码示例。如果您正苦于以下问题:Python Page.by_revision方法的具体用法?Python Page.by_revision怎么用?Python Page.by_revision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.by_revision方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_revision [as 别名]
def show(name):
revision = request.args.get('rev')
if revision:
revision = Page.by_revision(revision)
revision_requested = True
else:
revision = Page.by_name(name)
revision_requested = False
if revision is None:
return (web.render_template('missing.html',
revision_requested=revision_requested,
page_name=name,
protected=False), 404)
return web.render_template('show.html', revision=revision)
示例2: revert
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_revision [as 别名]
def revert(name):
"""Revert an old revision."""
rev_id = request.args.get('rev')
try:
rev_id = int(rev_id)
except:
pass
old_revision = page = None
error = _('No such revision')
if request.method == 'POST' and request.form.get('cancel'):
return web.redirect(web.url_for('show', name=page_name))
if rev_id:
old_revision = Page.by_revision(rev_id)
if old_revision:
new_revision = Page.by_name(name)
if old_revision == new_revision:
error = _('You tried to revert the current active ' \
'revision.')
elif old_revision.text == new_revision.text:
error = _('There are no changes between the current ' \
'revision and the revision you want to ' \
'restore.')
else:
error = ''
page = old_revision.page
if request.method == 'POST':
note = request.form.get('note', '')
note = 'revert' + (note and ': ' + note or '')
revision = Revision(page=page, text=old_revision.text,
note=note)
revision.save()
db.commit()
return web.redirect(web.url_for('show', name=name))
return web.render_template('revert.html',
error=error,
old_revision=old_revision,
revision=page
)