Example #1
0
File: pages.py Project: vin/reddit
    def __init__(self, link = None, comment = None,
                 link_title = '', *a, **kw):
        # TODO: temp hack until we find place for builder_wrapper
        from r2.controllers.listingcontroller import ListingController
        link_builder = IDBuilder(link._fullname,
                                 wrap = promote_builder_wrapper(ListingController.builder_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:
            author = Account._byID(comment.author_id, data=True).name
            title = _("%(author)s comments on %(title)s") % dict(author=author, title=_force_unicode(link_title))
        else:
            title = _("%(title)s : %(site)s") % dict(title=_force_unicode(link_title), site = c.site.name)
        Reddit.__init__(self, title = title, *a, **kw)
Example #2
0
    def organic(self):
        o_links, pos, calculation_key = organic.organic_links(c.user)
        if o_links:
            # get links in proximity to pos
            l = min(len(o_links) - 3, 8)
            disp_links = [o_links[(i + pos) % len(o_links)] for i in xrange(-2, l)]

            b = IDBuilder(disp_links,
                          wrap = promote_builder_wrapper(self.builder_wrapper))
            o = OrganicListing(b,
                               org_links = o_links,
                               visible_link = o_links[pos],
                               max_num = self.listing_obj.max_num,
                               max_score = self.listing_obj.max_score).listing()

            if len(o.things) > 0:
                # only pass through a listing if the links made it
                # through our builder
                organic.update_pos(pos+1, calculation_key)

                return o