Beispiel #1
0
    def GET_discussions(self, num, after, reverse, count):
        """Get a list of reddit submissions linking to this thread."""

        show_hidden = c.liveupdate_permissions.allow("discussions")
        builder = get_discussions(c.liveupdate_event,
                                  limit=50,
                                  show_hidden=show_hidden)
        listing = LinkListing(builder).listing()
        listing.render_class = pages.LiveUpdateDiscussionsListing
        listing.submit_url = pages.make_submit_url(c.liveupdate_event)
        return pages.LiveUpdateEventPage(content=listing, ).render()
Beispiel #2
0
 def GET_wiki_discussions(self, page, num, after, reverse, count):
     page_url = add_sr("%s/%s" % (c.wiki_base_url, page.name))
     builder = url_links_builder(page_url, num=num, after=after,
                                 reverse=reverse, count=count)
     listing = LinkListing(builder).listing()
     return WikiDiscussions(listing, page=page.name,
                            may_revise=this_may_revise(page)).render()
Beispiel #3
0
    def POST_request_promo(self, srnames, is_mobile_web, platform, loid,
                           is_refresh):
        self.OPTIONS_request_promo()

        if not srnames:
            return

        # backwards compat
        if platform is None:
            platform = "mobile_web" if is_mobile_web else "desktop"

        srnames = srnames.split('+')

        # request multiple ads in case some are hidden by the builder due
        # to the user's hides/preferences
        response = adzerk_request(srnames,
                                  self.get_uid(loid),
                                  platform=platform)

        if not response:
            g.stats.simple_event('adzerk.request.no_promo')
            return

        # for adservers, adzerk returns markup so we pass it to the client
        if isinstance(response, AdserverResponse):
            g.stats.simple_event('adzerk.request.adserver')
            return responsive(response.body)

        res_by_campaign = {r.campaign: r for r in response}
        adserver_click_urls = {r.campaign: r.click_url for r in response}
        tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response]
        builder = CampaignBuilder(tuples,
                                  wrap=default_thing_wrapper(),
                                  keep_fn=promote.promo_keep_fn,
                                  num=1,
                                  skip=True)
        listing = LinkListing(builder, nextprev=False).listing()
        promote.add_trackers(listing.things,
                             c.site,
                             adserver_click_urls=adserver_click_urls)
        promote.update_served(listing.things)
        if listing.things:
            g.stats.simple_event('adzerk.request.valid_promo')
            if is_refresh:
                g.stats.simple_event('adzerk.request.auto_refresh')

            w = listing.things[0]
            r = res_by_campaign[w.campaign]

            up = UrlParser(r.imp_pixel)
            up.hostname = "pixel.redditmedia.com"
            w.adserver_imp_pixel = up.unparse()
            w.adserver_upvote_pixel = r.upvote_pixel
            w.adserver_downvote_pixel = r.downvote_pixel
            w.adserver_click_url = r.click_url
            w.num = ""
            return responsive(w.render(), space_compress=True)
        else:
            g.stats.simple_event('adzerk.request.skip_promo')
Beispiel #4
0
 def GET_wiki_discussions(self, page, num, after, reverse, count):
     page_url = add_sr("%s/%s" % (c.wiki_base_url, page.name))
     links = url_links(page_url)
     builder = IDBuilder([ link._fullname for link in links ],
                         num = num, after = after, reverse = reverse,
                         count = count, skip = False)
     listing = LinkListing(builder).listing()
     return WikiDiscussions(listing).render()
Beispiel #5
0
 def GET_discussions(self, num, after, reverse, count):
     """Get a list of reddit submissions linking to this thread."""
     builder = url_links_builder(
         url="/live/" + c.liveupdate_event._id,
         num=num,
         after=after,
         reverse=reverse,
         count=count,
     )
     listing = LinkListing(builder).listing()
     return pages.LiveUpdateEventPage(content=listing, ).render()
Beispiel #6
0
 def GET_wiki_discussions(self, page, num, after, reverse, count):
     """Retrieve a list of discussions about this wiki `page`"""
     page_url = add_sr("%s/%s" % (c.wiki_base_url, page.name))
     builder = url_links_builder(page_url,
                                 num=num,
                                 after=after,
                                 reverse=reverse,
                                 count=count)
     listing = LinkListing(builder).listing()
     return WikiDiscussions(listing,
                            page=page.name,
                            may_revise=this_may_revise(page),
                            sr_path=not c.site.is_homepage).render()
Beispiel #7
0
    def POST_request_promo(self, srnames, is_mobile_web):
        self.OPTIONS_request_promo()

        if not srnames:
            return

        srnames = srnames.split('+')

        # request multiple ads in case some are hidden by the builder due
        # to the user's hides/preferences
        response = adzerk_request(srnames, mobile_web=is_mobile_web)

        if not response:
            g.stats.simple_event('adzerk.request.no_promo')
            return

        res_by_campaign = {r.campaign: r for r in response}
        tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response]
        builder = CampaignBuilder(tuples,
                                  wrap=default_thing_wrapper(),
                                  keep_fn=promote.promo_keep_fn,
                                  num=1,
                                  skip=True)
        listing = LinkListing(builder, nextprev=False).listing()
        promote.add_trackers(listing.things, c.site)
        if listing.things:
            g.stats.simple_event('adzerk.request.valid_promo')
            w = listing.things[0]
            r = res_by_campaign[w.campaign]

            up = UrlParser(r.imp_pixel)
            up.hostname = "pixel.redditmedia.com"
            w.adserver_imp_pixel = up.unparse()
            w.adserver_click_url = r.click_url
            w.num = ""
            return responsive(w.render(), space_compress=True)
        else:
            g.stats.simple_event('adzerk.request.skip_promo')
Beispiel #8
0
    def __init__(self, link = None, comment = None,
                 link_title = '', is_canonical = False, *a, **kw):
        
        link.render_full = True
        
        # TODO: temp hack until we find place for builder_wrapper
        from r2.controllers.listingcontroller import ListingController
        if comment:
            link_wrapper = lambda link: self.comment_permalink_wrapper(comment, link)
        else:
            link_wrapper = ListingController.builder_wrapper
        link_builder = IDBuilder(link._fullname,
                                 wrap = link_wrapper)

        # link_listing will be the one-element listing at the top
        self.link_listing = LinkListing(link_builder, nextprev=False).listing()

        # link is a wrapped Link object
        self.link = self.link_listing.things[0]

        link_title = ((self.link.title) if hasattr(self.link, 'title') else '')
        if comment:
            title = comment.make_permalink_title(link)
            
            # Comment permalinks should not be indexed, there's too many of them
            self.robots = 'noindex'

            if is_canonical == False:
                self.canonical_link = comment.make_permalink(link)
        else:
            params = {'title':_force_unicode(link_title), 'site' : c.site.title}
            title = strings.link_info_title % params

            if not (c.default_sr and is_canonical):
                # Not on the main page, so include a pointer to the canonical URL for this link
                self.canonical_link = link.canonical_url

        Reddit.__init__(self, title = title, body_class = 'post', robots = self.robots, *a, **kw)
    def POST_request_promo(self):
        if not (c.site and c.site.name in g.cpm_beta_srs):
            return super(AdzerkApiController, self).POST_request_promo()

        srids = promote.srids_with_live_promos(c.user, c.site)
        if not srids:
            return

        if '' in srids:
            srnames = [Frontpage.name]
            srids.remove('')
        else:
            srnames = []

        srs = Subreddit._byID(srids, data=True, return_dict=False)
        srnames.extend(sr.name for sr in srs)

        # request multiple ads in case some are hidden by the builder due
        # to the user's hides/preferences
        response = adzerk_request(srnames, num_placements=g.az_selfserve_num_request)

        if not response:
            return

        res_by_campaign = {r.campaign: r for r in response}
        tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response]
        builder = CampaignBuilder(tuples, wrap=default_thing_wrapper(),
                                  keep_fn=promote.is_promoted,
                                  num=1,
                                  skip=True)
        listing = LinkListing(builder, nextprev=False).listing()
        if listing.things:
            w = listing.things[0]
            r = res_by_campaign[w.campaign]
            w.adserver_imp_pixel = r.imp_pixel
            w.adserver_click_url = r.click_url
            return spaceCompress(w.render())
Beispiel #10
0
 def __init__(self):
     sr_ids = Subreddit.user_subreddits(c.user if c.user_is_loggedin else None)
     srs = Subreddit._byID(sr_ids, True, return_dict = False)
     srs.sort(key = lambda sr: sr.name.lower())
     b = IDBuilder([sr._fullname for sr in srs])
     self.reddits = LinkListing(b).listing().things