Example #1
0
    def make_permalink(self, sr, force_domain = False):
        from r2.lib.template_helpers import get_domain
        p = "comments/%s/%s/" % (self._id36, title_to_url(self.title))
        # promoted links belong to a separate subreddit and shouldn't
        # include that in the path
        if self.promoted is not None:
            if force_domain:
                res = "http://%s/%s" % (get_domain(cname = False,
                                                   subreddit = False), p)
            else:
                res = "/%s" % p
        elif not c.cname and not force_domain:
            res = "/r/%s/%s" % (sr.name, p)
        elif sr != c.site or force_domain:
            res = "http://%s/%s" % (get_domain(cname = (c.cname and
                                                        sr == c.site),
                                               subreddit = not c.cname), p)
        else:
            res = "/%s" % p

        # WARNING: If we ever decide to add any ?foo=bar&blah parameters
        # here, Comment.make_permalink will need to be updated or else
        # it will fail.

        return res
Example #2
0
    def make_permalink(self, sr, force_domain=False):
        from r2.lib.template_helpers import get_domain
        p = "comments/%s/%s/" % (self._id36, title_to_url(self.title))
        # promoted links belong to a separate subreddit and shouldn't
        # include that in the path
        if self.promoted is not None:
            if force_domain:
                res = "http://%s/%s" % (get_domain(cname=False,
                                                   subreddit=False), p)
            else:
                res = "/%s" % p
        elif not c.cname and not force_domain:
            res = "/r/%s/%s" % (sr.name, p)
        elif sr != c.site or force_domain:
            if (c.cname and sr == c.site):
                res = "http://%s/%s" % (get_domain(cname=True,
                                                   subreddit=False), p)
            else:
                res = "http://%s/r/%s/%s" % (get_domain(
                    cname=False, subreddit=False), sr.name, p)
        else:
            res = "/%s" % p

        # WARNING: If we ever decide to add any ?foo=bar&blah parameters
        # here, Comment.make_permalink will need to be updated or else
        # it will fail.

        return res
def request_start():
    # don't process ErrorController requests
    if request.environ.get("pylons.error_call", False):
        return

    cookie_name = 'beta_' + g.beta_name
    c.beta = g.beta_name if cookie_name in request.cookies else None

    if not c.beta and request.host != g.beta_domain:
        # a regular site url without a beta cookie got sent to a beta app.
        # this is a configuration error that should not happen in practice, and
        # can cause redirect loops if we're not careful.
        raise ConfigurationError('request missing beta cookie')

    # run our own authentication check to sidestep c.user overrides such as the
    # logged-out override for JSONP.
    user = authentication.cookie()
    user_allowed = user and beta_user_allowed(user)

    if request.path.startswith('/beta'):
        if request.host != g.beta_domain:
            # canonicalize /beta urls to beta domain for clarity.
            redirect_to_host(g.beta_domain)
    else:
        if request.host == g.beta_domain:
            # redirect non-/beta requests on the beta domain to default domain.
            redirect_to_host(get_domain(subreddit=False))

        if not user_allowed:
            # they have a beta cookie but are not permitted access.
            # this should hopefully only happen in corner cases (access
            # changed or they somehow logged out without deleting the beta
            # cookie)
            if (request.method == 'GET'
                    and response.content_type == 'text/html'):
                # redirect to /beta/disable/NAME, which will delete the cookie.
                redirect_to_host(g.beta_domain, '/beta/disable')
            else:
                # attempt to delete the cookie and redirect-retry.
                #
                # note: this redirect might result in a loop if the request on the
                # default domain is also served by this beta app, which is one
                # reason we strictly check and throw an error if this is the case
                # above.
                delete_beta_cookie()
                redirect_to_host(get_domain(subreddit=False))

        # extend cookie duration for a week
        touch_beta_cookie()
def request_start():
    # don't process ErrorController requests
    if request.environ.get("pylons.error_call", False):
        return

    cookie_name = 'beta_' + g.beta_name
    c.beta = g.beta_name if cookie_name in request.cookies else None

    if not c.beta and request.host != g.beta_domain:
        # a regular site url without a beta cookie got sent to a beta app.
        # this is a configuration error that should not happen in practice, and
        # can cause redirect loops if we're not careful.
        raise ConfigurationError('request missing beta cookie')

    # run our own authentication check to sidestep c.user overrides such as the
    # logged-out override for JSONP.
    user = authentication.cookie()
    user_allowed = user and beta_user_allowed(user)

    if request.path.startswith('/beta'):
        if request.host != g.beta_domain:
            # canonicalize /beta urls to beta domain for clarity.
            redirect_to_host(g.beta_domain)
    else:
        if request.host == g.beta_domain:
            # redirect non-/beta requests on the beta domain to default domain.
            redirect_to_host(get_domain(subreddit=False))

        if not user_allowed:
            # they have a beta cookie but are not permitted access.
            # this should hopefully only happen in corner cases (access
            # changed or they somehow logged out without deleting the beta
            # cookie)
            if (request.method == 'GET' and
                    response.content_type == 'text/html'):
                # redirect to /beta/disable/NAME, which will delete the cookie.
                redirect_to_host(g.beta_domain, '/beta/disable')
            else:
                # attempt to delete the cookie and redirect-retry.
                #
                # note: this redirect might result in a loop if the request on the
                # default domain is also served by this beta app, which is one
                # reason we strictly check and throw an error if this is the case
                # above.
                delete_beta_cookie()
                redirect_to_host(get_domain(subreddit=False))

        # extend cookie duration for a week
        touch_beta_cookie()
Example #5
0
    def make_permalink(self, sr, force_domain = False, sr_path = False):
        from r2.lib.template_helpers import get_domain

        def slug():
            """
            Retrieves the original URL slug (if any) to prevent the
            URL from changing when the article title is updated.
            """
            # This could probably just check for `self.url == None`.
            if not isinstance(self.url, basestring):
                return self.title

            regex = re.compile("""
              /ea                   # subreddit
              /[^/]+                # ID
              /(?P<title>[^/]+)/    # title
            """, re.X)
            match = regex.match(self.url)
            if match:
                return match.group("title")
            else:
                return title_to_url(self.title)

        p = "ea/%s/%s/" % (self._id36, slug())
        if c.default_sr and not sr_path:
            res = "/%s" % p
        elif sr and not c.cname:
            res = "/r/%s/%s" % (sr.name, p)
        elif sr != c.site or force_domain:
            res = "http://%s/%s" % (get_domain(cname = (c.cname and sr == c.site),
                                               subreddit = not c.cname), p)
        else:
            res = "/%s" % p
        return res
Example #6
0
    def make_permalink(self, sr, force_domain=False, sr_path=False):
        from r2.lib.template_helpers import get_domain

        def slug():
            """
            Retrieves the original URL slug (if any) to prevent the
            URL from changing when the article title is updated.
            """
            # This could probably just check for `self.url == None`.
            if not isinstance(self.url, basestring):
                return self.title

            regex = re.compile(
                """
              /ea                   # subreddit
              /[^/]+                # ID
              /(?P<title>[^/]+)/    # title
            """, re.X)
            match = regex.match(self.url)
            if match:
                return match.group("title")
            else:
                return title_to_url(self.title)

        p = "ea/%s/%s/" % (self._id36, slug())
        if c.default_sr and not sr_path:
            res = "/%s" % p
        elif sr and not c.cname:
            res = "/r/%s/%s" % (sr.name, p)
        elif sr != c.site or force_domain:
            res = "http://%s/%s" % (get_domain(
                cname=(c.cname and sr == c.site), subreddit=not c.cname), p)
        else:
            res = "/%s" % p
        return res
Example #7
0
    def GET_search(self, query, num, reverse, after, count, sort):
        """Search links page."""
        if query and '.' in query:
            url = sanitize_url(query, require_scheme = True)
            if url:
                return self.redirect("/submit" + query_string({'url':url}))

        q = IndextankQuery(query, c.site, sort)

        num, t, spane = self._search(q, num = num, after = after, reverse = reverse,
                                     count = count)

        if not isinstance(c.site,FakeSubreddit) and not c.cname:
            all_reddits_link = "%s/search%s" % (subreddit.All.path,
                                                query_string({'q': query}))
            d =  {'reddit_name':      c.site.name,
                  'reddit_link':      "http://%s/"%get_domain(cname = c.cname),
                  'all_reddits_link': all_reddits_link}
            infotext = strings.searching_a_reddit % d
        else:
            infotext = None

        res = SearchPage(_('search results'), query, t, num, content=spane,
                         nav_menus = [SearchSortMenu(default=sort)],
                         search_params = dict(sort = sort),
                         infotext = infotext).render()

        return res
Example #8
0
    def stylesheet_url(self):
        from r2.lib.template_helpers import static, get_domain

        if self.stylesheet_is_static:
            return static(self.static_stylesheet_name)
        else:
            return "http://%s/stylesheet.css?v=%s" % (get_domain(cname=False, subreddit=True), self.stylesheet_hash)
Example #9
0
    def submit_link(self):
        from r2.lib.template_helpers import get_domain
        from mako.filters import url_escape

        d = get_domain(subreddit=False)
        u = self.url()

        return "http://%s/r/ads/submit?url=%s" % (d, url_escape(u))
Example #10
0
    def submit_link(self):
        from r2.lib.template_helpers import get_domain
        from mako.filters import url_escape

        d = get_domain(subreddit=False)
        u = self.url()

        return "http://%s/r/ads/submit?url=%s" % (d, url_escape(u))
Example #11
0
    def stylesheet_url(self):
        from r2.lib.template_helpers import static, get_domain

        if self.stylesheet_is_static:
            return static(self.static_stylesheet_name)
        else:
            return "http://%s/stylesheet.css?v=%s" % (get_domain(
                cname=False, subreddit=True), self.stylesheet_hash)
Example #12
0
    def GET_search(self, query, num, time, reverse, after, count, langs, sort):
        """Search links page."""
        if query and '.' in query:
            url = sanitize_url(query, require_scheme=True)
            if url:
                return self.redirect("/submit" + query_string({'url': url}))

        if langs and self.verify_langs_regex.match(langs):
            langs = langs.split(',')
        else:
            langs = c.content_langs

        subreddits = None
        authors = None
        if c.site == subreddit.Friends and c.user_is_loggedin and c.user.friends:
            authors = c.user.friends
        elif isinstance(c.site, MultiReddit):
            subreddits = c.site.sr_ids
        elif not isinstance(c.site, FakeSubreddit):
            subreddits = [c.site._id]

        q = LinkSearchQuery(
            q=query,
            timerange=time,
            langs=langs,
            subreddits=subreddits,
            authors=authors,
            sort=SearchSortMenu.operator(sort))

        num, t, spane = self._search(
            q, num=num, after=after, reverse=reverse, count=count)

        if not isinstance(c.site, FakeSubreddit) and not c.cname:
            all_reddits_link = "%s/search%s" % (subreddit.All.path,
                                                query_string({
                                                    'q': query
                                                }))
            d = {
                'reddit_name': c.site.name,
                'reddit_link': "http://%s/" % get_domain(cname=c.cname),
                'all_reddits_link': all_reddits_link
            }
            infotext = strings.searching_a_reddit % d
        else:
            infotext = None

        res = SearchPage(
            _('search results'),
            query,
            t,
            num,
            content=spane,
            nav_menus=[TimeMenu(default=time),
                       SearchSortMenu(default=sort)],
            search_params=dict(sort=sort, t=time),
            infotext=infotext).render()

        return res
Example #13
0
    def GET_search(self, query, num, time, reverse, after, count, langs, sort):
        """Search links page."""
        if query and '.' in query:
            url = sanitize_url(query, require_scheme=True)
            if url:
                return self.redirect("/submit" + query_string({'url': url}))

        if langs and self.verify_langs_regex.match(langs):
            langs = langs.split(',')
        else:
            langs = c.content_langs

        subreddits = None
        authors = None
        if c.site == subreddit.Friends and c.user_is_loggedin and c.user.friends:
            authors = c.user.friends
        elif isinstance(c.site, MultiReddit):
            subreddits = c.site.sr_ids
        elif not isinstance(c.site, FakeSubreddit):
            subreddits = [c.site._id]

        q = LinkSearchQuery(q=query,
                            timerange=time,
                            langs=langs,
                            subreddits=subreddits,
                            authors=authors,
                            sort=SearchSortMenu.operator(sort))

        num, t, spane = self._search(q,
                                     num=num,
                                     after=after,
                                     reverse=reverse,
                                     count=count)

        if not isinstance(c.site, FakeSubreddit) and not c.cname:
            all_reddits_link = "%s/search%s" % (subreddit.All.path,
                                                query_string({'q': query}))
            d = {
                'reddit_name': c.site.name,
                'reddit_link': "http://%s/" % get_domain(cname=c.cname),
                'all_reddits_link': all_reddits_link
            }
            infotext = strings.searching_a_reddit % d
        else:
            infotext = None

        res = SearchPage(
            _('search results'),
            query,
            t,
            num,
            content=spane,
            nav_menus=[TimeMenu(default=time),
                       SearchSortMenu(default=sort)],
            search_params=dict(sort=sort, t=time),
            infotext=infotext).render()

        return res
Example #14
0
 def make_permalink(self, force_domain=False):
     from r2.lib.template_helpers import get_domain
     p = self.permalink
     if force_domain:
         permalink_domain = get_domain(subreddit=False)
         res = "%s://%s%s" % (g.default_scheme, permalink_domain, p)
     else:
         res = p
     return res
Example #15
0
    def make_permalink(self, force_domain=False):
        from r2.lib.template_helpers import get_domain

        p = self.permalink
        if force_domain:
            permalink_domain = get_domain(subreddit=False)
            res = "%s://%s%s" % (g.default_scheme, permalink_domain, p)
        else:
            res = p
        return res
Example #16
0
File: link.py Project: vin/reddit
 def make_permalink(self, sr, force_domain = False):
     from r2.lib.template_helpers import get_domain
     p = "comments/%s/%s/" % (self._id36, title_to_url(self.title))
     if not c.cname:
         res = "/r/%s/%s" % (sr.name, p)
     elif sr != c.site or force_domain:
         res = "http://%s/%s" % (get_domain(cname = (c.cname and sr == c.site),
                                            subreddit = not c.cname), p)
     else:
         res = "/%s" % p
     return res
Example #17
0
 def __init__(self, original_path, subreddit, sub_domain):
     Wrapped.__init__(self, original_path=original_path)
     if sub_domain and subreddit and original_path:
         self.title = "%s - %s" % (subreddit.title, sub_domain)
         u = UrlParser(subreddit.path + original_path)
         u.hostname = get_domain(cname = False, subreddit = False)
         u.update_query(**request.get.copy())
         u.put_in_frame()
         self.frame_target = u.unparse()
     else:
         self.title = ""
         self.frame_target = None
Example #18
0
File: pages.py Project: vin/reddit
 def __init__(self, original_path, subreddit, sub_domain):
     Wrapped.__init__(self, original_path=original_path)
     if sub_domain and subreddit and original_path:
         self.title = "%s - %s" % (subreddit.title, sub_domain)
         u = UrlParser(subreddit.path + original_path)
         u.hostname = get_domain(cname = False, subreddit = False)
         u.update_query(**request.get.copy())
         u.put_in_frame()
         self.frame_target = u.unparse()
     else:
         self.title = ""
         self.frame_target = None
Example #19
0
 def make_permalink(self, sr, force_domain=False, sr_path=False):
     from r2.lib.template_helpers import get_domain
     p = "lw/%s/%s/" % (self._id36, title_to_url(self.title))
     if c.default_sr and not sr_path:
         res = "/%s" % p
     elif sr and not c.cname:
         res = "/r/%s/%s" % (sr.name, p)
     elif sr != c.site or force_domain:
         res = "http://%s/%s" % (get_domain(
             cname=(c.cname and sr == c.site), subreddit=not c.cname), p)
     else:
         res = "/%s" % p
     return res
def render_iframe_arrows(context,thing):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, '__anon_0x7f21644298d0')._populate(_import_ns, [u'optionalstyle'])
        _mako_get_namespace(context, '__anon_0x7f2164429990')._populate(_import_ns, [u'arrow'])
        isinstance = _import_ns.get('isinstance', context.get('isinstance', UNDEFINED))
        optionalstyle = _import_ns.get('optionalstyle', context.get('optionalstyle', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 70
        __M_writer(u'\n  ')
        # SOURCE LINE 71
 
        from r2.lib.template_helpers import get_domain
        
        
        # SOURCE LINE 73
        __M_writer(u'\n  <div class="reddit-voting-arrows" \n     ')
        # SOURCE LINE 75
        __M_writer(conditional_websafe(optionalstyle("float:left; margin: 1px;")))
        __M_writer(u'>\n    <script type="text/javascript">\n      var reddit_bordercolor="FFFFFF";\n    </script>\n    ')
        # SOURCE LINE 79

        from r2.models import FakeSubreddit
        url = ("http://%s/static/button/button4.html?t=4&id=%s&sr=%s" % 
                (get_domain(cname = c.cname, subreddit = False), thing._fullname,
                c.site.name if not isinstance(c.site, FakeSubreddit) else ""))
        if c.bgcolor:
           url += "&bgcolor=%s&bordercolor=%s" % (c.bgcolor, c.bgcolor)
        else:
           url += "&bgcolor=FFFFFF&bordercolor=FFFFFF"
             
        
        # SOURCE LINE 88
        __M_writer(u'\n    <iframe src="')
        # SOURCE LINE 89
        __M_writer(conditional_websafe(url))
        __M_writer(u'" height="55" width="51" scrolling="no" frameborder="0"\n            ')
        # SOURCE LINE 90
        __M_writer(conditional_websafe(optionalstyle("margin:0px;")))
        __M_writer(u'>\n    </iframe>\n  </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
def render_static_arrows(context,thing):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, '__anon_0x7f21644298d0')._populate(_import_ns, [u'optionalstyle'])
        _mako_get_namespace(context, '__anon_0x7f2164429990')._populate(_import_ns, [u'arrow'])
        optionalstyle = _import_ns.get('optionalstyle', context.get('optionalstyle', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 50
        __M_writer(u'\n  ')
        # SOURCE LINE 51

        from r2.lib.template_helpers import get_domain
        domain = get_domain(subreddit=False)
        permalink = "http://%s%s" % (domain, thing.permalink)
        if thing.likes == False:
           arrow = "https://%s/static/widget_arrows_down.gif"
        elif thing.likes:
           arrow = "https://%s/static/widget_arrows_up.gif"
        else:
           arrow = "https://%s/static/widget_arrows.gif"
        arrow = arrow % domain
        
        
        # SOURCE LINE 62
        __M_writer(u'\n  <a href="')
        # SOURCE LINE 63
        __M_writer(conditional_websafe(permalink))
        __M_writer(u'" class="reddit-voting-arrows" target="_blank"\n     ')
        # SOURCE LINE 64
        __M_writer(conditional_websafe(optionalstyle("float:left; display:block;")))
        __M_writer(u'>\n    <img src="')
        # SOURCE LINE 65
        __M_writer(conditional_websafe(arrow))
        __M_writer(u'" alt="vote" \n         ')
        # SOURCE LINE 66
        __M_writer(conditional_websafe(optionalstyle("border:none;margin-top:3px;")))
        __M_writer(u'/>\n  </a>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Example #22
0
    def GET_search(self, query, num, reverse, after, count, sort):
        """Search links page."""
        if query and '.' in query:
            url = sanitize_url(query, require_scheme=True)
            if url:
                return self.redirect("/submit" + query_string({'url': url}))

        q = IndextankQuery(query, c.site, sort)

        num, t, spane = self._search(q,
                                     num=num,
                                     after=after,
                                     reverse=reverse,
                                     count=count)

        if not isinstance(c.site, FakeSubreddit) and not c.cname:
            all_reddits_link = "%s/search%s" % (subreddit.All.path,
                                                query_string({'q': query}))
            d = {
                'reddit_name': c.site.name,
                'reddit_link': "http://%s/" % get_domain(cname=c.cname),
                'all_reddits_link': all_reddits_link
            }
            infotext = strings.searching_a_reddit % d
        else:
            infotext = None

        res = SearchPage(_('search results'),
                         query,
                         t,
                         num,
                         content=spane,
                         nav_menus=[SearchSortMenu(default=sort)],
                         search_params=dict(sort=sort),
                         infotext=infotext).render()

        return res
Example #23
0
    def add_props(cls, user, wrapped):
        from r2.lib.pages import make_link_child
        from r2.lib.count import incr_counts
        from r2.lib.media import thumbnail_url
        from r2.lib.utils import timeago
        from r2.lib.template_helpers import get_domain
        from r2.models.subreddit import FakeSubreddit
        from r2.lib.wrapped import CachedVariable

        # referencing c's getattr is cheap, but not as cheap when it
        # is in a loop that calls it 30 times on 25-200 things.
        user_is_admin = c.user_is_admin
        user_is_loggedin = c.user_is_loggedin
        pref_media = user.pref_media
        pref_frame = user.pref_frame
        pref_newwindow = user.pref_newwindow
        cname = c.cname
        site = c.site

        saved = Link._saved(user, wrapped) if user_is_loggedin else {}
        hidden = Link._hidden(user, wrapped) if user_is_loggedin else {}
        trials = trial_info(wrapped)

        # clicked = Link._clicked(user, wrapped) if user else {}
        clicked = {}

        for item in wrapped:
            show_media = False
            if not hasattr(item, "score_fmt"):
                item.score_fmt = Score.number_only
            item.pref_compress = user.pref_compress
            if user.pref_compress and item.promoted is None:
                item.render_css_class = "compressed link"
                item.score_fmt = Score.points
            elif pref_media == "on" and not user.pref_compress:
                show_media = True
            elif pref_media == "subreddit" and item.subreddit.show_media:
                show_media = True
            elif item.promoted and item.has_thumbnail:
                if user_is_loggedin and item.author_id == user._id:
                    show_media = True
                elif pref_media != "off" and not user.pref_compress:
                    show_media = True

            item.over_18 = bool(item.over_18 or item.subreddit.over_18 or item._nsfw.findall(item.title))
            item.nsfw = item.over_18 and user.pref_label_nsfw

            #            if user.pref_no_profanity and item.over_18 and not c.site.over_18:
            #                item.thumbnail = ""
            #            elif not show_media:
            #                item.thumbnail = ""
            #            elif item.has_thumbnail:
            #                item.thumbnail = thumbnail_url(item)
            #            elif item.is_self:
            #                item.thumbnail = g.self_thumb
            #            else:
            #                item.thumbnail = g.default_thumb

            if item.has_thumbnail:
                item.thumbnail = thumbnail_url(item)
            else:
                item.thumbnail = ""

            item.score = max(0, item.score)

            item.domain = domain(item.url) if not item.is_self else "self." + item.subreddit.name
            item.urlprefix = ""
            item.saved = bool(saved.get((user, item, "save")))
            item.hidden = bool(hidden.get((user, item, "hide")))
            item.clicked = bool(clicked.get((user, item, "click")))
            item.num = None
            item.permalink = item.make_permalink(item.subreddit)
            if item.is_self:
                item.url = item.make_permalink(item.subreddit, force_domain=True)

            # do we hide the score?
            if user_is_admin:
                item.hide_score = False
            elif item.promoted and item.score <= 0:
                item.hide_score = True
            elif user == item.author:
                item.hide_score = False
            elif item._date > timeago("2 hours"):
                item.hide_score = True
            else:
                item.hide_score = False

            # store user preferences locally for caching
            item.pref_frame = pref_frame
            item.newwindow = pref_newwindow
            # is this link a member of a different (non-c.site) subreddit?
            item.different_sr = isinstance(site, FakeSubreddit) or site.name != item.subreddit.name

            if user_is_loggedin and item.author_id == user._id:
                item.nofollow = False
            elif item.score <= 1 or item._spam or item.author._spam:
                item.nofollow = True
            else:
                item.nofollow = False

            if c.user.pref_no_profanity:
                item.title = profanity_filter(item.title)

            item.subreddit_path = item.subreddit.path
            if cname:
                item.subreddit_path = "http://" + get_domain(cname=(site == item.subreddit), subreddit=False)
                if site != item.subreddit:
                    item.subreddit_path += item.subreddit.path
            item.domain_path = "/domain/%s" % item.domain
            if item.is_self:
                item.domain_path = item.subreddit_path

            # attach video or selftext as needed
            item.link_child, item.editable = make_link_child(item)

            item.tblink = "http://%s/tb/%s" % (get_domain(cname=cname, subreddit=False), item._id36)

            if item.is_self:
                item.href_url = item.permalink
            else:
                item.href_url = item.url

            # show the toolbar if the preference is set and the link
            # is neither a promoted link nor a self post
            if pref_frame and not item.is_self and not item.promoted:
                item.mousedown_url = item.tblink
            else:
                item.mousedown_url = None

            item.fresh = not any((item.likes != None, item.saved, item.clicked, item.hidden, item._deleted, item._spam))

            item.is_author = user == item.author

            # bits that we will render stubs (to make the cached
            # version more flexible)
            item.num = CachedVariable("num")
            item.numcolmargin = CachedVariable("numcolmargin")
            item.commentcls = CachedVariable("commentcls")
            item.midcolmargin = CachedVariable("midcolmargin")
            item.comment_label = CachedVariable("numcomments")

            item.as_deleted = False
            if item.deleted and not c.user_is_admin:
                item.author = DeletedUser()
                item.as_deleted = True

            item.trial_info = trials.get(item._fullname, None)

            item.approval_checkmark = None

            if item.can_ban:
                verdict = getattr(item, "verdict", None)
                if verdict in ("admin-approved", "mod-approved"):
                    approver = None
                    if getattr(item, "ban_info", None):
                        approver = item.ban_info.get("unbanner", None)

                    if approver:
                        item.approval_checkmark = _("approved by %s") % approver
                    else:
                        item.approval_checkmark = _("approved by a moderator")

                if item.trial_info is not None:
                    item.reveal_trial_info = True
                    item.use_big_modbuttons = True

        if user_is_loggedin:
            incr_counts(wrapped)

        # Run this last
        Printable.add_props(user, wrapped)
Example #24
0
def promo_edit_url(l=None, id36=""):
    if l: id36 = l._id36
    domain = get_domain(cname=False, subreddit=False)
    return "http://%s/promoted/edit_promo/%s" % (domain, id36)
Example #25
0
def promo_traffic_url(l):  # old traffic url
    domain = get_domain(cname=False, subreddit=False)
    return "http://%s/traffic/%s/" % (domain, l._id36)
Example #26
0
File: link.py Project: jcald/reddit
    def add_props(cls, user, wrapped):
        from r2.lib.pages import make_link_child
        from r2.lib.count import incr_counts
        from r2.lib import media
        from r2.lib.utils import timeago
        from r2.lib.template_helpers import get_domain
        from r2.models.subreddit import FakeSubreddit
        from r2.lib.wrapped import CachedVariable

        # referencing c's getattr is cheap, but not as cheap when it
        # is in a loop that calls it 30 times on 25-200 things.
        user_is_admin = c.user_is_admin
        user_is_loggedin = c.user_is_loggedin
        pref_media = user.pref_media
        pref_frame = user.pref_frame
        pref_newwindow = user.pref_newwindow
        cname = c.cname
        site = c.site

        if user_is_loggedin:
            try:
                saved = CassandraSave._fast_query(user, wrapped)
                hidden = CassandraHide._fast_query(user, wrapped)
            except tdb_cassandra.TRANSIENT_EXCEPTIONS as e:
                g.log.warning("Cassandra save/hide lookup failed: %r", e)
                saved = hidden = {}

            clicked = {}
        else:
            saved = hidden = clicked = {}

        for item in wrapped:
            show_media = False
            if not hasattr(item, "score_fmt"):
                item.score_fmt = Score.number_only
            if c.render_style == 'compact':
                item.score_fmt = Score.points
            item.pref_compress = user.pref_compress
            if user.pref_compress and item.promoted is None:
                item.render_css_class = "compressed link"
                item.score_fmt = Score.points
            elif pref_media == 'on' and not user.pref_compress:
                show_media = True
            elif pref_media == 'subreddit' and item.subreddit.show_media:
                show_media = True
            elif item.promoted and item.has_thumbnail:
                if user_is_loggedin and item.author_id == user._id:
                    show_media = True
                elif pref_media != 'off' and not user.pref_compress:
                    show_media = True

            item.nsfw_str = item._nsfw.findall(item.title)
            item.over_18 = bool(item.over_18 or item.subreddit.over_18 or
                                item.nsfw_str)
            item.nsfw = item.over_18 and user.pref_label_nsfw

            item.is_author = (user == item.author)

            item.thumbnail_sprited = False
            # always show a promo author their own thumbnail
            if item.promoted and (user_is_admin or item.is_author) and item.has_thumbnail:
                item.thumbnail = media.thumbnail_url(item)
            elif user.pref_no_profanity and item.over_18 and not c.site.over_18:
                if show_media:
                    item.thumbnail = "nsfw"
                    item.thumbnail_sprited = True
                else:
                    item.thumbnail = ""
            elif not show_media:
                item.thumbnail = ""
            elif item.has_thumbnail:
                item.thumbnail = media.thumbnail_url(item)
            elif item.is_self:
                item.thumbnail = "self"
                item.thumbnail_sprited = True
            else:
                item.thumbnail = "default"
                item.thumbnail_sprited = True

            item.score = max(0, item.score)

            if getattr(item, "domain_override", None):
                item.domain = item.domain_override
            else:
                item.domain = (domain(item.url) if not item.is_self
                               else 'self.' + item.subreddit.name)
            item.urlprefix = ''

            if user_is_loggedin:
                item.saved = (user, item) in saved
                item.hidden = (user, item) in hidden

                item.clicked = bool(clicked.get((user, item, 'click')))
            else:
                item.saved = item.hidden = item.clicked = False

            item.num = None
            item.permalink = item.make_permalink(item.subreddit)
            if item.is_self:
                item.url = item.make_permalink(item.subreddit,
                                               force_domain=True)

            if g.shortdomain:
                item.shortlink = g.shortdomain + '/' + item._id36

            # do we hide the score?
            if user_is_admin:
                item.hide_score = False
            elif item.promoted and item.score <= 0:
                item.hide_score = True
            elif user == item.author:
                item.hide_score = False
# TODO: uncomment to let gold users see the score of upcoming links
#            elif user.gold:
#                item.hide_score = False
            elif item._date > timeago("2 hours"):
                item.hide_score = True
            else:
                item.hide_score = False

            # store user preferences locally for caching
            item.pref_frame = pref_frame
            item.newwindow = pref_newwindow
            # is this link a member of a different (non-c.site) subreddit?
            item.different_sr = (isinstance(site, FakeSubreddit) or
                                 site.name != item.subreddit.name)

            if user_is_loggedin and item.author_id == user._id:
                item.nofollow = False
            elif item.score <= 1 or item._spam or item.author._spam:
                item.nofollow = True
            else:
                item.nofollow = False

            item.subreddit_path = item.subreddit.path
            if cname:
                item.subreddit_path = ("http://" +
                     get_domain(cname=(site == item.subreddit),
                                subreddit=False))
                if site != item.subreddit:
                    item.subreddit_path += item.subreddit.path
            item.domain_path = "/domain/%s/" % item.domain
            if item.is_self:
                item.domain_path = item.subreddit_path

            # attach video or selftext as needed
            item.link_child, item.editable = make_link_child(item)

            item.tblink = "http://%s/tb/%s" % (
                get_domain(cname=cname, subreddit=False),
                item._id36)

            if item.is_self:
                item.href_url = item.permalink
            else:
                item.href_url = item.url

            # show the toolbar if the preference is set and the link
            # is neither a promoted link nor a self post
            if pref_frame and not item.is_self and not item.promoted:
                item.mousedown_url = item.tblink
            else:
                item.mousedown_url = None

            item.fresh = not any((item.likes != None,
                                  item.saved,
                                  item.clicked,
                                  item.hidden,
                                  item._deleted,
                                  item._spam))

            # bits that we will render stubs (to make the cached
            # version more flexible)
            item.num = CachedVariable("num")
            item.numcolmargin = CachedVariable("numcolmargin")
            item.commentcls = CachedVariable("commentcls")
            item.midcolmargin = CachedVariable("midcolmargin")
            item.comment_label = CachedVariable("numcomments")
            item.lastedited = CachedVariable("lastedited")

            item.as_deleted = False
            if item.deleted and not c.user_is_admin:
                item.author = DeletedUser()
                item.as_deleted = True

            item.approval_checkmark = None

            item_age = datetime.now(g.tz) - item._date
            if item_age.days > g.VOTE_AGE_LIMIT and item.promoted is None:
                item.votable = False
            else:
                item.votable = True

            if item.can_ban:
                verdict = getattr(item, "verdict", None)
                if verdict in ('admin-approved', 'mod-approved'):
                    approver = None
                    if getattr(item, "ban_info", None):
                        approver = item.ban_info.get("unbanner", None)

                    if approver:
                        item.approval_checkmark = _("approved by %s") % approver
                    else:
                        item.approval_checkmark = _("approved by a moderator")

            item.expunged = False
            if item.is_self:
                item.expunged = Link._should_expunge_selftext(item)

            item.editted = getattr(item, "editted", False)

            taglinetext = ''
            if item.different_sr:
                author_text = (" <span>" + _("by %(author)s to %(reddit)s") +
                               "</span>")
            else:
                author_text = " <span>" + _("by %(author)s") + "</span>"
            if item.editted:
                if item.score_fmt == Score.points:
                    taglinetext = ("<span>" +
                                   _("%(score)s submitted %(when)s "
                                     "ago%(lastedited)s") +
                                   "</span>")
                    taglinetext += author_text
                elif item.different_sr:
                    taglinetext = _("submitted %(when)s ago%(lastedited)s "
                                    "by %(author)s to %(reddit)s")
                else:
                    taglinetext = _("submitted %(when)s ago%(lastedited)s "
                                    "by %(author)s")
            else:
                if item.score_fmt == Score.points:
                    taglinetext = ("<span>" +
                                   _("%(score)s submitted %(when)s ago") +
                                   "</span>")
                    taglinetext += author_text
                elif item.different_sr:
                    taglinetext = _("submitted %(when)s ago by %(author)s "
                                    "to %(reddit)s")
                else:
                    taglinetext = _("submitted %(when)s ago by %(author)s")
            item.taglinetext = taglinetext

        if user_is_loggedin:
            incr_counts(wrapped)

        # Run this last
        Printable.add_props(user, wrapped)
Example #27
0
 def GET_blog(self):
     return self.redirect(
         "https://blog.%s/" %
         get_domain(cname=False, subreddit=False, no_www=True))
Example #28
0
def promotraffic_url(l): # new traffic url
    domain = get_domain(cname=False, subreddit=False)
    return "http://%s/promoted/traffic/headline/%s" % (domain, l._id36)
Example #29
0
def view_live_url(l, srname):
    url = get_domain(cname=False, subreddit=False)
    if srname:
        url += '/r/%s' % srname
    return 'http://%s/?ad=%s' % (url, l._fullname)
def render_entry(context):
    context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, '__anon_0x7f2164409350')._populate(_import_ns, [u'optionalstyle'])
        def hide_if_appropriate(state):
            return render_hide_if_appropriate(context,state)
        optionalstyle = _import_ns.get('optionalstyle', context.get('optionalstyle', UNDEFINED))
        self = _import_ns.get('self', context.get('self', UNDEFINED))
        l = _import_ns.get('l', context.get('l', UNDEFINED))
        thing = _import_ns.get('thing', context.get('thing', UNDEFINED))
        def flair():
            return render_flair(context)
        __M_writer = context.writer()
        # SOURCE LINE 46
        __M_writer(u'\n')
        # SOURCE LINE 47
 
        from r2.lib.strings import Score
        domain = get_domain(subreddit=False)
        permalink = "http://%s%s" % (domain, thing.permalink)
        expanded = request.GET.get("expanded")
        two_col = request.GET.has_key("twocolumn") if l else False
         
        
        # SOURCE LINE 53
        __M_writer(u'\n  ')
        # SOURCE LINE 54
        __M_writer(conditional_websafe(self.arrows(thing)))
        __M_writer(u'\n  <div class="reddit-entry entry ')
        # SOURCE LINE 55
        __M_writer(conditional_websafe(thing.like_cls))
        __M_writer(u'" \n')
        # SOURCE LINE 56
        if expanded:
            # SOURCE LINE 57
            __M_writer(u'         ')
            __M_writer(conditional_websafe(optionalstyle("margin-left: 58px;")))
            __M_writer(u'\n')
            # SOURCE LINE 58
        else:
            # SOURCE LINE 59
            __M_writer(u'         ')
            __M_writer(conditional_websafe(optionalstyle("margin-left: 28px; min-height:32px;")))
            __M_writer(u'\n')
            pass
        # SOURCE LINE 61
        __M_writer(u'       >\n')
        # SOURCE LINE 62
        if c.site.link_flair_position == 'left' and thing.flair_text:
            # SOURCE LINE 63
            __M_writer(u'      ')
            __M_writer(conditional_websafe(flair()))
            __M_writer(u'\n')
            pass
        # SOURCE LINE 65
        __M_writer(u'    <a class="reddit-link-title may-blank"\n      ')
        # SOURCE LINE 66
        __M_writer(conditional_websafe(optionalstyle("text-decoration:none;color:#336699;font-size:small;")))
        __M_writer(u'\n')
        # SOURCE LINE 67
        if thing.is_self:
            # SOURCE LINE 68
            __M_writer(u'         href="')
            __M_writer(conditional_websafe(permalink))
            __M_writer(u'"\n')
            # SOURCE LINE 69
        else:
            # SOURCE LINE 70
            __M_writer(u'         href="')
            __M_writer(conditional_websafe(thing.href_url))
            __M_writer(u'"\n')
            pass
        # SOURCE LINE 72
        if thing.nofollow:
            # SOURCE LINE 73
            __M_writer(u'         rel="nofollow"\n')
            pass
        # SOURCE LINE 75
        if c.link_target:
            # SOURCE LINE 76
            __M_writer(u'         target="')
            __M_writer(conditional_websafe(c.link_target))
            __M_writer(u'"\n')
            # SOURCE LINE 77
        elif c.cname:
            # SOURCE LINE 78
            __M_writer(u'         target="_top"\n')
            pass
        # SOURCE LINE 80
        __M_writer(u'       >\n      ')
        # SOURCE LINE 81
        __M_writer(conditional_websafe(thing.title))
        __M_writer(u'\n    </a>\n')
        # SOURCE LINE 83
        if c.site.link_flair_position == 'right' and thing.flair_text:
            # SOURCE LINE 84
            __M_writer(u'      ')
            __M_writer(conditional_websafe(flair()))
            __M_writer(u'\n')
            pass
        # SOURCE LINE 86
        if not expanded:
            # SOURCE LINE 87
            __M_writer(u'      <br />\n')
            pass
        # SOURCE LINE 89
        __M_writer(u'    <small \n')
        # SOURCE LINE 90
        if expanded:
            # SOURCE LINE 91
            __M_writer(u'         ')
            __M_writer(conditional_websafe(optionalstyle("color:gray;margin-left:5px;")))
            __M_writer(u'\n')
            # SOURCE LINE 92
        else:
            # SOURCE LINE 93
            __M_writer(u'         ')
            __M_writer(conditional_websafe(optionalstyle("color:gray;")))
            __M_writer(u'\n')
            pass
        # SOURCE LINE 95
        __M_writer(u'       >\n')
        # SOURCE LINE 96
        if not expanded:
            # SOURCE LINE 97
            __M_writer(u'      ')

            score_dislikes, score_unvoted, score_likes = thing.display_score
            
            
            # SOURCE LINE 99
            __M_writer(u'\n      <span class="score dislikes" ')
            # SOURCE LINE 100
            __M_writer(conditional_websafe(hide_if_appropriate('dislikes')))
            __M_writer(u'>\n         ')
            # SOURCE LINE 101
            __M_writer(conditional_websafe(score_dislikes))
            __M_writer(u'\n      </span>\n      <span class="score unvoted" ')
            # SOURCE LINE 103
            __M_writer(conditional_websafe(hide_if_appropriate('unvoted')))
            __M_writer(u'>\n         ')
            # SOURCE LINE 104
            __M_writer(conditional_websafe(score_unvoted))
            __M_writer(u'\n      </span>\n      <span class="score likes" ')
            # SOURCE LINE 106
            __M_writer(conditional_websafe(hide_if_appropriate('likes')))
            __M_writer(u'>\n         ')
            # SOURCE LINE 107
            __M_writer(conditional_websafe(score_likes))
            __M_writer(u'\n      </span>\n      &#32;|&#32;\n')
            pass
        # SOURCE LINE 111
        __M_writer(u'      <a class="reddit-comment-link may-blank"\n         ')
        # SOURCE LINE 112
        __M_writer(conditional_websafe(optionalstyle("color:gray")))
        __M_writer(u'\n')
        # SOURCE LINE 113
        if c.link_target:
            # SOURCE LINE 114
            __M_writer(u'           target="')
            __M_writer(conditional_websafe(c.link_target))
            __M_writer(u'"\n')
            pass
        # SOURCE LINE 116
        __M_writer(u'         href="')
        __M_writer(conditional_websafe(permalink))
        __M_writer(u'">')
        __M_writer(conditional_websafe(thing.comment_label))
        __M_writer(u'</a>\n    </small>\n  </div>\n  <div class="reddit-link-end" ')
        # SOURCE LINE 119
        __M_writer(conditional_websafe(optionalstyle("clear:left; padding:3px;")))
        __M_writer(u'></div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Example #31
0
def sup_url():
    return 'http://%s/sup.json' % get_domain(subreddit = False)
Example #32
0
 def canonical_url(self):
     from r2.lib.template_helpers import get_domain
     p = "lw/%s/%s/" % (self._id36, title_to_url(self.title))
     return "http://%s/%s" % (get_domain(subreddit=False), p)
Example #33
0
    def add_props(cls, user, wrapped):
        from r2.lib.pages import make_link_child
        from r2.lib.count import incr_counts
        from r2.lib import media
        from r2.lib.utils import timeago
        from r2.lib.template_helpers import get_domain
        from r2.models.subreddit import FakeSubreddit
        from r2.lib.wrapped import CachedVariable

        # referencing c's getattr is cheap, but not as cheap when it
        # is in a loop that calls it 30 times on 25-200 things.
        user_is_admin = c.user_is_admin
        user_is_loggedin = c.user_is_loggedin
        pref_media = user.pref_media
        pref_frame = user.pref_frame
        pref_newwindow = user.pref_newwindow
        cname = c.cname
        site = c.site

        if user_is_loggedin:
            saved_lu = []
            for item in wrapped:
                if not SaveHide._can_skip_lookup(user, item):
                    saved_lu.append(item._id36)

            saved = CassandraSave._fast_query(user._id36, saved_lu)
            hidden = CassandraHide._fast_query(user._id36, saved_lu)

            clicked = {}
        else:
            saved = hidden = clicked = {}

        trials = trial_info(wrapped)

        for item in wrapped:
            show_media = False
            if not hasattr(item, "score_fmt"):
                item.score_fmt = Score.number_only
            if c.render_style == 'compact':
                item.score_fmt = Score.points
            item.pref_compress = user.pref_compress
            if user.pref_compress and item.promoted is None:
                item.render_css_class = "compressed link"
                item.score_fmt = Score.points
            elif pref_media == 'on' and not user.pref_compress:
                show_media = True
            elif pref_media == 'subreddit' and item.subreddit.show_media:
                show_media = True
            elif item.promoted and item.has_thumbnail:
                if user_is_loggedin and item.author_id == user._id:
                    show_media = True
                elif pref_media != 'off' and not user.pref_compress:
                    show_media = True

            item.nsfw_str = item._nsfw.findall(item.title)
            item.over_18 = bool(item.over_18 or item.subreddit.over_18
                                or item.nsfw_str)
            item.nsfw = item.over_18 and user.pref_label_nsfw

            item.is_author = (user == item.author)

            item.thumbnail_sprited = False
            # always show a promo author their own thumbnail
            if item.promoted and (user_is_admin
                                  or item.is_author) and item.has_thumbnail:
                item.thumbnail = media.thumbnail_url(item)
            elif user.pref_no_profanity and item.over_18 and not c.site.over_18:
                if show_media:
                    item.thumbnail = "nsfw"
                    item.thumbnail_sprited = True
                else:
                    item.thumbnail = ""
            elif not show_media:
                item.thumbnail = ""
            elif item.has_thumbnail:
                item.thumbnail = media.thumbnail_url(item)
            elif item.is_self:
                item.thumbnail = "self"
                item.thumbnail_sprited = True
            else:
                item.thumbnail = "default"
                item.thumbnail_sprited = True

            item.score = max(0, item.score)

            if getattr(item, "domain_override", None):
                item.domain = item.domain_override
            else:
                item.domain = (domain(item.url) if not item.is_self else
                               'self.' + item.subreddit.name)
            item.urlprefix = ''

            if user_is_loggedin:
                item.saved = (user._id36, item._id36) in saved
                item.hidden = (user._id36, item._id36) in hidden

                item.clicked = bool(clicked.get((user, item, 'click')))
            else:
                item.saved = item.hidden = item.clicked = False

            item.num = None
            item.permalink = item.make_permalink(item.subreddit)
            if item.is_self:
                item.url = item.make_permalink(item.subreddit,
                                               force_domain=True)

            if g.shortdomain:
                item.shortlink = g.shortdomain + '/' + item._id36

            # do we hide the score?
            if user_is_admin:
                item.hide_score = False
            elif item.promoted and item.score <= 0:
                item.hide_score = True
            elif user == item.author:
                item.hide_score = False


# TODO: uncomment to let gold users see the score of upcoming links
#            elif user.gold:
#                item.hide_score = False
            elif item._date > timeago("2 hours"):
                item.hide_score = True
            else:
                item.hide_score = False

            # store user preferences locally for caching
            item.pref_frame = pref_frame
            item.newwindow = pref_newwindow
            # is this link a member of a different (non-c.site) subreddit?
            item.different_sr = (isinstance(site, FakeSubreddit)
                                 or site.name != item.subreddit.name)

            if user_is_loggedin and item.author_id == user._id:
                item.nofollow = False
            elif item.score <= 1 or item._spam or item.author._spam:
                item.nofollow = True
            else:
                item.nofollow = False

            item.subreddit_path = item.subreddit.path
            if cname:
                item.subreddit_path = ("http://" + get_domain(
                    cname=(site == item.subreddit), subreddit=False))
                if site != item.subreddit:
                    item.subreddit_path += item.subreddit.path
            item.domain_path = "/domain/%s/" % item.domain
            if item.is_self:
                item.domain_path = item.subreddit_path

            # attach video or selftext as needed
            item.link_child, item.editable = make_link_child(item)

            item.tblink = "http://%s/tb/%s" % (get_domain(
                cname=cname, subreddit=False), item._id36)

            if item.is_self:
                item.href_url = item.permalink
            else:
                item.href_url = item.url

            # show the toolbar if the preference is set and the link
            # is neither a promoted link nor a self post
            if pref_frame and not item.is_self and not item.promoted:
                item.mousedown_url = item.tblink
            else:
                item.mousedown_url = None

            item.fresh = not any((item.likes != None, item.saved, item.clicked,
                                  item.hidden, item._deleted, item._spam))

            # bits that we will render stubs (to make the cached
            # version more flexible)
            item.num = CachedVariable("num")
            item.numcolmargin = CachedVariable("numcolmargin")
            item.commentcls = CachedVariable("commentcls")
            item.midcolmargin = CachedVariable("midcolmargin")
            item.comment_label = CachedVariable("numcomments")

            item.as_deleted = False
            if item.deleted and not c.user_is_admin:
                item.author = DeletedUser()
                item.as_deleted = True

            item.trial_info = trials.get(item._fullname, None)

            item.approval_checkmark = None

            item_age = datetime.now(g.tz) - item._date
            if item_age.days > g.VOTE_AGE_LIMIT and item.promoted is None:
                item.votable = False
            else:
                item.votable = True

            if item.can_ban:
                verdict = getattr(item, "verdict", None)
                if verdict in ('admin-approved', 'mod-approved'):
                    approver = None
                    if getattr(item, "ban_info", None):
                        approver = item.ban_info.get("unbanner", None)

                    if approver:
                        item.approval_checkmark = _(
                            "approved by %s") % approver
                    else:
                        item.approval_checkmark = _("approved by a moderator")

                if item.trial_info is not None:
                    item.reveal_trial_info = True
                    item.use_big_modbuttons = True

            item.expunged = False
            if item.is_self:
                item.expunged = Link._should_expunge_selftext(item)

        if user_is_loggedin:
            incr_counts(wrapped)

        # Run this last
        Printable.add_props(user, wrapped)
Example #34
0
    def add_props(cls, user, wrapped):
        from r2.lib.template_helpers import add_attr, get_domain
        from r2.lib import promote
        from r2.lib.wrapped import CachedVariable
        from r2.lib.pages import WrappedUser

        #fetch parent links
        links = Link._byID(set(l.link_id for l in wrapped),
                           data=True,
                           return_dict=True,
                           stale=True)

        # fetch authors
        authors = Account._byID(set(l.author_id for l in links.values()),
                                data=True,
                                return_dict=True,
                                stale=True)

        #get srs for comments that don't have them (old comments)
        for cm in wrapped:
            if not hasattr(cm, 'sr_id'):
                cm.sr_id = links[cm.link_id].sr_id

        subreddits = Subreddit._byID(set(cm.sr_id for cm in wrapped),
                                     data=True,
                                     return_dict=False,
                                     stale=True)
        cids = dict((w._id, w) for w in wrapped)
        parent_ids = set(
            cm.parent_id for cm in wrapped
            if getattr(cm, 'parent_id', None) and cm.parent_id not in cids)
        parents = {}
        if parent_ids:
            parents = Comment._byID(parent_ids, data=True, stale=True)

        can_reply_srs = set(s._id for s in subreddits if s.can_comment(user)) \
                        if c.user_is_loggedin else set()
        can_reply_srs.add(promote.get_promote_srid())

        min_score = user.pref_min_comment_score

        profilepage = c.profilepage
        user_is_admin = c.user_is_admin
        user_is_loggedin = c.user_is_loggedin
        focal_comment = c.focal_comment
        cname = c.cname
        site = c.site

        for item in wrapped:
            # for caching:
            item.profilepage = c.profilepage
            item.link = links.get(item.link_id)

            if (item.link._score <= 1 or item.score < 3 or item.link._spam
                    or item._spam or item.author._spam):
                item.nofollow = True
            else:
                item.nofollow = False

            if not hasattr(item, 'subreddit'):
                item.subreddit = item.subreddit_slow
            if item.author_id == item.link.author_id and not item.link._deleted:
                add_attr(item.attribs,
                         'S',
                         link=item.link.make_permalink(item.subreddit))
            if not hasattr(item, 'target'):
                item.target = "_top" if cname else None
            if item.parent_id:
                if item.parent_id in cids:
                    item.parent_permalink = '#' + utils.to36(item.parent_id)
                else:
                    parent = parents[item.parent_id]
                    item.parent_permalink = parent.make_permalink(
                        item.link, item.subreddit)
            else:
                item.parent_permalink = None

            item.can_reply = False
            if c.can_reply or (item.sr_id in can_reply_srs):
                age = datetime.now(g.tz) - item._date
                if age.days < g.REPLY_AGE_LIMIT:
                    item.can_reply = True

            # not deleted on profile pages,
            # deleted if spam and not author or admin
            item.deleted = (
                not profilepage and
                (item._deleted or
                 (item._spam and item.author != user and not item.show_spam)))

            extra_css = ''
            if item.deleted:
                extra_css += "grayed"
                if not user_is_admin:
                    item.author = DeletedUser()
                    item.body = '[deleted]'

            if focal_comment == item._id36:
                extra_css += " border"

            if profilepage:
                item.link_author = WrappedUser(authors[item.link.author_id])

                item.subreddit_path = item.subreddit.path
                if cname:
                    item.subreddit_path = ("http://" + get_domain(
                        cname=(site == item.subreddit), subreddit=False))
                    if site != item.subreddit:
                        item.subreddit_path += item.subreddit.path

            item.full_comment_path = item.link.make_permalink(item.subreddit)

            # don't collapse for admins, on profile pages, or if deleted
            item.collapsed = False
            if ((item.score < min_score)
                    and not (profilepage or item.deleted or user_is_admin)):
                item.collapsed = True
                item.collapsed_reason = _("comment score below threshold")
            if user_is_loggedin and item.author_id in c.user.enemies:
                if "grayed" not in extra_css:
                    extra_css += " grayed"
                item.collapsed = True
                item.collapsed_reason = _("blocked user")

            item.editted = getattr(item, "editted", False)

            item.render_css_class = "comment %s" % CachedVariable(
                "time_period")

            #will get updated in builder
            item.num_children = 0
            item.score_fmt = Score.points
            item.permalink = item.make_permalink(item.link, item.subreddit)

            item.is_author = (user == item.author)
            item.is_focal = (focal_comment == item._id36)

            item_age = c.start_time - item._date
            if item_age.days > g.VOTE_AGE_LIMIT:
                item.votable = False
            else:
                item.votable = True

            #will seem less horrible when add_props is in pages.py
            from r2.lib.pages import UserText
            item.usertext = UserText(item,
                                     item.body,
                                     editable=item.is_author,
                                     nofollow=item.nofollow,
                                     target=item.target,
                                     extra_css=extra_css)
        # Run this last
        Printable.add_props(user, wrapped)
Example #35
0
def promo_traffic_url(l): # old traffic url
    domain = get_domain(cname=False, subreddit=False)
    return "http://%s/traffic/%s/" % (domain, l._id36)
Example #36
0
def sup_url():
    return 'http://%s/sup.json' % get_domain(subdigg = False)
Example #37
0
def promo_edit_url(l):
    domain = get_domain(cname=False, subreddit=False)
    return "http://%s/promoted/edit_promo/%s" % (domain, l._id36)
Example #38
0
    def add_props(cls, user, wrapped):
        from r2.lib.pages import make_link_child
        from r2.lib.count import incr_counts
        from r2.lib.media import thumbnail_url
        from r2.lib.utils import timeago
        from r2.lib.template_helpers import get_domain
        from r2.models.subreddit import FakeSubreddit
        from r2.lib.wrapped import CachedVariable

        # referencing c's getattr is cheap, but not as cheap when it
        # is in a loop that calls it 30 times on 25-200 things.
        user_is_admin = c.user_is_admin
        user_is_loggedin = c.user_is_loggedin
        pref_media = user.pref_media
        pref_frame = user.pref_frame
        pref_newwindow = user.pref_newwindow
        cname = c.cname
        site = c.site

        saved = Link._saved(user, wrapped) if user_is_loggedin else {}
        hidden = Link._hidden(user, wrapped) if user_is_loggedin else {}
        trials = trial_info(wrapped)

        #clicked = Link._clicked(user, wrapped) if user else {}
        clicked = {}

        for item in wrapped:
            show_media = False
            if not hasattr(item, "score_fmt"):
                item.score_fmt = Score.number_only
            item.pref_compress = user.pref_compress
            if user.pref_compress and item.promoted is None:
                item.render_css_class = "compressed link"
                item.score_fmt = Score.points
            elif pref_media == 'on' and not user.pref_compress:
                show_media = True
            elif pref_media == 'subreddit' and item.subreddit.show_media:
                show_media = True
            elif item.promoted and item.has_thumbnail:
                if user_is_loggedin and item.author_id == user._id:
                    show_media = True
                elif pref_media != 'off' and not user.pref_compress:
                    show_media = True

            item.over_18 = bool(item.over_18 or item.subreddit.over_18
                                or item._nsfw.findall(item.title))
            item.nsfw = item.over_18 and user.pref_label_nsfw

            if user.pref_no_profanity and item.over_18 and not c.site.over_18:
                item.thumbnail = ""
            elif not show_media:
                item.thumbnail = ""
            elif item.has_thumbnail:
                item.thumbnail = thumbnail_url(item)
            elif item.is_self:
                item.thumbnail = g.self_thumb
            else:
                item.thumbnail = g.default_thumb

            item.score = max(0, item.score)

            item.domain = (domain(item.url) if not item.is_self else 'self.' +
                           item.subreddit.name)
            item.urlprefix = ''
            item.saved = bool(saved.get((user, item, 'save')))
            item.hidden = bool(hidden.get((user, item, 'hide')))
            item.clicked = bool(clicked.get((user, item, 'click')))
            item.num = None
            item.permalink = item.make_permalink(item.subreddit)
            if item.is_self:
                item.url = item.make_permalink(item.subreddit,
                                               force_domain=True)

            # do we hide the score?
            if user_is_admin:
                item.hide_score = False
            elif item.promoted and item.score <= 0:
                item.hide_score = True
            elif user == item.author:
                item.hide_score = False
            elif item._date > timeago("2 hours"):
                item.hide_score = True
            else:
                item.hide_score = False

            # store user preferences locally for caching
            item.pref_frame = pref_frame
            item.newwindow = pref_newwindow
            # is this link a member of a different (non-c.site) subreddit?
            item.different_sr = (isinstance(site, FakeSubreddit)
                                 or site.name != item.subreddit.name)

            if user_is_loggedin and item.author_id == user._id:
                item.nofollow = False
            elif item.score <= 1 or item._spam or item.author._spam:
                item.nofollow = True
            else:
                item.nofollow = False

            if c.user.pref_no_profanity:
                item.title = profanity_filter(item.title)

            item.subreddit_path = item.subreddit.path
            if cname:
                item.subreddit_path = ("http://" + get_domain(
                    cname=(site == item.subreddit), subreddit=False))
                if site != item.subreddit:
                    item.subreddit_path += item.subreddit.path
            item.domain_path = "/domain/%s" % item.domain
            if item.is_self:
                item.domain_path = item.subreddit_path

            # attach video or selftext as needed
            item.link_child, item.editable = make_link_child(item)

            item.tblink = "http://%s/tb/%s" % (get_domain(
                cname=cname, subreddit=False), item._id36)

            if item.is_self:
                item.href_url = item.permalink
            else:
                item.href_url = item.url

            # show the toolbar if the preference is set and the link
            # is neither a promoted link nor a self post
            if pref_frame and not item.is_self and not item.promoted:
                item.mousedown_url = item.tblink
            else:
                item.mousedown_url = None

            item.fresh = not any((item.likes != None, item.saved, item.clicked,
                                  item.hidden, item._deleted, item._spam))

            item.is_author = (user == item.author)

            # bits that we will render stubs (to make the cached
            # version more flexible)
            item.num = CachedVariable("num")
            item.numcolmargin = CachedVariable("numcolmargin")
            item.commentcls = CachedVariable("commentcls")
            item.midcolmargin = CachedVariable("midcolmargin")
            item.comment_label = CachedVariable("numcomments")

            item.as_deleted = False
            if item.deleted and not c.user_is_admin:
                item.author = DeletedUser()
                item.as_deleted = True

            item.trial_info = trials.get(item._fullname, None)

            item.approval_checkmark = None

            if item.can_ban:
                verdict = getattr(item, "verdict", None)
                if verdict in ('admin-approved', 'mod-approved'):
                    approver = None
                    if getattr(item, "ban_info", None):
                        approver = item.ban_info.get("unbanner", None)

                    if approver:
                        item.approval_checkmark = _(
                            "approved by %s") % approver
                    else:
                        item.approval_checkmark = _("approved by a moderator")

                if item.trial_info is not None:
                    item.reveal_trial_info = True
                    item.use_big_modbuttons = True

        if user_is_loggedin:
            incr_counts(wrapped)

        # Run this last
        Printable.add_props(user, wrapped)
Example #39
0
 def canonical_url(self):
   domain = get_domain(subreddit=False)
   return 'http://{0}/meetups/{1}'.format(domain, self._id36)
Example #40
0
def promo_edit_url(l):
    domain = get_domain(cname=False, subreddit=False)
    return "http://%s/promoted/edit_promo/%s" % (domain, l._id36)
Example #41
0
    def add_props(cls, user, wrapped):
        from r2.lib.pages import make_link_child
        from r2.lib.count import incr_counts
        from r2.lib.media import thumbnail_url
        from r2.lib.utils import timeago
        from r2.lib.template_helpers import get_domain
        from r2.models.subreddit import FakeSubreddit
        from r2.lib.wrapped import CachedVariable

        # referencing c's getattr is cheap, but not as cheap when it
        # is in a loop that calls it 30 times on 25-200 things.
        user_is_admin = c.user_is_admin
        user_is_loggedin = c.user_is_loggedin
        pref_media = user.pref_media
        pref_frame = user.pref_frame
        pref_newwindow = user.pref_newwindow
        cname = c.cname
        site = c.site

        if user_is_loggedin:
            saved_lu = []
            for item in wrapped:
                if not SaveHide._can_skip_lookup(user, item):
                    saved_lu.append(item._id36)

            saved = CassandraSave._fast_query(user._id36, saved_lu)
            hidden = CassandraHide._fast_query(user._id36, saved_lu)

            clicked = {}
        else:
            saved = hidden = clicked = {}

        trials = trial_info(wrapped)

        for item in wrapped:
            show_media = False
            if not hasattr(item, "score_fmt"):
                item.score_fmt = Score.number_only
            if c.render_style == 'compact':
                item.score_fmt = Score.points
            item.pref_compress = user.pref_compress
            if user.pref_compress and item.promoted is None:
                item.render_css_class = "compressed link"
                item.score_fmt = Score.points
            elif pref_media == 'on' and not user.pref_compress:
                show_media = True
            elif pref_media == 'subreddit' and item.subreddit.show_media:
                show_media = True
            elif item.promoted and item.has_thumbnail:
                if user_is_loggedin and item.author_id == user._id:
                    show_media = True
                elif pref_media != 'off' and not user.pref_compress:
                    show_media = True

            item.over_18 = bool(
                item.over_18 or item.subreddit.over_18
                or item._nsfw.findall(item.title))
            item.nsfw = item.over_18 and user.pref_label_nsfw

            item.is_author = (user == item.author)

            # always show a promo author their own thumbnail
            if item.promoted and (user_is_admin
                                  or item.is_author) and item.has_thumbnail:
                item.thumbnail = thumbnail_url(item)
            elif user.pref_no_profanity and item.over_18 and not c.site.over_18:
                if show_media:
                    item.thumbnail = "/static/nsfw2.png"
                else:
                    item.thumbnail = ""
            elif not show_media:
                item.thumbnail = ""
            elif item.has_thumbnail:
                item.thumbnail = thumbnail_url(item)
            elif item.is_self:
                item.thumbnail = g.self_thumb
            else:
                item.thumbnail = g.default_thumb

            item.score = max(0, item.score)

            if getattr(item, "domain_override", None):
                item.domain = item.domain_override
            else:
                item.domain = (domain(item.url) if not item.is_self else
                               'self.' + item.subreddit.name)
            item.urlprefix = ''

            if user_is_loggedin:
                item.saved = (user._id36, item._id36) in saved
                item.hidden = (user._id36, item._id36) in hidden

                item.clicked = bool(clicked.get((user, item, 'click')))
            else:
                item.saved = item.hidden = item.clicked = False

            item.num = None
            item.permalink = item.make_permalink(item.subreddit)
            if item.is_self:
                item.url = item.make_permalink(
                    item.subreddit, force_domain=True)

            if g.shortdomain:
                item.shortlink = g.shortdomain + '/' + item._id36

            # do we hide the score?
            if user_is_admin:
                item.hide_score = False
            elif item.promoted and item.score <= 0:
                item.hide_score = True
            elif user == item.author:
                item.hide_score = False


# TODO: uncomment to let gold users see the score of upcoming links
#            elif user.gold:
#                item.hide_score = False
            elif item._date > timeago("2 hours"):
                item.hide_score = True
            else:
                item.hide_score = False

            # store user preferences locally for caching
            item.pref_frame = pref_frame
            item.newwindow = pref_newwindow
            # is this link a member of a different (non-c.site) subreddit?
            item.different_sr = (isinstance(site, FakeSubreddit)
                                 or site.name != item.subreddit.name)

            if user_is_loggedin and item.author_id == user._id:
                item.nofollow = False
            elif item.score <= 1 or item._spam or item.author._spam:
                item.nofollow = True
            else:
                item.nofollow = False

            if c.user.pref_no_profanity:
                item.title = profanity_filter(item.title)

            item.subreddit_path = item.subreddit.path
            if cname:
                item.subreddit_path = ("http://" + get_domain(
                    cname=(site == item.subreddit), subreddit=False))
                if site != item.subreddit:
                    item.subreddit_path += item.subreddit.path
            item.domain_path = "/domain/%s/" % item.domain
            if item.is_self:
                item.domain_path = item.subreddit_path

            # attach video or selftext as needed
            item.link_child, item.editable = make_link_child(item)

            item.tblink = "http://%s/tb/%s" % (get_domain(
                cname=cname, subreddit=False), item._id36)

            if item.is_self:
                item.href_url = item.permalink
            else:
                item.href_url = item.url

            # show the toolbar if the preference is set and the link
            # is neither a promoted link nor a self post
            if pref_frame and not item.is_self and not item.promoted:
                item.mousedown_url = item.tblink
            else:
                item.mousedown_url = None

            item.fresh = not any((item.likes != None, item.saved, item.clicked,
                                  item.hidden, item._deleted, item._spam))

            # bits that we will render stubs (to make the cached
            # version more flexible)
            item.num = CachedVariable("num")
            item.numcolmargin = CachedVariable("numcolmargin")
            item.commentcls = CachedVariable("commentcls")
            item.midcolmargin = CachedVariable("midcolmargin")
            item.comment_label = CachedVariable("numcomments")

            item.as_deleted = False
            if item.deleted and not c.user_is_admin:
                item.author = DeletedUser()
                item.as_deleted = True

            item.trial_info = trials.get(item._fullname, None)

            item.approval_checkmark = None

            if item.can_ban:
                verdict = getattr(item, "verdict", None)
                if verdict in ('admin-approved', 'mod-approved'):
                    approver = None
                    if getattr(item, "ban_info", None):
                        approver = item.ban_info.get("unbanner", None)

                    if approver:
                        item.approval_checkmark = _(
                            "approved by %s") % approver
                    else:
                        item.approval_checkmark = _("approved by a moderator")

                if item.trial_info is not None:
                    item.reveal_trial_info = True
                    item.use_big_modbuttons = True

        if user_is_loggedin:
            incr_counts(wrapped)

        # Run this last
        Printable.add_props(user, wrapped)
Example #42
0
def promo_traffic_url(l):
    domain = get_domain(cname = False, subdigg = False)
    return "http://%s/traffic/%s/" % (domain, l._id36)
Example #43
0
    def add_props(cls, user, wrapped):
        from r2.lib.count import incr_counts
        from r2.lib.media import thumbnail_url
        from r2.lib.utils import timeago
        from r2.lib.template_helpers import get_domain
        from r2.models.subreddit import FakeSubreddit
        from r2.lib.wrapped import CachedVariable

        # referencing c's getattr is cheap, but not as cheap when it
        # is in a loop that calls it 30 times on 25-200 things.
        user_is_admin = c.user_is_admin
        user_is_loggedin = c.user_is_loggedin
        pref_media = user.pref_media
        pref_frame = user.pref_frame
        pref_newwindow = user.pref_newwindow
        cname = c.cname
        site = c.site

        saved = Link._saved(user, wrapped) if user_is_loggedin else {}
        hidden = Link._hidden(user, wrapped) if user_is_loggedin else {}

        #clicked = Link._clicked(user, wrapped) if user else {}
        clicked = {}

        for item in wrapped:
            show_media = False
            if not hasattr(item, "score_fmt"):
                item.score_fmt = Score.number_only
            item.pref_compress = user.pref_compress
            if user.pref_compress and item.promoted is None:
                item.render_css_class = "compressed link"
                item.score_fmt = Score.points
            elif pref_media == 'on' and not user.pref_compress:
                show_media = True
            elif pref_media == 'subreddit' and item.subreddit.show_media:
                show_media = True
            elif item.promoted and item.has_thumbnail:
                if user_is_loggedin and item.author_id == user._id:
                    show_media = True
                elif pref_media != 'off' and not user.pref_compress:
                    show_media = True

            if not show_media:
                item.thumbnail = ""
            elif item.has_thumbnail:
                item.thumbnail = thumbnail_url(item)
            else:
                item.thumbnail = g.default_thumb

            item.score = max(0, item.score)

            item.domain = (domain(item.url) if not item.is_self
                          else 'self.' + item.subreddit.name)
            if not hasattr(item,'top_link'):
                item.top_link = False
            item.urlprefix = ''
            item.saved = bool(saved.get((user, item, 'save')))
            item.hidden = bool(hidden.get((user, item, 'hide')))
            item.clicked = bool(clicked.get((user, item, 'click')))
            item.num = None
            item.permalink = item.make_permalink(item.subreddit)
            if item.is_self:
                item.url = item.make_permalink(item.subreddit, force_domain = True)

            # do we hide the score?
            if user_is_admin:
                item.hide_score = False
            elif item.promoted:
                item.hide_score = True
            elif user == item.author:
                item.hide_score = False
            elif item._date > timeago("2 hours"):
                item.hide_score = True
            else:
                item.hide_score = False

            # store user preferences locally for caching
            item.pref_frame = pref_frame
            item.newwindow = pref_newwindow
            # is this link a member of a different (non-c.site) subreddit?
            item.different_sr = (isinstance(site, FakeSubreddit) or
                                 site.name != item.subreddit.name)

            if user_is_loggedin and item.author._id == user._id:
                item.nofollow = False
            elif item.score <= 1 or item._spam or item.author._spam:
                item.nofollow = True
            else:
                item.nofollow = False

            item.subreddit_path = item.subreddit.path
            if cname:
                item.subreddit_path = ("http://" + 
                     get_domain(cname = (site == item.subreddit),
                                subreddit = False))
                if site != item.subreddit:
                    item.subreddit_path += item.subreddit.path
            item.domain_path = "/domain/%s" % item.domain
            if item.is_self:
                item.domain_path = item.subreddit_path

            #this is wrong, but won't be so wrong when we move this
            #whole chunk of code into pages.py
            from r2.lib.pages import MediaChild, SelfTextChild
            item.link_child = None
            item.editable = False
            if item.media_object:
                item.link_child = MediaChild(item, load = True)
            elif item.selftext:
                expand = getattr(item, 'expand_children', False)
                item.link_child = SelfTextChild(item, expand = expand,
                                                nofollow = item.nofollow)
                #draw the edit button if the contents are pre-expanded
                item.editable = expand and item.author == c.user
               
            item.tblink = "http://%s/tb/%s" % (
                get_domain(cname = cname, subreddit=False),
                item._id36)

            if item.is_self:
                item.href_url = item.permalink
            else:
                item.href_url = item.url

            # show the toolbar if the preference is set and the link
            # is neither a promoted link nor a self post
            if pref_frame and not item.is_self and not item.promoted:
                item.mousedown_url = item.tblink
            else:
                item.mousedown_url = None

            item.fresh = not any((item.likes != None,
                                  item.saved,
                                  item.clicked,
                                  item.hidden,
                                  item._deleted,
                                  item._spam))

            item.is_author = (user == item.author)

            # bits that we will render stubs (to make the cached
            # version more flexible)
            item.num = CachedVariable("num")
            item.numcolmargin = CachedVariable("numcolmargin")
            item.commentcls = CachedVariable("commentcls")
            item.midcolmargin = CachedVariable("midcolmargin")
            item.comment_label = CachedVariable("numcomments")

        if user_is_loggedin:
            incr_counts(wrapped)

        # Run this last
        Printable.add_props(user, wrapped)
Example #44
0
def sup_url():
    return 'http://%s/sup.json' % get_domain(subsciteit = False)
Example #45
0
 def canonical_url(self):
     from r2.lib.template_helpers import get_domain
     p = "lw/%s/%s/" % (self._id36, title_to_url(self.title))
     return "http://%s/%s" % (get_domain(subreddit = False), p)
Example #46
0
 def GET_blog(self):
     return self.redirect("http://blog.%s/" % get_domain(cname=False, subreddit=False, no_www=True))
Example #47
0
def promotraffic_url(l):  # new traffic url
    domain = get_domain(cname=False, subreddit=False)
    return "http://%s/promoted/traffic/headline/%s" % (domain, l._id36)
Example #48
0
def promo_edit_url(l=None, id36=""):
    if l: id36 = l._id36
    domain = get_domain(cname=False, subreddit=False)
    return "http://%s/promoted/edit_promo/%s" % (domain, id36)
Example #49
0
def view_live_url(l, srname):
    url = get_domain(cname=False, subreddit=False)
    if srname:
        url += '/r/%s' % srname
    return 'http://%s/?ad=%s' % (url, l._fullname)
Example #50
0
def sup_url():
    return "http://%s/sup.json" % get_domain(subreddit=False)
Example #51
0
    def add_props(cls, user, wrapped):
        from r2.lib.template_helpers import add_attr, get_domain
        from r2.lib import promote
        from r2.lib.wrapped import CachedVariable
        from r2.lib.pages import WrappedUser

        #fetch parent links
        links = Link._byID(set(l.link_id for l in wrapped), data = True,
                           return_dict = True, stale=True)

        # fetch authors
        authors = Account._byID(set(l.author_id for l in links.values()), data=True, 
                                return_dict=True, stale=True)

        #get srs for comments that don't have them (old comments)
        for cm in wrapped:
            if not hasattr(cm, 'sr_id'):
                cm.sr_id = links[cm.link_id].sr_id

        subreddits = Subreddit._byID(set(cm.sr_id for cm in wrapped),
                                     data=True, return_dict=False, stale=True)
        cids = dict((w._id, w) for w in wrapped)
        parent_ids = set(cm.parent_id for cm in wrapped
                         if getattr(cm, 'parent_id', None)
                         and cm.parent_id not in cids)
        parents = {}
        if parent_ids:
            parents = Comment._byID(parent_ids, data=True, stale=True)

        can_reply_srs = set(s._id for s in subreddits if s.can_comment(user)) \
                        if c.user_is_loggedin else set()
        can_reply_srs.add(promote.get_promote_srid())

        min_score = user.pref_min_comment_score

        profilepage = c.profilepage
        user_is_admin = c.user_is_admin
        user_is_loggedin = c.user_is_loggedin
        focal_comment = c.focal_comment
        cname = c.cname
        site = c.site

        for item in wrapped:
            # for caching:
            item.profilepage = c.profilepage
            item.link = links.get(item.link_id)

            if (item.link._score <= 1 or item.score < 3 or
                item.link._spam or item._spam or item.author._spam):
                item.nofollow = True
            else:
                item.nofollow = False

            if not hasattr(item, 'subreddit'):
                item.subreddit = item.subreddit_slow
            if item.author_id == item.link.author_id and not item.link._deleted:
                add_attr(item.attribs, 'S',
                         link = item.link.make_permalink(item.subreddit))
            if not hasattr(item, 'target'):
                item.target = "_top" if cname else None
            if item.parent_id:
                if item.parent_id in cids:
                    item.parent_permalink = '#' + utils.to36(item.parent_id)
                else:
                    parent = parents[item.parent_id]
                    item.parent_permalink = parent.make_permalink(item.link, item.subreddit)
            else:
                item.parent_permalink = None

            item.can_reply = False
            if c.can_reply or (item.sr_id in can_reply_srs):
                age = datetime.now(g.tz) - item._date
                if age.days < g.REPLY_AGE_LIMIT:
                    item.can_reply = True


            # not deleted on profile pages,
            # deleted if spam and not author or admin
            item.deleted = (not profilepage and
                           (item._deleted or
                            (item._spam and
                             item.author != user and
                             not item.show_spam)))

            extra_css = ''
            if item.deleted:
                extra_css += "grayed"
                if not user_is_admin:
                    item.author = DeletedUser()
                    item.body = '[deleted]'


            if focal_comment == item._id36:
                extra_css += " border"

            if profilepage:
                item.link_author = WrappedUser(authors[item.link.author_id])

                item.subreddit_path = item.subreddit.path
                if cname:
                    item.subreddit_path = ("http://" + 
                         get_domain(cname = (site == item.subreddit),
                                    subreddit = False))
                    if site != item.subreddit:
                        item.subreddit_path += item.subreddit.path

            item.full_comment_path = item.link.make_permalink(item.subreddit)

            # don't collapse for admins, on profile pages, or if deleted
            item.collapsed = False
            if ((item.score < min_score) and not (profilepage or
                item.deleted or user_is_admin)):
                item.collapsed = True
                item.collapsed_reason = _("comment score below threshold")
            if user_is_loggedin and item.author_id in c.user.enemies:
                if "grayed" not in extra_css:
                    extra_css += " grayed"
                item.collapsed = True
                item.collapsed_reason = _("blocked user")

            item.editted = getattr(item, "editted", False)

            item.render_css_class = "comment %s" % CachedVariable("time_period")

            #will get updated in builder
            item.num_children = 0
            item.score_fmt = Score.points
            item.permalink = item.make_permalink(item.link, item.subreddit)

            item.is_author = (user == item.author)
            item.is_focal  = (focal_comment == item._id36)

            item_age = c.start_time - item._date
            if item_age.days > g.VOTE_AGE_LIMIT:
                item.votable = False
            else:
                item.votable = True

            #will seem less horrible when add_props is in pages.py
            from r2.lib.pages import UserText
            item.usertext = UserText(item, item.body,
                                     editable = item.is_author,
                                     nofollow = item.nofollow,
                                     target = item.target,
                                     extra_css = extra_css)
        # Run this last
        Printable.add_props(user, wrapped)
Example #52
0
 def canonical_url(self):
     domain = get_domain(subreddit=False)
     return 'http://{0}/meetups/{1}'.format(domain, self._id36)