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


Python modaction.ModAction类代码示例

本文整理汇总了Python中r2.models.modaction.ModAction的典型用法代码示例。如果您正苦于以下问题:Python ModAction类的具体用法?Python ModAction怎么用?Python ModAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: POST_wiki_edit

    def POST_wiki_edit(self, pageandprevious, content, page_name, reason):
        """Edit a wiki `page`"""
        page, previous = pageandprevious

        if not page:
            error = c.errors.get(("WIKI_CREATE_ERROR", "page"))
            if error:
                self.handle_error(403, **(error.msg_params or {}))
            if not c.user._spam:
                page = WikiPage.create(c.site, page_name)
        if c.user._spam:
            error = _("You are doing that too much, please try again later.")
            self.handle_error(415, "SPECIAL_ERRORS", special_errors=[error])

        renderer = RENDERERS_BY_PAGE.get(page.name, "wiki")
        if renderer in ("wiki", "reddit"):
            content = VMarkdown(("content"), renderer=renderer).run(content)

        # Use the raw POST value as we need to tell the difference between
        # None/Undefined and an empty string.  The validators use a default
        # value with both of those cases and would need to be changed.
        # In order to avoid breaking functionality, this was done instead.
        previous = previous._id if previous else request.POST.get("previous")
        try:
            # special validation methods
            if page.name == "config/stylesheet":
                css_errors, parsed = c.site.parse_css(content, verify=False)
                if g.css_killswitch:
                    self.handle_error(403, "STYLESHEET_EDIT_DENIED")
                if css_errors:
                    error_items = [CssError(x).message for x in css_errors]
                    self.handle_error(415, "SPECIAL_ERRORS", special_errors=error_items)
            elif page.name == "config/automoderator":
                try:
                    rules = Ruleset(content)
                except ValueError as e:
                    error_items = [e.message]
                    self.handle_error(415, "SPECIAL_ERRORS", special_errors=error_items)

            # special saving methods
            if page.name == "config/stylesheet":
                c.site.change_css(content, parsed, previous, reason=reason)
            else:
                try:
                    page.revise(content, previous, c.user._id36, reason=reason)
                except ContentLengthError as e:
                    self.handle_error(403, "CONTENT_LENGTH_ERROR", max_length=e.max_length)

                # continue storing the special pages as data attributes on the subreddit
                # object. TODO: change this to minimize subreddit get sizes.
                if page.special and page.name in ATTRIBUTE_BY_PAGE:
                    setattr(c.site, ATTRIBUTE_BY_PAGE[page.name], content)
                    c.site._commit()

                if page.special or c.is_wiki_mod:
                    description = modactions.get(page.name, "Page %s edited" % page.name)
                    ModAction.create(c.site, c.user, "wikirevise", details=description)
        except ConflictException as e:
            self.handle_error(409, "EDIT_CONFLICT", newcontent=e.new, newrevision=page.revision, diffcontent=e.htmldiff)
        return json.dumps({})
开发者ID:justcool393,项目名称:reddit,代码行数:60,代码来源:wiki.py

示例2: POST_wiki_edit

    def POST_wiki_edit(self, pageandprevious, content):
        page, previous = pageandprevious
        previous = previous._id if previous else None
        try:
            if page.name == 'config/stylesheet':
                report, parsed = c.site.parse_css(content, verify=False)
                if report is None: # g.css_killswitch
                    self.handle_error(403, 'STYLESHEET_EDIT_DENIED')
                if report.errors:
                    error_items = [x.message for x in sorted(report.errors)]
                    self.handle_error(415, 'SPECIAL_ERRORS', special_errors=error_items)
                c.site.change_css(content, parsed, previous, reason=request.POST['reason'])
            else:
                try:
                    page.revise(content, previous, c.user.name, reason=request.POST['reason'])
                except ContentLengthError as e:
                    self.handle_error(403, 'CONTENT_LENGTH_ERROR', max_length = e.max_length)

                # continue storing the special pages as data attributes on the subreddit
                # object. TODO: change this to minimize subreddit get sizes.
                if page.special:
                    setattr(c.site, ATTRIBUTE_BY_PAGE[page.name], content)
                    setattr(c.site, "prev_" + ATTRIBUTE_BY_PAGE[page.name] + "_id", str(page.revision))
                    c.site._commit()

                if page.special or c.is_wiki_mod:
                    description = modactions.get(page.name, 'Page %s edited' % page.name)
                    ModAction.create(c.site, c.user, 'wikirevise', details=description)
        except ConflictException as e:
            self.handle_error(409, 'EDIT_CONFLICT', newcontent=e.new, newrevision=page.revision, diffcontent=e.htmldiff)
        return json.dumps({})
开发者ID:etel,项目名称:reddit,代码行数:31,代码来源:wiki.py

示例3: POST_wiki_settings

    def POST_wiki_settings(self, page, permlevel, listed):
        """Update the permissions and visibility of wiki `page`"""
        oldpermlevel = page.permlevel
        if oldpermlevel != permlevel:
            VNotInTimeout().run(action_name="wikipermlevel",
                details_text="edit", target=page)
        if page.listed != listed:
            VNotInTimeout().run(action_name="wikipagelisted",
                details_text="edit", target=page)

        try:
            page.change_permlevel(permlevel)
        except ValueError:
            self.handle_error(403, 'INVALID_PERMLEVEL')
        if page.listed != listed:
            page.listed = listed
            page._commit()
            verb = 'Relisted' if listed else 'Delisted'
            description = '%s page %s' % (verb, page.name)
            ModAction.create(c.site, c.user, 'wikipagelisted',
                             description=description)
        if oldpermlevel != permlevel:
            description = 'Page: %s, Changed from %s to %s' % (
                page.name, oldpermlevel, permlevel
            )
            ModAction.create(c.site, c.user, 'wikipermlevel',
                             description=description)
        return self.GET_wiki_settings(page=page.name)
开发者ID:pra85,项目名称:reddit,代码行数:28,代码来源:wiki.py

示例4: POST_wiki_edit

    def POST_wiki_edit(self, pageandprevious, content):
        page, previous = pageandprevious
        # Use the raw POST value as we need to tell the difference between
        # None/Undefined and an empty string.  The validators use a default
        # value with both of those cases and would need to be changed. 
        # In order to avoid breaking functionality, this was done instead.
        previous = previous._id if previous else request.post.get('previous')
        try:
            if page.name == 'config/stylesheet':
                report, parsed = c.site.parse_css(content, verify=False)
                if report is None: # g.css_killswitch
                    self.handle_error(403, 'STYLESHEET_EDIT_DENIED')
                if report.errors:
                    error_items = [x.message for x in sorted(report.errors)]
                    self.handle_error(415, 'SPECIAL_ERRORS', special_errors=error_items)
                c.site.change_css(content, parsed, previous, reason=request.POST['reason'])
            else:
                try:
                    page.revise(content, previous, c.user.name, reason=request.POST['reason'])
                except ContentLengthError as e:
                    self.handle_error(403, 'CONTENT_LENGTH_ERROR', max_length = e.max_length)

                # continue storing the special pages as data attributes on the subreddit
                # object. TODO: change this to minimize subreddit get sizes.
                if page.special:
                    setattr(c.site, ATTRIBUTE_BY_PAGE[page.name], content)
                    setattr(c.site, "prev_" + ATTRIBUTE_BY_PAGE[page.name] + "_id", str(page.revision))
                    c.site._commit()

                if page.special or c.is_wiki_mod:
                    description = modactions.get(page.name, 'Page %s edited' % page.name)
                    ModAction.create(c.site, c.user, 'wikirevise', details=description)
        except ConflictException as e:
            self.handle_error(409, 'EDIT_CONFLICT', newcontent=e.new, newrevision=page.revision, diffcontent=e.htmldiff)
        return json.dumps({})
开发者ID:Anenome,项目名称:reddit,代码行数:35,代码来源:wiki.py

示例5: POST_wiki_settings

 def POST_wiki_settings(self, page, permlevel):
     oldpermlevel = page.permlevel
     try:
         page.change_permlevel(permlevel)
     except ValueError:
         self.handle_error(403, 'INVALID_PERMLEVEL')
     description = 'Page: %s, Changed from %s to %s' % (page.name, oldpermlevel, permlevel)
     ModAction.create(c.site, c.user, 'wikipermlevel', description=description)
     return self.GET_wiki_settings(page=page.name)
开发者ID:BenHalberstam,项目名称:reddit,代码行数:9,代码来源:wiki.py

示例6: POST_wiki_edit

    def POST_wiki_edit(self, pageandprevious, content, page_name, reason):
        """Edit a wiki `page`"""
        page, previous = pageandprevious

        if not page:
            error = c.errors.get(('WIKI_CREATE_ERROR', 'page'))
            if error:
                self.handle_error(403, **(error.msg_params or {}))
            if not c.user._spam:
                page = WikiPage.create(c.site, page_name)
        if c.user._spam:
            error = _("You are doing that too much, please try again later.")
            self.handle_error(415, 'SPECIAL_ERRORS', special_errors=[error])

        renderer = RENDERERS_BY_PAGE.get(page.name, 'wiki')
        if renderer in ('wiki', 'reddit'):
            content = VMarkdown(('content'), renderer=renderer).run(content)

        # Use the raw POST value as we need to tell the difference between
        # None/Undefined and an empty string.  The validators use a default
        # value with both of those cases and would need to be changed.
        # In order to avoid breaking functionality, this was done instead.
        previous = previous._id if previous else request.POST.get('previous')
        try:
            if page.name == 'config/stylesheet':
                report, parsed = c.site.parse_css(content, verify=False)
                if report is None:  # g.css_killswitch
                    self.handle_error(403, 'STYLESHEET_EDIT_DENIED')
                if report.errors:
                    error_items = [x.message for x in sorted(report.errors)]
                    self.handle_error(415, 'SPECIAL_ERRORS', special_errors=error_items)
                c.site.change_css(content, parsed, previous, reason=reason)
            else:
                try:
                    page.revise(content, previous, c.user._id36, reason=reason)
                except ContentLengthError as e:
                    self.handle_error(403, 'CONTENT_LENGTH_ERROR', max_length=e.max_length)

                # continue storing the special pages as data attributes on the subreddit
                # object. TODO: change this to minimize subreddit get sizes.
                if page.special:
                    setattr(c.site, ATTRIBUTE_BY_PAGE[page.name], content)
                    setattr(c.site, "prev_" + ATTRIBUTE_BY_PAGE[page.name] + "_id", page.revision)
                    c.site._commit()

                if page.special or c.is_wiki_mod:
                    description = modactions.get(page.name, 'Page %s edited' % page.name)
                    ModAction.create(c.site, c.user, 'wikirevise', details=description)
        except ConflictException as e:
            self.handle_error(409, 'EDIT_CONFLICT', newcontent=e.new, newrevision=page.revision, diffcontent=e.htmldiff)
        return json.dumps({})
开发者ID:BenSloboda,项目名称:reddit,代码行数:51,代码来源:wiki.py

示例7: set_flair

    def set_flair(self, subreddit, text=None, css_class=None, set_by=None, log_details="edit"):
        log_details = "flair_%s" % log_details
        if not text and not css_class:
            # set to None instead of potentially empty strings
            text = css_class = None
            subreddit.remove_flair(self)
            log_details = "flair_delete"
        elif not subreddit.is_flair(self):
            subreddit.add_flair(self)

        setattr(self, "flair_%s_text" % subreddit._id, text)
        setattr(self, "flair_%s_css_class" % subreddit._id, css_class)
        self._commit()

        if set_by and set_by != self:
            ModAction.create(subreddit, set_by, action="editflair", target=self, details=log_details)
开发者ID:zeantsoi,项目名称:reddit,代码行数:16,代码来源:account.py

示例8: POST_wiki_settings

 def POST_wiki_settings(self, page, permlevel, listed):
     """Update the permissions and visibility of wiki `page`"""
     oldpermlevel = page.permlevel
     try:
         page.change_permlevel(permlevel)
     except ValueError:
         self.handle_error(403, "INVALID_PERMLEVEL")
     if page.listed != listed:
         page.listed = listed
         page._commit()
         verb = "Relisted" if listed else "Delisted"
         description = "%s page %s" % (verb, page.name)
         ModAction.create(c.site, c.user, "wikipagelisted", description=description)
     if oldpermlevel != permlevel:
         description = "Page: %s, Changed from %s to %s" % (page.name, oldpermlevel, permlevel)
         ModAction.create(c.site, c.user, "wikipermlevel", description=description)
     return self.GET_wiki_settings(page=page.name)
开发者ID:justcool393,项目名称:reddit,代码行数:17,代码来源:wiki.py

示例9: POST_wiki_settings

 def POST_wiki_settings(self, page, permlevel, listed):
     oldpermlevel = page.permlevel
     try:
         page.change_permlevel(permlevel)
     except ValueError:
         self.handle_error(403, 'INVALID_PERMLEVEL')
     if page.listed != listed:
         page.listed = listed
         page._commit()
         verb = 'Relisted' if listed else 'Delisted'
         description = '%s page %s' % (verb, page.name)
         ModAction.create(c.site, c.user, 'wikipagelisted',
                          description=description)
     if oldpermlevel != permlevel:
         description = 'Page: %s, Changed from %s to %s' % (
             page.name, oldpermlevel, permlevel
         )
         ModAction.create(c.site, c.user, 'wikipermlevel',
                          description=description)
     return self.GET_wiki_settings(page=page.name)
开发者ID:Bacce,项目名称:reddit,代码行数:20,代码来源:wiki.py

示例10: POST_wiki_edit

 def POST_wiki_edit(self, pageandprevious, content):
     page, previous = pageandprevious
     previous = previous._id if previous else None
     try:
         if page.name == 'config/stylesheet':
             report, parsed = c.site.parse_css(content, verify=False)
             if report is None: # g.css_killswitch
                 self.handle_error(403, 'STYLESHEET_EDIT_DENIED')
             if report.errors:
                 error_items = [x.message for x in sorted(report.errors)]
                 self.handle_error(415, 'SPECIAL_ERRORS', special_errors=error_items)
             c.site.change_css(content, parsed, previous, reason=request.POST['reason'])
         else:
             try:
                 page.revise(content, previous, c.user.name, reason=request.POST['reason'])
             except ContentLengthError as e:
                 self.handle_error(403, 'CONTENT_LENGTH_ERROR', max_length = e.max_length)
             if page.special or c.is_wiki_mod:
                 description = modactions.get(page.name, 'Page %s edited' % page.name)
                 ModAction.create(c.site, c.user, 'wikirevise', details=description)
     except ConflictException as e:
         self.handle_error(409, 'EDIT_CONFLICT', newcontent=e.new, newrevision=page.revision, diffcontent=e.htmldiff)
     return json.dumps({})
开发者ID:CryptArc,项目名称:reddit,代码行数:23,代码来源:wiki.py


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