当前位置: 首页>>代码示例>>Python>>正文


Python PageEditor.copyPage方法代码示例

本文整理汇总了Python中MoinMoin.PageEditor.PageEditor.copyPage方法的典型用法代码示例。如果您正苦于以下问题:Python PageEditor.copyPage方法的具体用法?Python PageEditor.copyPage怎么用?Python PageEditor.copyPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MoinMoin.PageEditor.PageEditor的用法示例。


在下文中一共展示了PageEditor.copyPage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CopyPage

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import copyPage [as 别名]
class CopyPage(ActionBase):
    """ Copy page action

    Note: the action name is the class name
    """
    def __init__(self, pagename, request):
        ActionBase.__init__(self, pagename, request)
        self.use_ticket = True
        _ = self._
        self.form_trigger = 'copy'
        self.form_trigger_label = _('Copy Page')
        filterfn = re.compile(ur"^%s/.*$" % re.escape(pagename), re.U).match
        pages = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
        subpagenames = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
        self.subpages = subpagenames
        self.users_subpages = [pagename for pagename in subpagenames if self.request.user.may.read(pagename)]

    def is_allowed(self):
        may = self.request.user.may
        return may.read(self.pagename)

    def check_condition(self):
        _ = self._
        if not self.page.exists():
            return _('This page is already deleted or was never created!')
        else:
            return None

    def do_action(self):
        """ copy this page to "pagename" """
        _ = self._
        # Currently we only check TextCha for upload (this is what spammers ususally do),
        # but it could be extended to more/all attachment write access
        if not TextCha(self.request).check_answer_from_form():
            return status, _('TextCha: Wrong answer! Go back and try again...')

        form = self.form
        newpagename = form.get('newpagename', u'')
        newpagename = wikiutil.normalize_pagename(newpagename, self.cfg)
        comment = form.get('comment', u'')
        comment = wikiutil.clean_input(comment)

        self.page = PageEditor(self.request, self.pagename)
        success, msgs = self.page.copyPage(newpagename, comment)

        copy_subpages = 0
        try:
            copy_subpages = int(form['copy_subpages'])
        except:
            pass

        if copy_subpages and self.subpages or (not self.users_subpages and self.subpages):
            for name in self.subpages:
                self.page = PageEditor(self.request, name)
                new_subpagename = name.replace(self.pagename, newpagename, 1)
                success_i, msg = self.page.copyPage(new_subpagename, comment)
                msgs = "%s %s" % (msgs, msg)

        self.newpagename = newpagename # keep there for finish
        return success, msgs

    def do_action_finish(self, success):
        if success:
            url = Page(self.request, self.newpagename).url(self.request)
            self.request.http_redirect(url)
        else:
            self.render_msg(self.make_form(), "dialog")

    def get_form_html(self, buttons_html):
        _ = self._
        if self.users_subpages:
            subpages = ' '.join([wikiutil.escape(page) for page in self.users_subpages])

            d = {
                'textcha': TextCha(self.request).render(),
                'subpage': subpages,
                'subpages_checked': ('', 'checked')[self.request.args.get('subpages_checked', '0') == '1'],
                'subpage_label': _('Copy all /subpages too?'),
                'pagename': wikiutil.escape(self.pagename, True),
                'newname_label': _("New name"),
                'comment_label': _("Optional reason for the copying"),
                'buttons_html': buttons_html,
                'querytext': _('Really copy this page?')
                }

            return '''
<strong>%(querytext)s</strong>
<br>
<br>
%(textcha)s
<table>
    <tr>
    <dd>
        %(subpage_label)s<input type="checkbox" name="copy_subpages" value="1" %(subpages_checked)s>
    </dd>
    <dd>
        <class="label"><subpage> %(subpage)s</subpage>
    </dd>
    </tr>
</table>
#.........这里部分代码省略.........
开发者ID:IvanLogvinov,项目名称:soar,代码行数:103,代码来源:CopyPage.py


注:本文中的MoinMoin.PageEditor.PageEditor.copyPage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。