本文整理汇总了Python中MoinMoin.PageEditor.PageEditor.mergeEditConflict方法的典型用法代码示例。如果您正苦于以下问题:Python PageEditor.mergeEditConflict方法的具体用法?Python PageEditor.mergeEditConflict怎么用?Python PageEditor.mergeEditConflict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.PageEditor.PageEditor
的用法示例。
在下文中一共展示了PageEditor.mergeEditConflict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_savepage
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import mergeEditConflict [as 别名]
def do_savepage(pagename, request):
from MoinMoin.PageEditor import PageEditor
_ = request.getText
if not request.user.may.write(pagename):
Page(request, pagename).send_page(request,
msg = _('You are not allowed to edit this page.'))
return
pg = PageEditor(request, pagename)
savetext = request.form.get('savetext', [u''])[0]
rev = int(request.form.get('rev', ['0'])[0])
comment = request.form.get('comment', [u''])[0]
category = request.form.get('category', [None])[0]
rstrip = int(request.form.get('rstrip', ['0'])[0])
trivial = int(request.form.get('trivial', ['0'])[0])
# IMPORTANT: normalize text from the form. This should be done in
# one place before we manipulate the text.
savetext = pg.normalizeText(savetext, stripspaces=rstrip)
# Add category
# TODO: this code does not work with extended links, and is doing
# things behind your back, and in general not needed. Either we have
# a full interface for categories (add, delete) or just add them by
# markup.
if category:
# strip trailing whitespace
savetext = savetext.rstrip()
# Add category separator if last non-empty line contains
# non-categories.
lines = filter(None, savetext.splitlines())
if lines:
#TODO: this code is broken, will not work for extended links
#categories, e.g ["category hebrew"]
categories = lines[-1].split()
if categories:
confirmed = wikiutil.filterCategoryPages(request, categories)
if len(confirmed) < len(categories):
# This was not a categories line, add separator
savetext += u'\n----\n'
# Add new category
if savetext and savetext[-1] != u'\n':
savetext += ' '
savetext += category + u'\n' # Should end with newline!
# Clean comment - replace CR, LF, TAB by whitespace, delete control chars
# TODO: move this to config, create on first call then return cached.
remap_chars = {
ord(u'\t'): u' ',
ord(u'\r'): u' ',
ord(u'\n'): u' ',
}
control_chars = u'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f' \
'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
for c in control_chars:
remap_chars[c] = None
comment = comment.translate(remap_chars)
# Preview, spellcheck or spellcheck add new words
if (request.form.has_key('button_preview') or
request.form.has_key('button_spellcheck') or
request.form.has_key('button_newwords')):
pg.sendEditor(preview=savetext, comment=comment)
# Edit was canceled
elif request.form.has_key('button_cancel'):
pg.sendCancel(savetext, rev)
# Save new text
else:
try:
savemsg = pg.saveText(savetext, rev, trivial=trivial,
comment=comment)
except pg.EditConflict, msg:
# Handle conflict and send editor
# TODO: conflict messages are duplicated from PageEditor,
# refactor to one place only.
conflict_msg = _('Someone else changed this page while you were editing!')
pg.set_raw_body(savetext, modified=1)
if pg.mergeEditConflict(rev):
conflict_msg = _("""Someone else saved this page while you were editing!
Please review the page and save then. Do not save this page as it is!
Have a look at the diff of %(difflink)s to see what has been changed.""") % {
'difflink': pg.link_to(pg.request,
querystr='action=diff&rev=%d' % rev)
}
# We don't send preview when we do merge conflict
pg.sendEditor(msg=conflict_msg, comment=comment)
return
else:
savemsg = conflict_msg
#.........这里部分代码省略.........