示例#1
0
文件: pages.py 项目: vin/reddit
    def __init__(self, space_compress = True, nav_menus = None, loginbox = True,
                 infotext = '', content = None, title = '', robots = None, 
                 show_sidebar = True, **context):
        Wrapped.__init__(self, **context)
        self.title          = title
        self.robots         = robots
        self.infotext       = infotext
        self.loginbox       = True
        self.show_sidebar   = show_sidebar
        self.space_compress = space_compress

        #put the sort menus at the top
        self.nav_menu = MenuArea(menus = nav_menus) if nav_menus else None

        #add the infobar
        self.infobar = None
        if c.firsttime and c.site.firsttext and not infotext:
            infotext = c.site.firsttext
        if infotext:
            self.infobar = InfoBar(message = infotext)

        self.srtopbar = None
        if not c.cname:
            self.srtopbar = SubredditTopBar()

        if c.user_is_loggedin and self.show_sidebar:
            self._content = PaneStack([ShareLink(), content])
        else:
            self._content = content
        
        self.toolbars = self.build_toolbars()
示例#2
0
文件: pages.py 项目: vin/reddit
 def __init__(self, panes=[], div_id = None, css_class=None, div=False):
     div = div or div_id or css_class or False
     self.div_id    = div_id
     self.css_class = css_class
     self.div       = div
     self.stack     = list(panes)
     Wrapped.__init__(self)
示例#3
0
 def __init__(self, sr = None, link = None, listing = '',
              timedeltatext = '', *a, **kw):
     Wrapped.__init__(self, sr = sr, link = link,
                      datefmt = datefmt,
                      timedeltatext = timedeltatext,
                      listing = listing,
                      *a, **kw)
示例#4
0
 def __init__(self, user, type, cellnames, container_name, editable):
     self.user, self.type, self.cells = user, type, cellnames
     self.container_name = container_name
     self.name           = "tr_%s_%s" % (user.name, type)
     self.editable       = editable
     Wrapped.__init__(self)
     Ajaxed.__init__(self, 'UserTable', 'add')
示例#5
0
 def __init__(self, panes=[], div_id = None, css_class=None, div=False):
     div = div or div_id or css_class or False
     self.div_id    = div_id
     self.css_class = css_class
     self.div       = div
     self.stack     = list(panes)
     Wrapped.__init__(self)
示例#6
0
 def __init__(self, sr = None, link = None, listing = '',
              timedeltatext = '', *a, **kw):
     Wrapped.__init__(self, sr = sr, link = link,
                      datefmt = datefmt,
                      timedeltatext = timedeltatext,
                      listing = listing,
                      *a, **kw)
示例#7
0
    def context_from_comment(self, comment):
        link = Link._byID(comment.link_id)
        wrapped, = self.wrap_items((comment, ))

        # If there are any child comments, add an expand link
        children = list(Comment._query(Comment.c.parent_id == comment._id))
        if children:
            more = Wrapped(MoreChildren(link, 0))
            more.children.extend(children)
            more.count = len(children)
            wrapped.child = self.empty_listing()
            wrapped.child.things.append(more)

        # If there's a parent comment, surround the child comment with it
        parent_id = getattr(comment, 'parent_id', None)
        if parent_id is not None:
            parent_comment = Comment._byID(parent_id)
            if parent_comment:
                parent_wrapped, = self.wrap_items((parent_comment, ))
                parent_wrapped.child = self.empty_listing()
                parent_wrapped.child.things.append(wrapped)
                wrapped = parent_wrapped

        wrapped.show_response_to = True
        return wrapped
示例#8
0
    def __init__(self, space_compress = True, nav_menus = None, loginbox = True,
                 infotext = '', content = None, title = '', robots = None, 
                 show_sidebar = True, body_class = None, **context):
        Wrapped.__init__(self, **context)
        self.title          = title
        self.robots         = robots
        self.infotext       = infotext
        self.loginbox       = True
        self.show_sidebar   = show_sidebar
        self.space_compress = space_compress
        self.body_class     = body_class

        #put the sort menus at the top
        self.nav_menu = MenuArea(menus = nav_menus) if nav_menus else None

        #add the infobar
        self.infobar = None
        if c.firsttime and c.site.firsttext and not infotext:
            infotext = c.site.firsttext
        if not infotext and hasattr(c.site, 'infotext'):
            infotext = c.site.infotext
        if infotext:
            self.infobar = InfoBar(message = infotext)

        self.srtopbar = None
        if not c.cname:
            self.srtopbar = SubredditTopBar()

        self._content = content
        self.toolbars = self.build_toolbars()
示例#9
0
 def trial_wrap(item):
     if item is trial:
         w = Wrapped(item)
         w.trial_mode = True
         w.render_class = LinkOnTrial
         return w
     return self.builder_wrapper(item)
示例#10
0
文件: pages.py 项目: vin/reddit
 def __init__(self, user, type, cellnames, container_name, editable):
     self.user, self.type, self.cells = user, type, cellnames
     self.container_name = container_name
     self.name           = "tr_%s_%s" % (user.name, type)
     self.editable       = editable
     Wrapped.__init__(self)
     Ajaxed.__init__(self, 'UserTable', 'add')
示例#11
0
    def context_from_comment(self, comment):
        if isinstance(comment, Comment):
            link = Link._byID(comment.link_id)
            wrapped, = self.wrap_items((comment,))

            # If there are any child comments, add an expand link
            children = list(Comment._query(Comment.c.parent_id == comment._id))
            if children:
                more = Wrapped(MoreChildren(link, 0))
                more.children.extend(children)
                more.count = len(children)
                wrapped.child = self.empty_listing()
                wrapped.child.things.append(more)

            # If there's a parent comment, surround the child comment with it
            parent_id = getattr(comment, 'parent_id', None)
            if parent_id is not None:
                parent_comment = Comment._byID(parent_id)
                if parent_comment:
                    parent_wrapped, = self.wrap_items((parent_comment,))
                    parent_wrapped.child = self.empty_listing()
                    parent_wrapped.child.things.append(wrapped)
                    wrapped = parent_wrapped

            wrapped.show_response_to = True
        else:
            wrapped, = self.wrap_items((comment,))
        return wrapped
示例#12
0
    def builder_wrapper(thing):
        w = Wrapped(thing)

        if isinstance(thing, Link):
            w.render_class = InlineArticle

        return w
示例#13
0
文件: pages.py 项目: vin/reddit
 def __init__(self, link = None, button = None, css=None, 
              url = None, title = '', score_fmt = None, vote = True, target = "_parent", 
              bgcolor = None, width = 100):
     Wrapped.__init__(self, link = link, score_fmt = score_fmt,
                      likes = link.likes if link else None, 
                      button = button, css = css, url = url, title = title, 
                      vote = vote, target = target, bgcolor=bgcolor, width=width)
示例#14
0
    def builder_wrapper(thing):
        w = Wrapped(thing)

        if isinstance(thing, Link):
            w.render_class = InlineArticle

        return w
示例#15
0
 def __init__(self, link = None, button = None, css=None, 
              url = None, title = '', score_fmt = None, vote = True, target = "_parent", 
              bgcolor = None, width = 100):
     Wrapped.__init__(self, link = link, score_fmt = score_fmt,
                      likes = link.likes if link else None, 
                      button = button, css = css, url = url, title = title, 
                      vote = vote, target = target, bgcolor=bgcolor, width=width)
示例#16
0
    def __init__(self, space_compress = True, nav_menus = None, loginbox = True,
                 infotext = '', content = None, title = '', robots = None, 
                 show_sidebar = True, body_class = None, **context):
        Wrapped.__init__(self, **context)
        self.title          = title
        self.robots         = robots
        self.infotext       = infotext
        self.loginbox       = True
        self.show_sidebar   = show_sidebar
        self.space_compress = space_compress
        self.body_class     = body_class

        #put the sort menus at the top
        self.nav_menu = MenuArea(menus = nav_menus) if nav_menus else None

        #add the infobar
        self.infobar = None
        if c.firsttime and c.site.firsttext and not infotext:
            infotext = c.site.firsttext
        if not infotext and hasattr(c.site, 'infotext'):
            infotext = c.site.infotext
        if infotext:
            self.infobar = InfoBar(message = infotext)

        self.srtopbar = None
        if not c.cname:
            self.srtopbar = SubredditTopBar()

        self._content = content
        self.toolbars = self.build_toolbars()
示例#17
0
    def get_links(cls, event_id):
        link_ids = cls._get_related_link_ids(event_id)
        links = Link._byID(link_ids, data=True, return_dict=False)
        links.sort(key=lambda L: L.num_comments, reverse=True)

        sr_ids = set(L.sr_id for L in links)
        subreddits = Subreddit._byID(sr_ids, data=True)

        wrapped = []
        for link in links:
            w = Wrapped(link)

            if w._spam or w._deleted:
                continue

            if not getattr(w, "allow_liveupdate", True):
                continue

            w.subreddit = subreddits[link.sr_id]

            # ideally we'd check if the user can see the subreddit, but by
            # doing this we keep everything user unspecific which makes caching
            # easier.
            if w.subreddit.type == "private":
                continue

            comment_label = ungettext("comment", "comments", link.num_comments)
            w.comments_label = strings.number_label % dict(
                num=link.num_comments, thing=comment_label)

            wrapped.append(w)
        return wrapped
示例#18
0
文件: pages.py 项目: cmak/reddit
    def __init__(self, space_compress = True, nav_menus = None, loginbox = True,
                 infotext = '', content = None, title = '', show_sidebar = True,
                 **context):
        Wrapped.__init__(self, **context)
        self.title          = title
        self.infotext       = infotext
        self.loginbox       = True
        self.show_sidebar   = show_sidebar
        self.space_compress = space_compress

        #put the sort menus at the top
        self.nav_menu = MenuArea(menus = nav_menus) if nav_menus else None

        #add the infobar
        self.infobar = None
        if c.firsttime and c.site.firsttext and not infotext:
            infotext = c.site.firsttext
        if infotext:
            self.infobar = InfoBar(message = infotext)

        #c.subredditbox is set by VSRMask
        self.subreddit_sidebox = False
        if c.subreddit_sidebox:
            self.subreddit_sidebox = True
            self.subreddit_checkboxes = c.site == Default

        self._content = content
        self.toolbars = self.build_toolbars()
    def get_links(cls, event_id):
        link_ids = cls._get_related_link_ids(event_id)
        links = Link._byID(link_ids, data=True, return_dict=False)
        links.sort(key=lambda L: L.num_comments, reverse=True)

        sr_ids = set(L.sr_id for L in links)
        subreddits = Subreddit._byID(sr_ids, data=True)

        wrapped = []
        for link in links:
            w = Wrapped(link)

            if w._spam or w._deleted:
                continue

            if not getattr(w, "allow_liveupdate", True):
                continue

            w.subreddit = subreddits[link.sr_id]

            # ideally we'd check if the user can see the subreddit, but by
            # doing this we keep everything user unspecific which makes caching
            # easier.
            if w.subreddit.type == "private":
                continue

            comment_label = ungettext("comment", "comments", link.num_comments)
            w.comments_label = strings.number_label % dict(
                num=link.num_comments, thing=comment_label)

            wrapped.append(w)
        return wrapped
示例#20
0
 def trial_wrap(item):
    if item is trial:
        w = Wrapped(item)
        w.trial_mode = True
        w.render_class = LinkOnTrial
        return w
    return self.builder_wrapper(item)
示例#21
0
文件: pages.py 项目: vin/reddit
    def __init__(self):
        Wrapped.__init__(self)

        my_reddits = []
        sr_ids = Subreddit.user_subreddits(c.user if c.user_is_loggedin else None)
        if sr_ids:
            my_reddits = Subreddit._byID(sr_ids, True,
                                         return_dict = False)
            my_reddits.sort(key = lambda sr: sr.name.lower())

        drop_down_buttons = []    
        for sr in my_reddits:
            drop_down_buttons.append(SubredditButton(sr))

        #leaving the 'home' option out for now
        #drop_down_buttons.insert(0, NamedButton('home', sr_path = False,
        #                                        css_class = 'top-option',
        #                                        dest = '/'))
        drop_down_buttons.append(NamedButton('edit', sr_path = False,
                                             css_class = 'bottom-option',
                                             dest = '/reddits/'))
        self.sr_dropdown = SubredditMenu(drop_down_buttons,
                                         title = _('my reddits'),
                                         type = 'srdrop')

    
        pop_reddits = Subreddit.default_srs(c.content_langs, limit = 30)        
        buttons = [SubredditButton(sr) for sr in c.recent_reddits]
        for sr in pop_reddits:
            if sr not in c.recent_reddits:
                buttons.append(SubredditButton(sr))
    
        self.sr_bar = NavMenu(buttons, type='flatlist', separator = '-',
                                        _id = 'sr-bar')
示例#22
0
    def builder_wrapper(thing):
        w = Wrapped(thing)

        if c.user.pref_compress and isinstance(thing, Link):
            w.render_class = LinkCompressed
            w.score_fmt = Score.points

        return w
示例#23
0
    def wrap_thing(thing):
        w = Wrapped(thing)
        
        if isinstance(thing, Link):
            w.render_class = InlineArticle
        elif isinstance(thing, Comment):
            w.render_class = InlineComment

        return w
示例#24
0
文件: i18n.py 项目: therufs/lesswrong
 def GET_edit(self, lang):
     if not lang and c.user_is_admin:
         content = Wrapped(TranslatorTemplate())
     elif Translator.exists(lang):
         content = Wrapped(get_translator(locale=lang))
     else:
         content = UnfoundPage()
     res = AdminPage(content=content, title='translate reddit').render()
     return res
示例#25
0
    def wrap_thing(thing):
        w = Wrapped(thing)
        
        if isinstance(thing, Link):
            w.render_class = InlineArticle
        elif isinstance(thing, Comment):
            w.render_class = InlineComment

        return w
示例#26
0
文件: things.py 项目: rajbot/tikical
 def _default_thing_wrapper(thing):
     w = Wrapped(thing)
     style = params.get("style", c.render_style)
     if isinstance(thing, Link):
         if thing.promoted:
             w.render_class = PromotedLink
             w.rowstyle = "promoted link"
         elif style == "htmllite":
             w.score_fmt = Score.points
     return w
示例#27
0
    def __init__(self, *args, **kwargs):
        from r2.lib.user_stats import top_users
        uids = top_users()
        users = Account._byID(uids, data=True, return_dict=False)

        # Filter out accounts banned from the default subreddit
        sr = Subreddit._by_name(g.default_sr)
        self.things = filter(lambda user: not sr.is_banned(user), users)

        Wrapped.__init__(self, *args, **kwargs)
示例#28
0
    def __init__(self, *args, **kwargs):
        from r2.lib.user_stats import top_users
        uids = top_users()
        users = Account._byID(uids, data=True, return_dict=False)

        # Filter out accounts banned from the default subreddit
        sr = Subreddit._by_name(g.default_sr)
        self.things = filter(lambda user: not sr.is_banned(user), users)

        Wrapped.__init__(self, *args, **kwargs)
示例#29
0
文件: things.py 项目: nty-/reddit
 def _default_thing_wrapper(thing):
     w = Wrapped(thing)
     style = params.get('style', c.render_style)
     if isinstance(thing, Link):
         if thing.promoted is not None:
             w.render_class = PromotedLink
         elif style == 'htmllite':
             w.score_fmt = Score.safepoints
         w.should_incr_counts = style != 'htmllite'
     return w
示例#30
0
 def _default_thing_wrapper(thing):
     w = Wrapped(thing)
     style = params.get('style', c.render_style)
     if isinstance(thing, Link):
         if thing.promoted is not None:
             w.render_class = PromotedLink
         elif style == 'htmllite':
             w.score_fmt = Score.safepoints
         w.should_incr_counts = style != 'htmllite'
     return w
示例#31
0
文件: things.py 项目: 9peppe/reddit
 def _default_thing_wrapper(thing):
     w = Wrapped(thing)
     style = params.get('style', c.render_style)
     if isinstance(thing, Link):
         if thing.promoted is not None:
             w.render_class = PromotedLink
             w.rowstyle = 'promoted link'
         elif style == 'htmllite':
             w.score_fmt = Score.points
     return w
示例#32
0
def editable_add_props(l):
    if not isinstance(l, Wrapped):
        l = Wrapped(l)

    l.bids = get_transactions(l)
    l.campaigns = dict(
        (indx, RenderableCampaign(l, indx, campaign, l.bids.get(indx)))
        for indx, campaign in getattr(l, "campaigns", {}).iteritems())

    return l
示例#33
0
 def _default_thing_wrapper(thing):
     w = Wrapped(thing)
     style = params.get('style', c.render_style)
     if isinstance(thing, Link):
         if thing.promoted is not None:
             w.render_class = PromotedLink
             w.rowstyle = 'promoted link'
         elif style == 'htmllite':
             w.score_fmt = Score.points
     return w
示例#34
0
def editable_add_props(l):
    if not isinstance(l, Wrapped):
        l = Wrapped(l)

    l.bids = get_transactions(l)
    l.campaigns = dict((indx, RenderableCampaign(l, indx, campaign, l.bids.get(indx))) 
                       for indx, campaign in
                       getattr(l, "campaigns", {}).iteritems())

    return l
示例#35
0
 def builder_wrapper(thing):
     if isinstance(thing, Comment):
         p = thing.make_permalink_slow()
         f = thing._fullname
         w = Wrapped(thing)
         w.render_class = Message
         w.to_id = c.user._id
         w.was_comment = True
         w.permalink, w._fullname = p, f
         return w
     else:
         return ListingController.builder_wrapper(thing)
示例#36
0
def editable_add_props(l):
    if not isinstance(l, Wrapped):
        l = Wrapped(l)

    l.bids = get_transactions(l)

    campaigns = {}
    for campaign in PromoCampaign._by_link(l._id):
        campaigns[campaign._id] = RenderableCampaign(l, campaign, l.bids.get(campaign._id))
    l.campaigns = campaigns

    return l
示例#37
0
    def builder_wrapper(thing):
        if isinstance(thing, Comment):
            f = thing._fullname
            w = Wrapped(thing)
            w.render_class = Message
            w.to_id = c.user._id
            w.was_comment = True
            w._fullname = f
        else:
            w = ListingController.builder_wrapper(thing)

        return w
示例#38
0
    def __init__(self, *args, **kwargs):
        from r2.lib.user_stats import top_users
        uids = top_users()
        # Returns a hash keyed in the uid
        users = Account._byID(uids, data=True)
        # Retrieve the Account objects in this way to preseve the sort order
        all_users = (users[u] for u in uids)

        # Filter out banned and spammy accounts
        self.things = filter(lambda user: not c.site.is_banned(user) and user.spammer < 1, all_users)

        Wrapped.__init__(self, *args, **kwargs)
示例#39
0
文件: pages.py 项目: 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
示例#40
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
示例#41
0
 def builder_wrapper(thing):
     if isinstance(thing, Comment):
         p = thing.permalink
         f = thing._fullname
         thing.__class__ = Message
         w = Wrapped(thing)
         w.to_id = c.user._id
         w.subject = 'comment reply'
         w.was_comment = True
         w.permalink, w._fullname = p, f
         return w
     else:
         return ListingController.builder_wrapper(thing)
示例#42
0
文件: promote.py 项目: nod3x/reddit
def editable_add_props(l):
    if not isinstance(l, Wrapped):
        l = Wrapped(l)

    l.bids = get_transactions(l)

    campaigns = {}
    for campaign in PromoCampaign._by_link(l._id):
        campaigns[campaign._id] = RenderableCampaign(l, campaign,
                                                     l.bids.get(campaign._id))
    l.campaigns = campaigns

    return l
示例#43
0
    def __init__(self, num_results = 0, prev_search = '', elapsed_time = 0, **kw):

        # not listed explicitly in args to ensure it translates properly
        self.header = kw.get('header', _("Previous search"))

        self.prev_search  = prev_search
        self.elapsed_time = elapsed_time

        # All results are approximate unless there are fewer than 10.
        if num_results > 10:
            self.num_results = (num_results / 10) * 10
        else:
            self.num_results = num_results

        Wrapped.__init__(self)
示例#44
0
文件: pages.py 项目: vin/reddit
    def __init__(self, num_results = 0, prev_search = '', elapsed_time = 0, **kw):

        # not listed explicitly in args to ensure it translates properly
        self.header = kw.get('header', _("previous search"))

        self.prev_search  = prev_search
        self.elapsed_time = elapsed_time

        # All results are approximate unless there are fewer than 10.
        if num_results > 10:
            self.num_results = (num_results / 10) * 10
        else:
            self.num_results = num_results

        Wrapped.__init__(self)
示例#45
0
    def listing(self, next_suggestions=None):
        self.things, prev, next, bcount, acount = self.get_items()

        self.next_suggestions = next_suggestions
        self._max_num = max(acount, bcount)
        self.after = None
        self.before = None

        if self.nextprev and self.prev_link and prev and bcount > 1:
            p = self.params.copy()
            p.update({'after':None, 'before':prev._fullname, 'count':bcount})
            self.before = prev._fullname
            self.prev = (request.path + utils.query_string(p))
            p_first = self.params.copy()
            p_first.update({'after':None, 'before':None, 'count':None})
            self.first = (request.path + utils.query_string(p_first))
        if self.nextprev and self.next_link and next:
            p = self.params.copy()
            p.update({'after':next._fullname, 'before':None, 'count':acount})
            self.after = next._fullname
            self.next = (request.path + utils.query_string(p))

        for count, thing in enumerate(self.things):
            thing.rowstyle_cls = getattr(thing, 'rowstyle_cls', "")
            thing.rowstyle_cls += ' ' + ('even' if (count % 2) else 'odd')
            thing.rowstyle = CachedVariable("rowstyle")

        #TODO: need name for template -- must be better way
        return Wrapped(self)
示例#46
0
 def wrap_items_fn(items):
     wrapped = []
     for item in items:
         w = Wrapped(item)
         wrapped.append(w)
     GameLogEntry.add_props(c.user, wrapped)
     return wrapped
示例#47
0
    def listing(self):
        self.things, prev, next, bcount, acount = self.get_items()

        self._max_num = max(acount, bcount)
        self.after = None
        self.before = None

        if self.nextprev and self.prev_link and prev and bcount > 1:
            p = request.get.copy()
            p.update({
                'after': None,
                'before': prev._fullname,
                'count': bcount
            })
            self.before = prev._fullname
            self.prev = (request.path + utils.query_string(p))
            p_first = request.get.copy()
            p_first.update({'after': None, 'before': None, 'count': None})
            self.first = (request.path + utils.query_string(p_first))
        if self.nextprev and self.next_link and next:
            p = request.get.copy()
            p.update({
                'after': next._fullname,
                'before': None,
                'count': acount
            })
            self.after = next._fullname
            self.next = (request.path + utils.query_string(p))
        #TODO: need name for template -- must be better way
        return Wrapped(self)
示例#48
0
文件: pages.py 项目: cmak/reddit
    def __init__(self, checkboxes = True):
        Wrapped.__init__(self)

        self.checkboxes = checkboxes
        if checkboxes:
            self.title = _('Customize your reddit')
            self.subtitle = _('Select which communities you want to see')
        else:
            self.title = _('Other reddit communities')
            self.subtitle = 'Visit your subscribed reddits (in bold) or explore new ones'
        self.create_link = ('/reddits/', menu.more)
        self.more_link   = ('/reddits/create', _('create'))

        my_reddits = []
        sr_ids = Subreddit.user_subreddits(c.user if c.user_is_loggedin else None)
        if sr_ids:
            my_reddits = Subreddit._byID(sr_ids, True,
                                         return_dict = False)
            my_reddits.sort(key = lambda sr: sr._downs, reverse = True)

        display_reddits = my_reddits[:g.num_side_reddits]
        
        #remove the current reddit
        display_reddits = filter(lambda x: x != c.site, display_reddits)

        pop_reddits = Subreddit.default_srs(c.content_langs, limit = g.num_side_reddits)
        #add english reddits to the list
        if c.content_langs != 'all' and 'en' not in c.content_langs:
            en_reddits = Subreddit.default_srs(['en'])
            pop_reddits += [sr for sr in en_reddits if sr not in pop_reddits]

        for sr in pop_reddits:
            if len(display_reddits) >= g.num_side_reddits:
                break

            if sr != c.site and sr not in display_reddits:
                display_reddits.append(sr)

        col1, col2 = [], []
        cur_col, other = col1, col2
        for sr in display_reddits:
            cur_col.append((sr, sr in my_reddits))
            cur_col, other = other, cur_col

        self.cols = ((col1, col2))
        self.mine = my_reddits
示例#49
0
文件: pages.py 项目: vin/reddit
    def __init__(self):
        Wrapped.__init__(self)
        cache_stats = cache.get('stats')
        if cache_stats:
            top_users, top_day, top_week = cache_stats

            #lookup user objs
            uids = []
            uids.extend(u    for u in top_users)
            uids.extend(u[0] for u in top_day)
            uids.extend(u[0] for u in top_week)
            users = Account._byID(uids, data = True)

            self.top_users = (users[u]            for u in top_users)
            self.top_day   = ((users[u[0]], u[1]) for u in top_day)
            self.top_week  = ((users[u[0]], u[1]) for u in top_week)
        else:
            self.top_users = self.top_day = self.top_week = ()
示例#50
0
 def ajax_render(self, style="html"):
     """Generates a 'rendering' of this item suitable for
     processing by JS for insert or removal from an existing
     UserList"""
     cells = []
     for cell in self.cells:
         r = Wrapped.part_render(self, 'cell_type', cell)
         cells.append(spaceCompress(r))
     return dict(cells=cells, id=self.type, name=self.name)
示例#51
0
文件: pages.py 项目: vin/reddit
 def ajax_render(self, style="html"):
     """Generates a 'rendering' of this item suitable for
     processing by JS for insert or removal from an existing
     UserList"""
     cells = []
     for cell in self.cells:
         r = Wrapped.part_render(self, 'cell_type', cell)
         cells.append(spaceCompress(r))
     return dict(cells=cells, id=self.type, name=self.name)
示例#52
0
    def __init__(self):
        Wrapped.__init__(self)
        cache_stats = cache.get('stats')
        if cache_stats:
            top_users, top_day, top_week = cache_stats

            #lookup user objs
            uids = []
            uids.extend(u    for u in top_users)
            uids.extend(u[0] for u in top_day)
            uids.extend(u[0] for u in top_week)
            users = Account._byID(uids, data = True)

            self.top_users = (users[u]            for u in top_users)
            self.top_day   = ((users[u[0]], u[1]) for u in top_day)
            self.top_week  = ((users[u[0]], u[1]) for u in top_week)
        else:
            self.top_users = self.top_day = self.top_week = ()
示例#53
0
    def listing(self):
        ##TODO use the local builder with the render cache. this may
        ##require separating the builder's get_items and tree-building
        ##functionality
        wrapped_items = self.get_items()

        self.things = wrapped_items

        #make into a tree thing
        return Wrapped(self)
示例#54
0
def empty_listing(*things):
    parent_name = None
    for t in things:
        try:
            parent_name = t.parent_name
            break
        except AttributeError:
            continue
    l = Listing(None, None, parent_name=parent_name)
    l.things = list(things)
    return Wrapped(l)
示例#55
0
def wrap_things(*things):
    """Instantiate Wrapped for each thing, calling add_props if available."""
    if not things:
        return []

    wrapped = [Wrapped(thing) for thing in things]
    if hasattr(things[0], 'add_props'):
        # assume all things are of the same type and use the first thing's
        # add_props to process the list.
        things[0].add_props(c.user, wrapped)
    return wrapped
示例#56
0
    def __init__(self):
        Wrapped.__init__(self)
        
        self.title = _('Other reddit communities')
        self.subtitle = 'Visit your subscribed categories (in bold) or explore new ones'
        self.create_link = ('/categories/', menu.more)
        self.more_link   = ('/categories/create', _('Create'))

        my_reddits = []
        sr_ids = Subreddit.user_subreddits(c.user if c.user_is_loggedin else None)
        if sr_ids:
            my_reddits = Subreddit._byID(sr_ids, True,
                                         return_dict = False)
            my_reddits.sort(key = lambda sr: sr._downs, reverse = True)

        display_reddits = my_reddits[:g.num_side_reddits]
        
        #remove the current reddit
        display_reddits = filter(lambda x: x != c.site, display_reddits)

        pop_reddits = Subreddit.default_srs(c.content_langs, limit = g.num_side_reddits)
        #add english reddits to the list
        if c.content_langs != 'all' and 'en' not in c.content_langs:
            en_reddits = Subreddit.default_srs(['en'])
            pop_reddits += [sr for sr in en_reddits if sr not in pop_reddits]

        for sr in pop_reddits:
            if len(display_reddits) >= g.num_side_reddits:
                break

            if sr != c.site and sr not in display_reddits:
                display_reddits.append(sr)

        col1, col2 = [], []
        cur_col, other = col1, col2
        for sr in display_reddits:
            cur_col.append((sr, sr in my_reddits))
            cur_col, other = other, cur_col

        self.cols = ((col1, col2))
        self.mine = my_reddits
示例#57
0
    def builder_wrapper(thing):
        w = Wrapped(thing)

        if isinstance(thing, Link):
            if thing.promoted:
                w = Wrapped(thing)
                w.render_class = PromotedLink
                w.rowstyle = 'promoted link'

            elif c.user.pref_compress:
                w.render_class = LinkCompressed
                w.score_fmt = Score.points

        return w
示例#58
0
    def __init__(self):
        Wrapped.__init__(self)

        my_reddits = []
        sr_ids = Subreddit.user_subreddits(c.user if c.user_is_loggedin else None)
        if sr_ids:
            my_reddits = Subreddit._byID(sr_ids, True,
                                         return_dict = False)
            my_reddits.sort(key = lambda sr: sr.name.lower())

        drop_down_buttons = []    
        for sr in my_reddits:
            drop_down_buttons.append(SubredditButton(sr))

        #leaving the 'home' option out for now
        #drop_down_buttons.insert(0, NamedButton('home', sr_path = False,
        #                                        css_class = 'top-option',
        #                                        dest = '/'))
        drop_down_buttons.append(NamedButton('edit', sr_path = False,
                                             css_class = 'bottom-option',
                                             dest = '/categories/'))
        self.sr_dropdown = SubredditMenu(drop_down_buttons,
                                         title = _('My categories'),
                                         type = 'srdrop')

    
        pop_reddits = Subreddit.default_srs(c.content_langs, limit = 30)
        buttons = []
        for sr in c.recent_reddits:
            # Extra guarding for Issue #50
            if hasattr(sr, 'name'):
                buttons.append(SubredditButton(sr))

        for sr in pop_reddits:
            if sr not in c.recent_reddits:
                buttons.append(SubredditButton(sr))
    
        self.sr_bar = NavMenu(buttons, type='flatlist', separator = '-',
                                        _id = 'sr-bar')
示例#59
0
文件: pages.py 项目: cmak/reddit
 def render(self, *a, **kw):
     """Overrides default Wrapped.render with two additions
        * support for rendering API requests with proper wrapping
        * support for space compression of the result
     In adition, unlike Wrapped.render, the result is in the form of a pylons
     Response object with it's content set.
     """
     res = Wrapped.render(self, *a, **kw)
     if is_api():
         res = json_respond(res)
     elif self.space_compress:
         res = spaceCompress(res)
     c.response.content = res
     return c.response
示例#60
0
 def builder_wrapper(thing):
     if isinstance(thing, Comment):
         p = thing.make_permalink_slow()
         f = thing._fullname
         w = Wrapped(thing)
         w.render_class = Message
         w.to_id = c.user._id
         w.subject = _('Comment Reply')
         w.was_comment = True
         w.permalink, w._fullname = p, f
         return w
     else:
         return ListingController.builder_wrapper(thing)