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()
Esempio n. 2
0
 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)
Esempio n. 3
0
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
Esempio n. 4
0
    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()
Esempio n. 5
0
    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()
Esempio n. 6
0
    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()
Esempio n. 7
0
    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()
Esempio n. 8
0
File: pages.py Progetto: cmak/reddit
 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
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
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 == 'api' or ext.startswith('json'):
            c.response_access_control = 'allow <*>'
        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['reddit_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['reddit_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
Esempio n. 12
0
 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")
Esempio n. 13
0
File: pages.py Progetto: vin/reddit
 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")
Esempio n. 14
0
 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)
Esempio n. 15
0
File: front.py Progetto: NkL4/reddit
    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,
                                        cloneable = True))

        if previous_visits:
            displayPane.append(CommentVisitsBox(previous_visits))
            # Used in later "more comments" renderings
            pv_hex = md5(repr(previous_visits)).hexdigest()
            g.cache.set(pv_hex, previous_visits, time=g.comment_visits_period)
            c.previous_visits_hex = pv_hex

        # Used in template_helpers
        c.previous_visits = previous_visits

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

        subtitle_buttons = []

        if c.focal_comment or context is not None:
            subtitle = None
        elif article.num_comments == 0:
            subtitle = _("no comments (yet)")
        elif article.num_comments <= num:
            subtitle = _("all %d comments") % article.num_comments
        else:
            subtitle = _("top %d comments") % num

            if g.max_comments > num:
                self._add_show_comments_link(subtitle_buttons, article, num,
                                             g.max_comments, gold=False)

            if (c.user_is_loggedin and c.user.gold
                and article.num_comments > g.max_comments):
                self._add_show_comments_link(subtitle_buttons, article, num,
                                             g.max_comments_gold, gold=True)

        res = LinkInfoPage(link = article, comment = comment,
                           content = displayPane,
                           subtitle = subtitle,
                           subtitle_buttons = subtitle_buttons,
                           nav_menus = [CommentSortMenu(default = sort)],
                           infotext = infotext).render()
        return res
Esempio n. 16
0
    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,
                                        cloneable = True))

        if previous_visits:
            displayPane.append(CommentVisitsBox(previous_visits))
            # Used in later "more comments" renderings
            pv_hex = md5(repr(previous_visits)).hexdigest()
            g.cache.set(pv_hex, previous_visits, time=g.comment_visits_period)
            c.previous_visits_hex = pv_hex

        # Used in template_helpers
        c.previous_visits = previous_visits

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

        subtitle_buttons = []

        if c.focal_comment or context is not None:
            subtitle = None
        elif article.num_comments == 0:
            subtitle = _("no comments (yet)")
        elif article.num_comments <= num:
            subtitle = _("all %d comments") % article.num_comments
        else:
            subtitle = _("top %d comments") % num

            if g.max_comments > num:
                self._add_show_comments_link(subtitle_buttons, article, num,
                                             g.max_comments, gold=False)

            if (c.user_is_loggedin and c.user.gold
                and article.num_comments > g.max_comments):
                self._add_show_comments_link(subtitle_buttons, article, num,
                                             g.max_comments_gold, gold=True)

        res = LinkInfoPage(link = article, comment = comment,
                           content = displayPane,
                           subtitle = subtitle,
                           subtitle_buttons = subtitle_buttons,
                           nav_menus = [CommentSortMenu(default = sort)],
                           infotext = infotext).render()
        return res
Esempio n. 17
0
    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
Esempio n. 18
0
    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
        # 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 = not bool(comment)
            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
Esempio n. 19
0
 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()
Esempio n. 20
0
 def GET_about(self, vuser):
     if not is_api() or not vuser:
         return self.abort404()
     return Reddit(content = Wrapped(vuser)).render()
Esempio n. 21
0
 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()
Esempio n. 22
0
    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
 def GET_about(self, vuser):
     if not is_api() or not vuser:
         return self.abort404()
     return Reddit(content=Wrapped(vuser)).render()