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


Python jsontemplates.is_api函数代码示例

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


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

示例1: GET_about

    def GET_about(self, vuser):
        print "API?"
	print is_api()
	print "Vuser"
	print "|%s|" % vuser
        if not is_api() or not vuser:
            return self.abort404()
        return Sciteit(content = Wrapped(vuser)).render()
开发者ID:constantAmateur,项目名称:sciteit,代码行数:8,代码来源:listingcontroller.py

示例2: GET_about

    def GET_about(self):
        """Return information about the subreddit.

        Data includes the subscriber count, description, and header image."""
        if not is_api() or isinstance(c.site, FakeSubreddit):
            return self.abort404()
        return Reddit(content = Wrapped(c.site)).render()
开发者ID:Brijen,项目名称:reddit,代码行数:7,代码来源:front.py

示例3: set_content_type

def set_content_type():
    e = request.environ
    c.render_style = e["render_style"]
    c.response_content_type = e["content_type"]

    if e.has_key("extension"):
        c.extension = ext = e["extension"]
        if ext in ("embed", "wired", "widget"):

            def to_js(content):
                return utils.to_js(content, callback=request.params.get("callback", "document.write"))

            c.response_wrappers.append(to_js)
        if ext in ("rss", "api", "json") and request.method.upper() == "GET":
            user = valid_feed(request.GET.get("user"), request.GET.get("feed"), request.path)
            if user and not g.read_only_mode:
                c.user = user
                c.user_is_loggedin = True
        if ext in ("mobile", "m") and not request.GET.get("keep_extension"):
            try:
                if request.cookies["sciteit_mobility"] == "compact":
                    c.extension = "compact"
                    c.render_style = "compact"
            except (ValueError, KeyError):
                c.suggest_compact = True
        if ext in ("mobile", "m", "compact"):
            if request.GET.get("keep_extension"):
                c.cookies["sciteit_mobility"] = Cookie(ext, expires=NEVER)
    # allow JSONP requests to generate callbacks, but do not allow
    # the user to be logged in for these
    if is_api() and request.method.upper() == "GET" and request.GET.get("jsonp"):
        c.allowed_callback = request.GET["jsonp"]
        c.user = UnloggedUser(get_browser_langs())
        c.user_is_loggedin = False
开发者ID:constantAmateur,项目名称:sciteit,代码行数:34,代码来源:sciteit_base.py

示例4: _edit_normal_reddit

    def _edit_normal_reddit(self, location, num, after, reverse, count, created,
                            name, user):
        # moderator is either reddit's moderator or an admin
        is_moderator = c.user_is_loggedin and c.site.is_moderator(c.user) or c.user_is_admin
        extension_handling = False
        if is_moderator and location == 'edit':
            pane = PaneStack()
            if created == 'true':
                pane.append(InfoBar(message = strings.sr_created))
            c.allow_styles = True
            c.site = Subreddit._byID(c.site._id, data=True, stale=False)
            pane.append(CreateSubreddit(site = c.site))
        elif location == 'moderators':
            pane = ModList(editable = is_moderator)
        elif is_moderator and location == 'banned':
            pane = BannedList(editable = is_moderator)
        elif (location == 'contributors' and
              # On public reddits, only moderators can see the whitelist.
              # On private reddits, all contributors can see each other.
              (c.site.type != 'public' or
               (c.user_is_loggedin and
                (c.site.is_moderator(c.user) or c.user_is_admin)))):
                pane = ContributorList(editable = is_moderator)
        elif (location == 'stylesheet'
              and c.site.can_change_stylesheet(c.user)
              and not g.css_killswitch):
            if hasattr(c.site,'stylesheet_contents_user') and c.site.stylesheet_contents_user:
                stylesheet_contents = c.site.stylesheet_contents_user
            elif hasattr(c.site,'stylesheet_contents') and c.site.stylesheet_contents:
                stylesheet_contents = c.site.stylesheet_contents
            else:
                stylesheet_contents = ''
            c.allow_styles = True
            pane = SubredditStylesheet(site = c.site,
                                       stylesheet_contents = stylesheet_contents)
        elif location in ('reports', 'spam', 'trials', 'modqueue') and is_moderator:
            c.allow_styles = True
            pane = self._make_spamlisting(location, num, after, reverse, count)
            if c.user.pref_private_feeds:
                extension_handling = "private"
        elif is_moderator and location == 'traffic':
            pane = RedditTraffic()
        elif is_moderator and location == 'flair':
            c.allow_styles = True
            pane = FlairPane(num, after, reverse, name, user)
        elif c.user_is_sponsor and location == 'ads':
            pane = RedditAds()
        elif (location == "about") and is_api():
            return self.redirect(add_sr('about.json'), code=301)
        else:
            return self.abort404()

        return EditReddit(content=pane,
                          location=location,
                          extension_handling=extension_handling).render()
开发者ID:ProfNandaa,项目名称:reddit,代码行数:55,代码来源:front.py

示例5: render

 def render(self, *a, **kw):
     """Overrides default Wrapped.render with two additions
        * support for rendering API requests with proper wrapping
        * support for space compression of the result
     In adition, unlike Wrapped.render, the result is in the form of a pylons
     Response object with it's content set.
     """
     res = Wrapped.render(self, *a, **kw)
     if is_api():
         res = json_respond(res)
     elif self.space_compress:
         res = spaceCompress(res)
     c.response.content = res
     return c.response
开发者ID:cmak,项目名称:reddit,代码行数:14,代码来源:pages.py

示例6: GET_listing

 def GET_listing(self, where, mark, message, subwhere = None, **env):
     if not (c.default_sr or c.site.is_moderator(c.user) or c.user_is_admin):
         abort(403, "forbidden")
     if not c.default_sr:
         self.where = "moderator"
     else:
         self.where = where
     self.subwhere = subwhere
     if mark is not None:
         self.mark = mark
     elif is_api():
         self.mark = 'false'
     elif c.render_style and c.render_style == "xml":
         self.mark = 'false'
     else:
         self.mark = 'true'
     self.message = message
     return ListingController.GET_listing(self, **env)
开发者ID:AmbroiseKritz,项目名称:reddit,代码行数:18,代码来源:listingcontroller.py

示例7: render

 def render(self, *a, **kw):
     """Overrides default Wrapped.render with two additions
        * support for rendering API requests with proper wrapping
        * support for space compression of the result
     In adition, unlike Wrapped.render, the result is in the form of a pylons
     Response object with it's content set.
     """
     try:
         res = Wrapped.render(self, *a, **kw)
         if is_api():
             res = json_respond(res)
         elif self.space_compress:
             res = spaceCompress(res)
         c.response.content = res
     except NoTemplateFound, e:
         # re-raise the error -- development environment
         if g.debug:
             s = sys.exc_info()
             raise s[1], None, s[2]
         # die gracefully -- production environment
         else:
             abort(404, "not found")
开发者ID:vin,项目名称:reddit,代码行数:22,代码来源:pages.py

示例8: GET_listing

 def GET_listing(self, where, mark, message, subwhere = None, **env):
     if not (c.default_sr or c.site.is_moderator(c.user) or c.user_is_admin):
         abort(403, "forbidden")
     if isinstance(c.site, MultiReddit):
         srs = Subreddit._byID(c.site.sr_ids, data=False, return_dict=False)
         if not (c.user_is_admin or Subreddit.user_mods_all(c.user, srs)):
             self.abort403()
         self.where = "multi"
         self.srs = srs
     elif isinstance(c.site, ModSR) or not c.default_sr:
         self.where = "moderator"
     else:
         self.where = where
     self.subwhere = subwhere
     if mark is not None:
         self.mark = mark
     elif is_api():
         self.mark = 'false'
     elif c.render_style and c.render_style == "xml":
         self.mark = 'false'
     else:
         self.mark = 'true'
     self.message = message
     return ListingController.GET_listing(self, **env)
开发者ID:jkkorn,项目名称:reddit,代码行数:24,代码来源:listingcontroller.py

示例9: GET_comments

    def GET_comments(self, article, comment, context, sort, num_comments,
                     limit, depth):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        sr = Subreddit._byID(article.sr_id, True)

        if sr.name == g.takedown_sr:
            request.environ['REDDIT_TAKEDOWN'] = article._fullname
            return self.abort404()

        if not c.default_sr and c.site._id != sr._id:
            return self.abort404()

        if not can_view_link_comments(article):
            abort(403, 'forbidden')

        #check for 304
        self.check_modified(article, 'comments')

        # if there is a focal comment, communicate down to
        # comment_skeleton.html who that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        # figure out number to show based on the menu (when num_comments
        # is 'true', the user wants to temporarily override their
        # comments limit pref
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == 'true' else user_num

        kw = {}
        # allow depth to be reset (I suspect I'll turn the VInt into a
        # validator on my next pass of .compact)
        if depth is not None and 0 < depth < MAX_RECURSION:
            kw['max_depth'] = depth
        elif c.render_style == "compact":
            kw['max_depth'] = 5
        # allow the user's total count preferences to be overwritten
        # (think of .embed as the use case together with depth=1)x
        if limit is not None and 0 < limit < g.max_comments:
            num = limit

        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.make_permalink_slow()))

        # insert reply box only for logged in user
        if c.user_is_loggedin and can_comment_link(article) and not is_api():
            #no comment box for permalinks
            display = False
            if not comment:
                age = c.start_time - article._date
                if age.days < g.REPLY_AGE_LIMIT:
                    display = True
            displayPane.append(UserText(item = article, creating = True,
                                        post_form = 'comment',
                                        display = display,
                                        cloneable = True))

        # finally add the comment listing
        displayPane.append(CommentPane(article, CommentSortMenu.operator(sort),
                                       comment, context, num, **kw))

        loc = None if c.focal_comment or context is not None else 'comments'

        res = LinkInfoPage(link = article, comment = comment,
                           content = displayPane, 
                           subtitle = _("comments"),
                           nav_menus = [CommentSortMenu(default = sort), 
                                        NumCommentsMenu(article.num_comments,
                                                        default=num_comments)],
                           infotext = infotext).render()
        return res
开发者ID:JediWatchman,项目名称:reddit,代码行数:84,代码来源:front.py

示例10: GET_about

 def GET_about(self, vuser):
     if not is_api() or not vuser:
         return self.abort404()
     return Reddit(content = Wrapped(vuser)).render()
开发者ID:donslice,项目名称:reddit,代码行数:4,代码来源:listingcontroller.py

示例11: GET_comments

    def GET_comments(self, article, comment, context, sort, limit, depth):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        sr = Subreddit._byID(article.sr_id, True)

        if sr.name == g.takedown_sr:
            request.environ['REDDIT_TAKEDOWN'] = article._fullname
            return self.abort404()

        if not c.default_sr and c.site._id != sr._id:
            return self.abort404()

        if not can_view_link_comments(article):
            abort(403, 'forbidden')

        #check for 304
        self.check_modified(article, 'comments')

        # If there is a focal comment, communicate down to
        # comment_skeleton.html who that will be. Also, skip
        # comment_visits check
        previous_visits = None
        if comment:
            c.focal_comment = comment._id36
        elif (c.user_is_loggedin and c.user.gold and
              c.user.pref_highlight_new_comments):
            #TODO: remove this profiling if load seems okay
            from datetime import datetime
            before = datetime.now(g.tz)
            previous_visits = self._comment_visits(article, c.user, c.start_time)
            after = datetime.now(g.tz)
            delta = (after - before)
            msec = (delta.seconds * 1000 + delta.microseconds / 1000)
            if msec >= 100:
                g.log.warning("previous_visits code took %d msec" % msec)

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        if not c.user.pref_num_comments:
            num = g.num_comments
        elif c.user.gold:
            num = min(c.user.pref_num_comments, g.max_comments_gold)
        else:
            num = min(c.user.pref_num_comments, g.max_comments)

        kw = {}
        # allow depth to be reset (I suspect I'll turn the VInt into a
        # validator on my next pass of .compact)
        if depth is not None and 0 < depth < MAX_RECURSION:
            kw['max_depth'] = depth
        elif c.render_style == "compact":
            kw['max_depth'] = 5

        displayPane = PaneStack()

        # allow the user's total count preferences to be overwritten
        # (think of .embed as the use case together with depth=1)

        if limit and limit > 0:
            num = limit

        if c.user_is_loggedin and c.user.gold:
            if num > g.max_comments_gold:
                displayPane.append(InfoBar(message =
                                           strings.over_comment_limit_gold
                                           % max(0, g.max_comments_gold)))
                num = g.max_comments_gold
        elif num > g.max_comments:
            if limit:
                displayPane.append(InfoBar(message =
                                       strings.over_comment_limit
                                       % dict(max=max(0, g.max_comments),
                                              goldmax=max(0,
                                                   g.max_comments_gold))))
            num = g.max_comments

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.make_permalink_slow()))

        displayPane.append(LinkCommentSep())

        # insert reply box only for logged in user
        if c.user_is_loggedin and can_comment_link(article) and not is_api():
            #no comment box for permalinks
            display = False
            if not comment:
                age = c.start_time - article._date
                if age.days < g.REPLY_AGE_LIMIT:
                    display = True
            displayPane.append(UserText(item = article, creating = True,
                                        post_form = 'comment',
                                        display = display,
#.........这里部分代码省略.........
开发者ID:NkL4,项目名称:reddit,代码行数:101,代码来源:front.py

示例12: GET_comments

    def GET_comments(self, article, comment, context, sort, num_comments):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        if not c.default_sr and c.site._id != article.sr_id:
            return self.abort404()

        if not article.subreddit_slow.can_view(c.user):
            abort(403, "forbidden")

        # check for 304
        self.check_modified(article, "comments")

        # if there is a focal comment, communicate down to
        # comment_skeleton.html who that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get("already_submitted"):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating("comments")

        # figure out number to show based on the menu (when num_comments
        # is 'true', the user wants to temporarily override their
        # comments limit pref
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == "true" else user_num

        builder = CommentBuilder(article, CommentSortMenu.operator(sort), comment, context)
        listing = NestedListing(builder, num=num, parent_name=article._fullname)

        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.make_permalink_slow()))

        # insert reply box only for logged in user
        if c.user_is_loggedin and article.subreddit_slow.can_comment(c.user) and not is_api():
            # no comment box for permalinks
            displayPane.append(
                UserText(item=article, creating=True, post_form="comment", display=not bool(comment), cloneable=True)
            )

        # finally add the comment listing
        displayPane.append(listing.listing())

        loc = None if c.focal_comment or context is not None else "comments"

        res = LinkInfoPage(
            link=article,
            comment=comment,
            content=displayPane,
            subtitle=_("comments"),
            nav_menus=[CommentSortMenu(default=sort), NumCommentsMenu(article.num_comments, default=num_comments)],
            infotext=infotext,
        ).render()
        return res
开发者ID:rajbot,项目名称:tikical,代码行数:62,代码来源:front.py

示例13: GET_about

 def GET_about(self, vuser):
     """Return information about the user, including karma and gold status."""
     if not is_api() or not vuser:
         return self.abort404()
     return Reddit(content = Wrapped(vuser)).render()
开发者ID:A5,项目名称:reddit,代码行数:5,代码来源:listingcontroller.py


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