def listing(self): """Listing to generate from the builder""" if (getattr(c.site, "_id", -1) == get_promote_srid() and not c.user_is_sponsor): abort(403, 'forbidden') listing = LinkListing(self.builder_obj, show_nums=self.show_nums) return listing.listing()
def listing(self): """Listing to generate from the builder""" if (getattr(c.site, "_id", -1) == get_promote_srid() and not c.user_is_sponsor): abort(403, 'forbidden') listing = LinkListing(self.builder_obj, show_nums = self.show_nums) return listing.listing()
def listing(self): """Listing to generate from the builder""" if (getattr(c.site, "_id", -1) == get_promote_srid() and not c.user_is_sponsor): abort(403, 'forbidden') listing = LinkListing(self.builder_obj, show_nums = self.show_nums) try: return listing.listing() except SolrError, e: errmsg = "SolrError: %r %r" % (e, self.builder_obj) if (str(e) == 'None'): # Production error logs only get non-None errors g.log.debug(errmsg) else: g.log.error(errmsg) sf = SearchFail() us = unsafe(sf.render()) errpage = pages.RedditError(_('search failed'), us) c.response = Response() c.response.status_code = 503 request.environ['usable_error_content'] = errpage.render() request.environ['retry_after'] = 60 abort(503)
def listing(self): """Listing to generate from the builder""" if (getattr(c.site, "_id", -1) == get_promote_srid() and not c.user_is_sponsor): abort(403, 'forbidden') listing = LinkListing(self.builder_obj, show_nums=self.show_nums) try: return listing.listing() except SolrError, e: errmsg = "SolrError: %r %r" % (e, self.builder_obj) if (str(e) == 'None'): # Production error logs only get non-None errors g.log.debug(errmsg) else: g.log.error(errmsg) sf = SearchFail() us = unsafe(sf.render()) errpage = pages.RedditError(_('search failed'), us) c.response = Response() c.response.status_code = 503 request.environ['usable_error_content'] = errpage.render() request.environ['retry_after'] = 60 abort(503)
def listing(self): """Listing to generate from the builder""" if getattr(c.site, "_id", -1) == get_promote_srid() and not c.user_is_sponsor: abort(403, "forbidden") pane = LinkListing(self.builder_obj, show_nums=self.show_nums).listing() # Indicate that the comment tree wasn't built for comments for i in pane: if hasattr(i, "full_comment_path"): i.child = None return pane
def listing(self): """Listing to generate from the builder""" if (getattr(c.site, "_id", -1) == get_promote_srid() and not c.user_is_sponsor): abort(403, 'forbidden') pane = LinkListing(self.builder_obj, show_nums = self.show_nums).listing() # Indicate that the comment tree wasn't built for comments for i in pane: if hasattr(i, 'full_comment_path'): i.child = None return pane
def add_props(cls, user, wrapped): from r2.lib.template_helpers import add_attr from r2.lib import promote from r2.lib.wrapped import CachedVariable #fetch parent links links = Link._byID( set(l.link_id for l in wrapped), 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 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 = 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 = c.start_time - 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" # don't collapse for admins, on profile pages, or if deleted item.collapsed = ( (item.score < min_score) and not (profilepage or item.deleted or user_is_admin)) 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) #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)
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)
def add_props(cls, user, wrapped): from r2.lib.template_helpers import add_attr from r2.lib import promote #fetch parent links links = Link._byID(set(l.link_id for l in wrapped), data = True, return_dict = 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) 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) 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 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 = 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 = c.start_time - 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" # don't collapse for admins, on profile pages, or if deleted item.collapsed = ((item.score < min_score) and not (profilepage or item.deleted or user_is_admin)) item.editted = getattr(item, "editted", False) #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) #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)
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)