本文整理汇总了Python中r2.lib.template_helpers.get_domain函数的典型用法代码示例。如果您正苦于以下问题:Python get_domain函数的具体用法?Python get_domain怎么用?Python get_domain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_domain函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_permalink
def make_permalink(self, sr, force_domain = False):
from r2.lib.template_helpers import get_domain
p = "comments/%s/%s/" % (self._id36, title_to_url(self.title))
# promoted links belong to a separate subreddit and shouldn't
# include that in the path
if self.promoted is not None:
if force_domain:
res = "http://%s/%s" % (get_domain(cname = False,
subreddit = False), p)
else:
res = "/%s" % p
elif not c.cname and not force_domain:
res = "/r/%s/%s" % (sr.name, p)
elif sr != c.site or force_domain:
res = "http://%s/%s" % (get_domain(cname = (c.cname and
sr == c.site),
subreddit = not c.cname), p)
else:
res = "/%s" % p
# WARNING: If we ever decide to add any ?foo=bar&blah parameters
# here, Comment.make_permalink will need to be updated or else
# it will fail.
return res
示例2: request_start
def request_start():
# don't process ErrorController requests
if request.environ.get("pylons.error_call", False):
return
cookie_name = 'beta_' + g.beta_name
c.beta = g.beta_name if cookie_name in request.cookies else None
if not c.beta and request.host != g.beta_domain:
# a regular site url without a beta cookie got sent to a beta app.
# this is a configuration error that should not happen in practice, and
# can cause redirect loops if we're not careful.
raise ConfigurationError('request missing beta cookie')
# run our own authentication check to sidestep c.user overrides such as the
# logged-out override for JSONP.
user = authentication.cookie()
user_allowed = user and beta_user_allowed(user)
if request.path.startswith('/beta'):
if request.host != g.beta_domain:
# canonicalize /beta urls to beta domain for clarity.
redirect_to_host(g.beta_domain)
else:
if request.host == g.beta_domain:
# redirect non-/beta requests on the beta domain to default domain.
redirect_to_host(get_domain(subreddit=False))
if not user_allowed:
# they have a beta cookie but are not permitted access.
# this should hopefully only happen in corner cases (access
# changed or they somehow logged out without deleting the beta
# cookie)
if (request.method == 'GET' and
response.content_type == 'text/html'):
# redirect to /beta/disable/NAME, which will delete the cookie.
redirect_to_host(g.beta_domain, '/beta/disable')
else:
# attempt to delete the cookie and redirect-retry.
#
# note: this redirect might result in a loop if the request on the
# default domain is also served by this beta app, which is one
# reason we strictly check and throw an error if this is the case
# above.
delete_beta_cookie()
redirect_to_host(get_domain(subreddit=False))
# extend cookie duration for a week
touch_beta_cookie()
示例3: stylesheet_url
def stylesheet_url(self):
from r2.lib.template_helpers import static, get_domain
if self.stylesheet_is_static:
return static(self.static_stylesheet_name)
else:
return "http://%s/stylesheet.css?v=%s" % (get_domain(cname=False, subreddit=True), self.stylesheet_hash)
示例4: make_permalink
def make_permalink(self, sr, force_domain = False, sr_path = False):
from r2.lib.template_helpers import get_domain
def slug():
"""
Retrieves the original URL slug (if any) to prevent the
URL from changing when the article title is updated.
"""
# This could probably just check for `self.url == None`.
if not isinstance(self.url, basestring):
return self.title
regex = re.compile("""
/ea # subreddit
/[^/]+ # ID
/(?P<title>[^/]+)/ # title
""", re.X)
match = regex.match(self.url)
if match:
return match.group("title")
else:
return title_to_url(self.title)
p = "ea/%s/%s/" % (self._id36, slug())
if c.default_sr and not sr_path:
res = "/%s" % p
elif sr and not c.cname:
res = "/r/%s/%s" % (sr.name, p)
elif sr != c.site or force_domain:
res = "http://%s/%s" % (get_domain(cname = (c.cname and sr == c.site),
subreddit = not c.cname), p)
else:
res = "/%s" % p
return res
示例5: GET_search
def GET_search(self, query, num, reverse, after, count, sort):
"""Search links page."""
if query and '.' in query:
url = sanitize_url(query, require_scheme = True)
if url:
return self.redirect("/submit" + query_string({'url':url}))
q = IndextankQuery(query, c.site, sort)
num, t, spane = self._search(q, num = num, after = after, reverse = reverse,
count = count)
if not isinstance(c.site,FakeSubreddit) and not c.cname:
all_reddits_link = "%s/search%s" % (subreddit.All.path,
query_string({'q': query}))
d = {'reddit_name': c.site.name,
'reddit_link': "http://%s/"%get_domain(cname = c.cname),
'all_reddits_link': all_reddits_link}
infotext = strings.searching_a_reddit % d
else:
infotext = None
res = SearchPage(_('search results'), query, t, num, content=spane,
nav_menus = [SearchSortMenu(default=sort)],
search_params = dict(sort = sort),
infotext = infotext).render()
return res
示例6: submit_link
def submit_link(self):
from r2.lib.template_helpers import get_domain
from mako.filters import url_escape
d = get_domain(subreddit=False)
u = self.url()
return "http://%s/r/ads/submit?url=%s" % (d, url_escape(u))
示例7: GET_search
def GET_search(self, query, num, time, reverse, after, count, langs, sort):
"""Search links page."""
if query and '.' in query:
url = sanitize_url(query, require_scheme=True)
if url:
return self.redirect("/submit" + query_string({'url': url}))
if langs and self.verify_langs_regex.match(langs):
langs = langs.split(',')
else:
langs = c.content_langs
subreddits = None
authors = None
if c.site == subreddit.Friends and c.user_is_loggedin and c.user.friends:
authors = c.user.friends
elif isinstance(c.site, MultiReddit):
subreddits = c.site.sr_ids
elif not isinstance(c.site, FakeSubreddit):
subreddits = [c.site._id]
q = LinkSearchQuery(
q=query,
timerange=time,
langs=langs,
subreddits=subreddits,
authors=authors,
sort=SearchSortMenu.operator(sort))
num, t, spane = self._search(
q, num=num, after=after, reverse=reverse, count=count)
if not isinstance(c.site, FakeSubreddit) and not c.cname:
all_reddits_link = "%s/search%s" % (subreddit.All.path,
query_string({
'q': query
}))
d = {
'reddit_name': c.site.name,
'reddit_link': "http://%s/" % get_domain(cname=c.cname),
'all_reddits_link': all_reddits_link
}
infotext = strings.searching_a_reddit % d
else:
infotext = None
res = SearchPage(
_('search results'),
query,
t,
num,
content=spane,
nav_menus=[TimeMenu(default=time),
SearchSortMenu(default=sort)],
search_params=dict(sort=sort, t=time),
infotext=infotext).render()
return res
示例8: make_permalink
def make_permalink(self, force_domain=False):
from r2.lib.template_helpers import get_domain
p = self.permalink
if force_domain:
permalink_domain = get_domain(subreddit=False)
res = "%s://%s%s" % (g.default_scheme, permalink_domain, p)
else:
res = p
return res
示例9: make_permalink
def make_permalink(self, sr, force_domain = False):
from r2.lib.template_helpers import get_domain
p = "comments/%s/%s/" % (self._id36, title_to_url(self.title))
if not c.cname:
res = "/r/%s/%s" % (sr.name, p)
elif sr != c.site or force_domain:
res = "http://%s/%s" % (get_domain(cname = (c.cname and sr == c.site),
subreddit = not c.cname), p)
else:
res = "/%s" % p
return res
示例10: __init__
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
示例11: render_iframe_arrows
def render_iframe_arrows(context,thing):
context.caller_stack._push_frame()
try:
_import_ns = {}
_mako_get_namespace(context, '__anon_0x7f21644298d0')._populate(_import_ns, [u'optionalstyle'])
_mako_get_namespace(context, '__anon_0x7f2164429990')._populate(_import_ns, [u'arrow'])
isinstance = _import_ns.get('isinstance', context.get('isinstance', UNDEFINED))
optionalstyle = _import_ns.get('optionalstyle', context.get('optionalstyle', UNDEFINED))
__M_writer = context.writer()
# SOURCE LINE 70
__M_writer(u'\n ')
# SOURCE LINE 71
from r2.lib.template_helpers import get_domain
# SOURCE LINE 73
__M_writer(u'\n <div class="reddit-voting-arrows" \n ')
# SOURCE LINE 75
__M_writer(conditional_websafe(optionalstyle("float:left; margin: 1px;")))
__M_writer(u'>\n <script type="text/javascript">\n var reddit_bordercolor="FFFFFF";\n </script>\n ')
# SOURCE LINE 79
from r2.models import FakeSubreddit
url = ("http://%s/static/button/button4.html?t=4&id=%s&sr=%s" %
(get_domain(cname = c.cname, subreddit = False), thing._fullname,
c.site.name if not isinstance(c.site, FakeSubreddit) else ""))
if c.bgcolor:
url += "&bgcolor=%s&bordercolor=%s" % (c.bgcolor, c.bgcolor)
else:
url += "&bgcolor=FFFFFF&bordercolor=FFFFFF"
# SOURCE LINE 88
__M_writer(u'\n <iframe src="')
# SOURCE LINE 89
__M_writer(conditional_websafe(url))
__M_writer(u'" height="55" width="51" scrolling="no" frameborder="0"\n ')
# SOURCE LINE 90
__M_writer(conditional_websafe(optionalstyle("margin:0px;")))
__M_writer(u'>\n </iframe>\n </div>\n')
return ''
finally:
context.caller_stack._pop_frame()
开发者ID:guizhenwei,项目名称:reddit,代码行数:44,代码来源:home-reddit-src-reddit-r2-r2-templates-printable.htmllite.py
示例12: render_static_arrows
def render_static_arrows(context,thing):
context.caller_stack._push_frame()
try:
_import_ns = {}
_mako_get_namespace(context, '__anon_0x7f21644298d0')._populate(_import_ns, [u'optionalstyle'])
_mako_get_namespace(context, '__anon_0x7f2164429990')._populate(_import_ns, [u'arrow'])
optionalstyle = _import_ns.get('optionalstyle', context.get('optionalstyle', UNDEFINED))
__M_writer = context.writer()
# SOURCE LINE 50
__M_writer(u'\n ')
# SOURCE LINE 51
from r2.lib.template_helpers import get_domain
domain = get_domain(subreddit=False)
permalink = "http://%s%s" % (domain, thing.permalink)
if thing.likes == False:
arrow = "https://%s/static/widget_arrows_down.gif"
elif thing.likes:
arrow = "https://%s/static/widget_arrows_up.gif"
else:
arrow = "https://%s/static/widget_arrows.gif"
arrow = arrow % domain
# SOURCE LINE 62
__M_writer(u'\n <a href="')
# SOURCE LINE 63
__M_writer(conditional_websafe(permalink))
__M_writer(u'" class="reddit-voting-arrows" target="_blank"\n ')
# SOURCE LINE 64
__M_writer(conditional_websafe(optionalstyle("float:left; display:block;")))
__M_writer(u'>\n <img src="')
# SOURCE LINE 65
__M_writer(conditional_websafe(arrow))
__M_writer(u'" alt="vote" \n ')
# SOURCE LINE 66
__M_writer(conditional_websafe(optionalstyle("border:none;margin-top:3px;")))
__M_writer(u'/>\n </a>\n')
return ''
finally:
context.caller_stack._pop_frame()
开发者ID:guizhenwei,项目名称:reddit,代码行数:41,代码来源:home-reddit-src-reddit-r2-r2-templates-printable.htmllite.py
示例13: add_props
def add_props(cls, user, wrapped):
from r2.lib.pages import make_link_child
from r2.lib.count import incr_counts
from r2.lib.media import thumbnail_url
from r2.lib.utils import timeago
from r2.lib.template_helpers import get_domain
from r2.models.subreddit import FakeSubreddit
from r2.lib.wrapped import CachedVariable
# referencing c's getattr is cheap, but not as cheap when it
# is in a loop that calls it 30 times on 25-200 things.
user_is_admin = c.user_is_admin
user_is_loggedin = c.user_is_loggedin
pref_media = user.pref_media
pref_frame = user.pref_frame
pref_newwindow = user.pref_newwindow
cname = c.cname
site = c.site
if user_is_loggedin:
saved_lu = []
for item in wrapped:
if not SaveHide._can_skip_lookup(user, item):
saved_lu.append(item._id36)
saved = CassandraSave._fast_query(user._id36, saved_lu)
hidden = CassandraHide._fast_query(user._id36, saved_lu)
clicked = {}
else:
saved = hidden = clicked = {}
trials = trial_info(wrapped)
for item in wrapped:
show_media = False
if not hasattr(item, "score_fmt"):
item.score_fmt = Score.number_only
if c.render_style == 'compact':
item.score_fmt = Score.points
item.pref_compress = user.pref_compress
if user.pref_compress and item.promoted is None:
item.render_css_class = "compressed link"
item.score_fmt = Score.points
elif pref_media == 'on' and not user.pref_compress:
show_media = True
elif pref_media == 'subreddit' and item.subreddit.show_media:
show_media = True
elif item.promoted and item.has_thumbnail:
if user_is_loggedin and item.author_id == user._id:
show_media = True
elif pref_media != 'off' and not user.pref_compress:
show_media = True
item.over_18 = bool(
item.over_18 or item.subreddit.over_18
or item._nsfw.findall(item.title))
item.nsfw = item.over_18 and user.pref_label_nsfw
item.is_author = (user == item.author)
# always show a promo author their own thumbnail
if item.promoted and (user_is_admin
or item.is_author) and item.has_thumbnail:
item.thumbnail = thumbnail_url(item)
elif user.pref_no_profanity and item.over_18 and not c.site.over_18:
if show_media:
item.thumbnail = "/static/nsfw2.png"
else:
item.thumbnail = ""
elif not show_media:
item.thumbnail = ""
elif item.has_thumbnail:
item.thumbnail = thumbnail_url(item)
elif item.is_self:
item.thumbnail = g.self_thumb
else:
item.thumbnail = g.default_thumb
item.score = max(0, item.score)
if getattr(item, "domain_override", None):
item.domain = item.domain_override
else:
item.domain = (domain(item.url) if not item.is_self else
'self.' + item.subreddit.name)
item.urlprefix = ''
if user_is_loggedin:
item.saved = (user._id36, item._id36) in saved
item.hidden = (user._id36, item._id36) in hidden
item.clicked = bool(clicked.get((user, item, 'click')))
else:
item.saved = item.hidden = item.clicked = False
item.num = None
item.permalink = item.make_permalink(item.subreddit)
if item.is_self:
item.url = item.make_permalink(
#.........这里部分代码省略.........
示例14: promo_edit_url
def promo_edit_url(l):
domain = get_domain(cname=False, subreddit=False)
return "http://%s/promoted/edit_promo/%s" % (domain, l._id36)
示例15: view_live_url
def view_live_url(l, srname):
url = get_domain(cname=False, subreddit=False)
if srname:
url += '/r/%s' % srname
return 'http://%s/?ad=%s' % (url, l._fullname)