本文整理汇总了Python中r2.lib.promote.get_promote_srid函数的典型用法代码示例。如果您正苦于以下问题:Python get_promote_srid函数的具体用法?Python get_promote_srid怎么用?Python get_promote_srid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_promote_srid函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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()
示例2: 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)
示例3: 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")
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
示例4: add_props
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)
#.........这里部分代码省略.........
示例5: add_props
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:
#.........这里部分代码省略.........