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


Python PageEditor.renamePage方法代码示例

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


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

示例1: do_renamepage

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import renamePage [as 别名]
    def do_renamepage(self, pagename, newpagename, author=u"Scripting Subsystem", comment=u"Renamed by the scripting subsystem."):
        """ Renames a page.

        @param pagename: name of the target page
        @param newpagename: name of the new page
        @param author:   user name of the editor (optional)
        @param comment:  comment related to this revision (optional)
        """
        if self.request.user.may.write(pagename):
            _ = self.request.getText
            page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
            if not page.exists():
                raise RuntimeScriptException(_("The page %s does not exist.") % pagename)
            newpage = PageEditor(self.request, newpagename)
            page.renamePage(newpage.page_name, comment=u"Renamed from '%s'" % (pagename))
            self.msg += u'%(pagename)s renamed to %(newpagename)s\n' % {
                            "pagename": pagename,
                            "newpagename": newpagename}
        else:
            self.msg += u"action rename page: not enough rights - nothing done \n"
开发者ID:steveyen,项目名称:moingo,代码行数:22,代码来源:packages.py

示例2: xmlrpc_renamePage

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import renamePage [as 别名]
    def xmlrpc_renamePage(self, pagename, newpagename):
        """
        Renames a page <pagename> to <newpagename>.

        @param pagename: the page name (unicode or utf-8)
        @param newpagename: the new pagename (unicode or utf-8)
        @rtype: bool
        @return: True on success
        """

        pagename = self._instr(pagename)
        pagename = wikiutil.normalize_pagename(pagename, self.cfg)
        if not pagename:
            return xmlrpclib.Fault("INVALID", "pagename can't be empty")

        # check ACLs
        if not (self.request.user.may.delete(pagename) and self.request.user.may.write(newpagename)):
            return xmlrpclib.Fault(1, "You are not allowed to rename this page")
        editor = PageEditor(self.request, pagename, do_editor_backup=0)

        try:
            editor.renamePage(newpagename)
        except PageEditor.SaveError, error:
            return xmlrpclib.Fault(1, "Rename failed: %s" % (str(error), ))
开发者ID:Kartstig,项目名称:engineering-inventions-wiki,代码行数:26,代码来源:__init__.py

示例3: RenamePage

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import renamePage [as 别名]
class RenamePage(ActionBase):
    """ Rename 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 = 'rename'
        self.form_trigger_label = _('Rename Page')
        filterfn = re.compile(ur"^%s/.*$" % re.escape(pagename), re.U).match
        subpagenames = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
        self.subpages = [pagename for pagename in subpagenames if self.request.user.may.delete(pagename)]

    def is_allowed(self):
        may = self.request.user.may
        return may.write(self.pagename) and may.delete(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):
        """ Rename this page to "pagename" """
        _ = self._
        form = self.form
        newpagename = form.get('newpagename', [u''])[0]
        newpagename = self.request.normalizePagename(newpagename)
        comment = form.get('comment', [u''])[0]
        comment = wikiutil.clean_input(comment)

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

        rename_subpages = 0
        if 'rename_subpages' in form:
            try:
                rename_subpages = int(form['rename_subpages'][0])
            except:
                pass

        if rename_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.renamePage(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.subpages:
            subpages = ' '.join(self.subpages)

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

            return '''
<strong>%(querytext)s</strong>
<br>
<br>
<table>
    <tr>
    <dd>
        %(subpage_label)s<input type="checkbox" name="rename_subpages" value="1" %(subpages_checked)s>
    </dd>
    <dd>
        <class="label"><subpage> %(subpage)s</subpage>
    </dd>
    </tr>
</table>
<table>
    <tr>
        <td class="label"><label>%(newname_label)s</label></td>
        <td class="content">
            <input type="text" name="newpagename" value="%(pagename)s" size="80">
        </td>
    </tr>
    <tr>
#.........这里部分代码省略.........
开发者ID:steveyen,项目名称:moingo,代码行数:103,代码来源:RenamePage.py

示例4: RenamePage

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import renamePage [as 别名]
class RenamePage(ActionBase):
    """ Rename 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 = 'rename'
        self.form_trigger_label = _('Rename Page')
        filterfn = re.compile(ur"^%s/.*$" % re.escape(pagename), re.U).match
        subpagenames = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
        self.subpages = [pagename for pagename in subpagenames if self.request.user.may.delete(pagename)]
        try:
            self.show_redirect = request.cfg.show_rename_redirect
        except AttributeError:
            self.show_redirect = False
        try:
            self.rename_redirect = int(self.request.form.get('rename_redirect', '0'))
        except ValueError:
            self.rename_redirect = 0

    def is_allowed(self):
        may = self.request.user.may
        return may.write(self.pagename) and may.delete(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):
        """ Rename this page to "pagename" """
        _ = self._
        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)
        try:
            rename_subpages = int(self.request.form.get('rename_subpages', '0'))
        except ValueError:
            rename_subpages = 0

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

        if not success:
            return success, msgs

        msgs = [msgs]

        if self.show_redirect and self.rename_redirect:
            self.page = PageEditor(self.request, self.pagename)
            self.page.saveText('#redirect %s' % newpagename, 0)

        if rename_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.renamePage(new_subpagename, comment)
                msgs.append(msg)

                if self.show_redirect and self.rename_redirect and success_i:
                    self.page = PageEditor(self.request, name)
                    self.page.saveText('#redirect %s' % new_subpagename, 0)
            msgs = ' '.join([msg for msg in msgs if 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, code=301)
        else:
            self.render_msg(self.make_form(), "dialog")

    def get_form_html(self, buttons_html):
        _ = self._

        if self.subpages:
            redirect_label = _('Create redirect for renamed page(s)?')

            subpages = ' '.join([wikiutil.escape(page) for page in self.subpages])
            subpages_html = """
                <tr>
                <dd>
                    %(subpage_label)s<input type="checkbox" name="rename_subpages" value="1" %(subpages_checked)s>
                </dd>
                <dd>
                    <class="label"><subpage> %(subpage)s</subpage>
                </dd>
                </tr>
                """ % {
                    'subpage': subpages,
                    'subpages_checked': ('', 'checked')[self.request.args.get('subpages_checked', '0') == '1'],
#.........这里部分代码省略.........
开发者ID:Glottotopia,项目名称:aagd,代码行数:103,代码来源:RenamePage.py

示例5: RenamePage

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import renamePage [as 别名]
class RenamePage(ActionBase):
    """ Rename 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 = 'rename'
        self.form_trigger_label = _('Rename Page')

    def is_allowed(self):
        may = self.request.user.may
        return may.write(self.pagename) and may.delete(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):
        """ Rename this page to "pagename" """
        _ = self._
        form = self.form
        newpagename = form.get('newpagename', [u''])[0]
        newpagename = self.request.normalizePagename(newpagename)
        comment = form.get('comment', [u''])[0]
        comment = wikiutil.clean_comment(comment)

        self.page = PageEditor(self.request, self.pagename)
        success, msg = self.page.renamePage(newpagename, comment)
        self.newpagename = newpagename # keep there for finish
        return success, msg

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

    def get_form_html(self, buttons_html):
        _ = self._
        d = {
            'pagename': self.pagename,
            'newname_label': _("New name"),
            'comment_label': _("Optional reason for the renaming"),
            'buttons_html': buttons_html,
        }
        return '''
<table>
    <tr>
        <td class="label"><label>%(newname_label)s</label></td>
        <td class="content">
            <input type="text" name="newpagename" value="%(pagename)s">
        </td>
    </tr>
    <tr>
        <td class="label"><label>%(comment_label)s</label></td>
        <td class="content">
            <input type="text" name="comment" maxlength="200">
        </td>
    </tr>
    <tr>
        <td></td>
        <td class="buttons">
            %(buttons_html)s
        </td>
    </tr>
</table>
''' % d
开发者ID:imosts,项目名称:flume,代码行数:77,代码来源:RenamePage.py

示例6: RenamePage

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import renamePage [as 别名]

#.........这里部分代码省略.........
            # User rights _ARE_ checked here!
            if not self.request.user.may.write(page):
                continue

            # If inlink rename of a single page does not work,
            # continue but make sure to emit a warning
            success_i, msg = self._inlink_rename(page, newpagename,
                                                 oldpagename, comment)
            if not success_i:
                success = False

            if msg:
                msgs.append(msg)

        if not success:
            msgs.append(_(u'Other pages with inlinks renamed successfully.'))

        return success, msgs

    def do_action(self):
        """ Rename this page to "pagename" """
        _ = self._
        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)
        try:
            rename_subpages = int(self.request.form.get('rename_subpages', '0'))
        except ValueError:
            rename_subpages = 0

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

        if not success:
            return success, msgs

        msgs = [msgs]

        if rename_inlinks:
            success, msgs = self.rename_inlinks(newpagename, comment, msgs)

        if self.show_redirect and self.rename_redirect:
            self.page = PageEditor(self.request, self.pagename)
            self.page.saveText('#redirect %s' % newpagename, 0)

        if rename_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.renamePage(new_subpagename, comment)
                msgs.append(msg)

                if self.show_redirect and self.rename_redirect and success_i:
                    self.page = PageEditor(self.request, name)
                    self.page.saveText('#redirect %s' % new_subpagename, 0)
            msgs = ' '.join([msg for msg in msgs if 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, code=301)
开发者ID:graphingwiki,项目名称:gwiki-with-moin,代码行数:70,代码来源:RenamePage.py


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