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


Python PageEditor.send_page方法代码示例

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


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

示例1: execute

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import send_page [as 别名]
def execute(pagename, request):
    _ = request.getText
    actname = __name__.split('.')[-1]
    # Create a page editor that does not do edior backups, becuase
    # delete generate "deleted" version, of the page.
    page = PageEditor(request, pagename, do_editor_backup=0)

    # be extra paranoid in dangerous actions
    if actname in request.cfg.excluded_actions \
            or not request.user.may.write(pagename) \
            or not request.user.may.delete(pagename):
        return page.send_page(request,
            msg = _('You are not allowed to delete this page.'))

    # check whether page exists at all
    if not page.exists():
        return page.send_page(request,
            msg = _('This page is already deleted or was never created!'))

    # check whether the user clicked the delete button
    if request.form.has_key('button') and request.form.has_key('ticket'):
        # check whether this is a valid deletion request (make outside
        # attacks harder by requiring two full HTTP transactions)
        if not wikiutil.checkTicket(request.form['ticket'][0]):
            return page.send_page(request,
                msg = _('Please use the interactive user interface to delete pages!'))

        # Delete the page
        page.deletePage(request.form.get('comment', [u''])[0])

        return page.send_page(request,
                msg = _('Page "%s" was successfully deleted!') % (pagename,))

    # send deletion form
    ticket = wikiutil.createTicket()
    querytext = _('Really delete this page?')
    button = _('Delete')
    comment_label = _("Optional reason for the deletion")

    # TODO: this form suck, redesign like RenamePage
    formhtml = '''
<form method="post" action="">
<strong>%(querytext)s</strong>
<input type="hidden" name="action" value="%(actname)s">
<input type="hidden" name="ticket" value="%(ticket)s">
<input type="submit" name="button" value="%(button)s">
<p>
%(comment_label)s<br>
<input type="text" name="comment" size="60" maxlength="80">
</form>''' % {
    'querytext': querytext,
    'actname': actname,
    'ticket': ticket,
    'button': button,
    'comment_label': comment_label,
}

    return page.send_page(request, msg=formhtml)
开发者ID:mikejamesthompson,项目名称:orgsites,代码行数:60,代码来源:DeletePage.py

示例2: execute

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import send_page [as 别名]
def execute (pagename, request):

    # get the etherpad instance and related information: 
    (ep, padname, padURL) = etherpadConnect (pagename)

    # teh moinmoin data: 
    pe = PageEditor(request, pagename) 
    currev = pe.current_rev()
    request.reset()

    try: 
        padtext = ep.getText (padname)[u'text']
        try:
            pe.saveText (padtext, currev)
            msg = "Text has been successfully obtained from Etherpad."
        except Exception as e:
            msg = "Text has been obtained from Etherpad, but an error occured when saving it to Wiki. " 
    except Exception as e:
        msg = "An error occured when trying to obtain text from Etherpad." 

    request.theme.add_msg(msg, "info")
    pe.send_page()
开发者ID:hkarl,项目名称:propgen,代码行数:24,代码来源:PullFromEtherpad.py

示例3: ActionClass

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

#.........这里部分代码省略.........
            "user": None, # XXX should be refactored into a password agent or OpenID like solution
            "password": None,
        }

        options.update(Dict(self.request, self.pagename))

        # Convert page and group list strings to lists
        if options["pageList"] is not None:
            options["pageList"] = unpackLine(options["pageList"], ",")
        if options["groupList"] is not None:
            options["groupList"] = unpackLine(options["groupList"], ",")

        options["direction"] = directions_map.get(options["direction"].lower(), BOTH)

        return options

    def fix_params(self, params):
        """ Does some fixup on the parameters. """
        # Load the password
        if "password" in self.request.form:
            params["password"] = self.request.form["password"][0]

        # merge the pageList case into the pageMatch case
        if params["pageList"] is not None:
            params["pageMatch"] = u'|'.join([r'^%s$' % re.escape(name)
                                             for name in params["pageList"]])

        if params["pageMatch"] is not None:
            params["pageMatch"] = re.compile(params["pageMatch"], re.U)

        # we do not support matching or listing pages if there is a group of pages
        if params["groupList"]:
            params["pageMatch"] = None
            params["pageList"] = None

        return params

    def show_password_form(self):
        _ = self.request.getText
        d = {"message": _(r"Please enter your password of your account at the remote wiki below. <<BR>> /!\ You should trust both wikis because the password could be read by the particular administrators.", wiki=True),
             "passwordlabel": _("Password"),
             "submit": _("Login"),
             "cancel": _("Cancel"),
        }
        html_form = """
%(message)s
<form method="post">
<div>
<input type="hidden" name="action" value="SyncPages">
<label for="iPassword" style="font-weight: bold;">%(passwordlabel)s:</label>
<input type="password" name="password" id="iPassword" size="20">
</div>
<div style="margin-top:1em; margin-bottom:1em;">
<div style="float:left">
<input type="submit" value="%(submit)s">
</div>
<div style="margin-left: 10em; margin-right: 10em;">
<input type="submit" value="%(cancel)s" name="cancel">
</div>
</div>
</form>
""" % d
        self.request.theme.add_msg(html_form, "dialog")
        self.page.send_page()

    def render(self):
        """ Render action

        This action returns a status message.
        """
        _ = self.request.getText

        params = self.fix_params(self.parse_page())

        try:
            if "cancel" in self.request.form:
                raise ActionStatus(_("Operation was canceled."), "error")

            if params["direction"] == UP:
                raise ActionStatus(_("The only supported directions are BOTH and DOWN."), "error")

            if not self.request.cfg.interwikiname:
                raise ActionStatus(_("Please set an interwikiname in your wikiconfig (see HelpOnConfiguration) to be able to use this action.", wiki=True), "error")

            if not params["remoteWiki"]:
                raise ActionStatus(_("Incorrect parameters. Please supply at least the ''remoteWiki'' parameter. Refer to HelpOnSynchronisation for help.", wiki=True), "error")

            local = MoinLocalWiki(self.request, params["localPrefix"], params["pageList"])
            try:
                remote = MoinRemoteWiki(self.request, params["remoteWiki"], params["remotePrefix"], params["pageList"], params["user"], params["password"], verbose=debug)
            except (UnsupportedWikiException, NotAllowedException), (msg, ):
                raise ActionStatus(msg, "error")

            if not remote.valid:
                raise ActionStatus(_("The ''remoteWiki'' is unknown.", wiki=True), "error")
            # if only the username is supplied, we ask for the password
            if params["user"] and not params["password"]:
                return self.show_password_form()
        except ActionStatus, e:
            self.request.theme.add_msg(*e.args)
开发者ID:steveyen,项目名称:moingo,代码行数:104,代码来源:SyncPages.py

示例4: __init__

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import send_page [as 别名]
class RenamePage:
    """ Rename page action

    Note: the action name is the class name
    """
    def __init__(self, pagename, request):
        self.request = request
        self.pagename = pagename
        self.page = PageEditor(request, pagename)
        self.newpage = None
        self.error = ''

    def allowed(self):
        """ Check if user is allowed to do this

        This could be a standard method of the base action class, doing
        the filtering by action class name and cfg.allowed_actions.
        """
        may = self.request.user.may
        return (self.__class__.__name__ in self.request.cfg.allowed_actions and
                may.write(self.pagename) and may.delete(self.pagename))
    
    def render(self):
        """ Render action

        This action return a wiki page with optional message, or
        redirect to new page.
        """
        _ = self.request.getText
        form = self.request.form
        
        if form.has_key('cancel'):
            # User canceled
            return self.page.send_page(self.request)

        # Validate user rights and page state. If we get error here, we
        # return an error message, without the rename form.
        error = None
        if not self.allowed():
            error = _('You are not allowed to rename pages in this wiki!')
        elif not self.page.exists():
            error = _('This page is already deleted or was never created!')
        if error:
            # Send page with an error message
            return self.page.send_page(self.request, msg=error)

        # Try to rename. If we get an error here, we return the error
        # message with a rename form.
        elif (form.has_key('rename') and form.has_key('newpagename') and
              form.has_key('ticket')):
            # User replied to the rename form with all required items
            self.rename()
            if not self.error:
                self.request.http_redirect(self.newpage.url(self.request))
                return self.request.finish()    

        # A new form request, or form has missing data, or rename
        # failed. Return a new form with optional error.
        return self.page.send_page(self.request, msg=self.makeform())

    def rename(self):
        """ Rename pagename and return the new page """
        _ = self.request.getText
        form = self.request.form
        
        # Require a valid ticket. Make outside attacks harder by
        # requiring two full HTTP transactions
        if not wikiutil.checkTicket(form['ticket'][0]):
            self.error = _('Please use the interactive user interface to rename pages!')
            return

        # Get new name from form and normalize.
        comment = form.get('comment', [u''])[0]
        newpagename = form.get('newpagename')[0]
        newpagename = self.request.normalizePagename(newpagename)

        # Name might be empty after normalization. To save translation
        # work for this extreme case, we just use "EmptyName".
        if not newpagename:
            newpagename = "EmptyName"

        # Valid new name
        newpage = PageEditor(self.request, newpagename)

        # Check whether a page with the new name already exists
        if newpage.exists(includeDeleted=1):
            return self.pageExistsError(newpagename)
        
        # Get old page text
        savetext = self.page.get_raw_body()

        oldpath = self.page.getPagePath(check_create=0)
        newpath = newpage.getPagePath(check_create=0)

        # Rename page

        # NOTE: might fail if another process created newpagename just
        # NOW, while you read this comment. Rename is atomic for files -
        # but for directories, rename will fail if the directory
        # exists. We should have global edit-lock to avoid this.
#.........这里部分代码省略.........
开发者ID:mikejamesthompson,项目名称:orgsites,代码行数:103,代码来源:RenamePage.py


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