本文整理汇总了Python中r2.lib.filters.spaceCompress函数的典型用法代码示例。如果您正苦于以下问题:Python spaceCompress函数的具体用法?Python spaceCompress怎么用?Python spaceCompress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spaceCompress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: thing_attr
def thing_attr(self, thing, attr):
if attr == "_fullname":
return "LiveUpdateEvent_" + thing._id
elif attr == "viewer_count":
if thing.state == "live":
return thing.active_visitors
else:
return None
elif attr == "viewer_count_fuzzed":
if thing.state == "live":
return thing.active_visitors_fuzzed
else:
return None
elif attr == "description_html":
return filters.spaceCompress(
filters.safemarkdown(thing.description, nofollow=True) or "")
elif attr == "resources_html":
return filters.spaceCompress(
filters.safemarkdown(thing.resources, nofollow=True) or "")
elif attr == "websocket_url":
if thing.state == "live":
return websockets.make_url(
"/live/" + c.liveupdate_event._id, max_age=24 * 60 * 60)
else:
return None
else:
return ThingJsonTemplate.thing_attr(self, thing, attr)
示例2: thing_attr
def thing_attr(self, thing, attr):
if attr == "_fullname":
return "LiveUpdateEvent_" + thing._id
elif attr == "viewer_count":
if thing.state == "live":
return thing.active_visitors
else:
return None
elif attr == "viewer_count_fuzzed":
if thing.state == "live":
return thing.active_visitors_fuzzed
else:
return None
elif attr == "total_views":
# this requires an extra query, so we'll only show it in places
# where we're just getting one event.
if not hasattr(thing, "total_views"):
return None
return thing.total_views
elif attr == "description_html":
return filters.spaceCompress(
filters.safemarkdown(thing.description, nofollow=True) or "")
elif attr == "resources_html":
return filters.spaceCompress(
filters.safemarkdown(thing.resources, nofollow=True) or "")
elif attr == "websocket_url":
if thing.state == "live":
return websockets.make_url(
"/live/" + thing._id, max_age=24 * 60 * 60)
else:
return None
else:
return ThingJsonTemplate.thing_attr(self, thing, attr)
示例3: GET_tb
def GET_tb(self, link):
from r2.lib.media import thumbnail_url
"/tb/$id36, show a given link with the toolbar"
if not link:
return self.abort404()
elif link.is_self:
return self.redirect(link.url)
# if the domain is shame-banned, bail out.
if is_shamed_domain(link.url, request.ip)[0]:
self.abort404()
if not link.subreddit_slow.can_view(c.user):
self.abort403()
if link.has_thumbnail:
thumbnail = thumbnail_url(link)
else:
thumbnail = None
res = Frame(title = link.title,
url = link.url,
thumbnail = thumbnail,
fullname = link._fullname)
return spaceCompress(res.render())
示例4: POST_request_promo
def POST_request_promo(self, srnames):
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)
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.is_promoted,
num=1,
skip=True)
listing = LinkListing(builder, nextprev=False).listing()
if listing.things:
g.stats.simple_event('adzerk.request.valid_promo')
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())
else:
g.stats.simple_event('adzerk.request.skip_promo')
示例5: GET_tb
def GET_tb(self, link):
'''/tb/$id36, show a given link with the toolbar
If the user doesn't have the toolbar enabled, redirect to comments
page.
'''
from r2.lib.media import thumbnail_url
if not link:
return self.abort404()
elif link.is_self:
return self.redirect(link.url)
elif not (c.user_is_loggedin and c.user.pref_frame):
return self.redirect(link.make_permalink_slow(force_domain=True))
# if the domain is shame-banned, bail out.
if is_shamed_domain(link.url)[0]:
self.abort404()
if not link.subreddit_slow.can_view(c.user):
self.abort403()
if link.has_thumbnail:
thumbnail = thumbnail_url(link)
else:
thumbnail = None
res = Frame(
title=link.title,
url=match_current_reddit_subdomain(link.url),
thumbnail=thumbnail,
fullname=link._fullname,
)
return spaceCompress(res.render())
示例6: thing_attr
def thing_attr(self, thing, attr):
from r2.models import Comment, Link, Subreddit
if attr == 'link_id':
return make_fullname(Link, thing.link_id)
elif attr == "controversiality":
return 1 if thing.is_controversial else 0
elif attr == "editted" and not isinstance(thing.editted, bool):
return (time.mktime(thing.editted.astimezone(pytz.UTC).timetuple())
- time.timezone)
elif attr == 'subreddit':
return thing.subreddit.name
elif attr == 'subreddit_id':
return thing.subreddit._fullname
elif attr == "parent_id":
if getattr(thing, "parent_id", None):
return make_fullname(Comment, thing.parent_id)
else:
return make_fullname(Link, thing.link_id)
elif attr == "body_html":
return spaceCompress(safemarkdown(thing.body))
elif attr == "gilded":
return thing.gildings
elif attr == "archived":
return not thing.votable
return ThingJsonTemplate.thing_attr(self, thing, attr)
示例7: cells
def cells(self, thing):
cells = []
for cell in thing.cells:
thing.name = cell
r = thing.part_render('cell_type', style = "html")
cells.append(spaceCompress(r))
return cells
示例8: GET_toolbar
def GET_toolbar(self, link, url):
"""The visible toolbar, with voting buttons and all"""
if url:
url = demangle_url(url)
if link:
wrapped = wrap_links(link, wrapper=FrameToolbar, num=1)
elif url:
listing = hot_links_by_url_listing(url, sr=c.site, num=1, skip=True)
if listing.things:
wrapped = listing.things[0]
else:
wrapped = None
else:
return self.abort404()
res = None
if wrapped:
res = wrapped
elif url:
res = FrameToolbar(link=None, title=None, url=url, expanded=False)
if res:
return spaceCompress(res.render())
else:
return self.abort404()
示例9: GET_button_content
def GET_button_content(self, url, title, css, vote, newwindow, width, link):
# no buttons on domain listings
if isinstance(c.site, DomainSR):
c.site = Default
return self.redirect(request.path + query_string(request.GET))
#disable css hack
if (css != 'http://blog.wired.com/css/diggsocial.css' and
css != 'http://www.wired.com/css/diggsocial.css'):
css = None
if link:
url = link.url
wrapper = make_wrapper(Button if vote else ButtonNoBody,
url = url,
target = "_new" if newwindow else "_parent",
title = title, vote = vote, bgcolor = c.bgcolor,
width = width, css = css,
button = self.buttontype())
l = self.get_wrapped_link(url, link, wrapper)
res = l.render()
c.response.content = spaceCompress(res)
return c.response
示例10: GET_inner
def GET_inner(self, link):
"""The intermediate frame that displays the comments side-bar
on one side and the link on the other"""
if not link:
return self.abort404()
res = InnerToolbarFrame(link = link, expanded = auto_expand_panel(link))
return spaceCompress(res.render())
示例11: rendered_data
def rendered_data(self, thing):
from r2.lib.filters import spaceCompress
from r2.lib.template_helpers import replace_render
from pylons import c
listing = thing.listing if hasattr(thing, "listing") else None
return dict(id = thing._fullname,
vl = self.points(thing),
content = spaceCompress(replace_render(listing, thing,
style=get_api_subtype())))
示例12: ajax_render
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)
示例13: GET_tb
def GET_tb(self, link):
"/tb/$id36, show a given link with the toolbar"
if not link:
return self.abort404()
res = Frame(title = link.title,
url = link.url,
fullname = link._fullname)
return spaceCompress(res.render())
示例14: GET_toolbar
def GET_toolbar(self, link, url):
"""The visible toolbar, with voting buttons and all"""
if url:
url = demangle_url(url)
if link:
wrapped = wrap_links(link, wrapper=FrameToolbar, num=1)
else:
return self.abort404()
return spaceCompress(wrapped.render())
示例15: GET_s
def GET_s(self, rest):
"""/s/http://..., show a given URL with the toolbar. if it's
submitted, redirect to /tb/$id36"""
force_html()
path = demangle_url(request.fullpath)
if not path:
# it was malformed
self.abort404()
# if the domain is shame-banned, bail out.
if is_shamed_domain(path)[0]:
self.abort404()
listing = hot_links_by_url_listing(path, sr=c.site, num=1)
link = listing.things[0] if listing.things else None
if c.cname and not c.authorized_cname:
# In this case, we make some bad guesses caused by the
# cname frame on unauthorised cnames.
# 1. User types http://foo.com/http://myurl?cheese=brie
# (where foo.com is an unauthorised cname)
# 2. We generate a frame that points to
# http://www.reddit.com/r/foo/http://myurl?cnameframe=0.12345&cheese=brie
# 3. Because we accept everything after the /r/foo/, and
# we've now parsed, modified, and reconstituted that
# URL to add cnameframe, we really can't make any good
# assumptions about what we've done to a potentially
# already broken URL, and we can't assume that we've
# rebuilt it in the way that it was originally
# submitted (if it was)
# We could try to work around this with more guesses (by
# having demangle_url try to remove that param, hoping
# that it's not already a malformed URL, and that we
# haven't re-ordered the GET params, removed
# double-slashes, etc), but for now, we'll just refuse to
# do this operation
return self.abort404()
if link:
# we were able to find it, let's send them to the
# link-id-based URL so that their URL is reusable
return self.redirect(add_sr("/tb/" + link._id36))
title = utils.domain(path)
res = Frame(
title=title,
url=match_current_reddit_subdomain(path),
)
# we don't want clients to think that this URL is actually a
# valid URL for search-indexing or the like
request.environ['usable_error_content'] = spaceCompress(res.render())
abort(404)