本文整理汇总了Python中pyramid.url.static_url函数的典型用法代码示例。如果您正苦于以下问题:Python static_url函数的具体用法?Python static_url怎么用?Python static_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了static_url函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: icon_url
def icon_url(self):
if isdir(self.path):
return static_url('weboot:static/folder_32.png', self.request)
if exists(self.path) and isfile(self.path):
if self.name.endswith(".root"):
return static_url('weboot:static/folder_chart_32.png', self.request)
return static_url('weboot:static/close_32.png', self.request)
开发者ID:JohannesEbke,项目名称:WebOOT,代码行数:9,代码来源:filesystem.py
示例2: icon_url
def icon_url(self):
p = self.vfs.get(self.path)
if p.isdir():
if p.isvfile():
return static_url('weboot:static/folder_chart_32.png', self.request)
else:
return static_url('weboot:static/folder_32.png', self.request)
elif p.isobject():
raise RuntimeError("Should not be a VFSTraverser!")
return static_url('weboot:static/close_32.png', self.request)
开发者ID:pwaller,项目名称:WebOOT,代码行数:11,代码来源:vfs.py
示例3: test_it_with_name
def test_it_with_name(self):
from jslibs import includeme
request = testing.DummyRequest()
self.config.registry.settings['jslibs.static_view_name'] = 'aname'
includeme(self.config)
url = static_url(u'jslibs:resources/', request)
self.assertEqual(url, u'http://example.com/aname/')
开发者ID:Pylons,项目名称:jslibs,代码行数:7,代码来源:tests.py
示例4: cover
def cover(request):
sbid = request.matchdict['sbid']
response_headers = {'content_type': 'image/jpeg',}
try:
monograph = request.db.get(sbid)
if 'thumbnail' in request.path:
img = request.db.fetch_attachment(monograph,monograph['cover_thumbnail']['filename'], stream=True)
else:
img = request.db.fetch_attachment(monograph,monograph['cover']['filename'], stream=True)
response_headers['expires'] = datetime_rfc822(365)
except (couchdbkit.ResourceNotFound, KeyError):
img = urllib2.urlopen(static_url('scielobooks:static/images/fakecover.jpg', request))
response = Response(**response_headers)
response.app_iter = img
try:
response.etag = str(hash(img))
except TypeError:
#cannot generate a hash for the object, return it without the ETag
pass
return response
开发者ID:bireme,项目名称:scielobooks,代码行数:25,代码来源:views.py
示例5: static_url
def static_url(self, path, **kw):
"""
Generates a fully qualified URL for a static :term:`asset`. The
asset must live within a location defined via the
:meth:`pyramid.config.Configurator.add_static_view`
:term:`configuration declaration` or the ``<static>`` ZCML directive
(see :ref:`static_assets_section`).
This is a convenience method. The result of calling
:meth:`pyramid.request.Request.static_url` is the same as calling
:func:`pyramid.url.static_url` with an explicit ``request`` parameter.
The :meth:`pyramid.request.Request.static_url` method calls the
:func:`pyramid.url.static_url` function using the Request object as
the ``request`` argument. The ``*kw`` arguments passed to
:meth:`pyramid.request.Request.static_url` are passed through to
:func:`pyramid.url.static_url` unchanged and its result is returned.
This call to :meth:`pyramid.request.Request.static_url`::
request.static_url('mypackage:static/foo.css')
Is completely equivalent to calling :func:`pyramid.url.static_url`
like this::
from pyramid.url import static_url
static_url('mypackage:static/foo.css', request)
See :func:`pyramid.url.static_url` for more information
"""
return static_url(path, self, **kw)
开发者ID:jkrebs,项目名称:pyramid,代码行数:32,代码来源:request.py
示例6: book_details
def book_details(request):
main = get_renderer(BASE_TEMPLATE).implementation()
sbid = request.matchdict['sbid']
try:
monograph = Monograph.get(request.db, sbid)
except couchdbkit.ResourceNotFound:
raise exceptions.NotFound()
book_attachments = []
if getattr(monograph, 'toc', None):
toc_url = static_url('scielobooks:database/%s/%s', request) % (monograph._id, monograph.toc['filename'])
book_attachments.append({'url':toc_url, 'text':_('Table of Contents')})
if getattr(monograph, 'editorial_decision', None):
editorial_decision_url = static_url('scielobooks:database/%s/%s', request) % (monograph._id, monograph.editorial_decision['filename'])
book_attachments.append({'url':editorial_decision_url, 'text':_('Parecer da Editora')})
if getattr(monograph, 'pdf_file', None):
pdf_file_url = static_url('scielobooks:database/%s/%s', request) % (monograph._id, monograph.pdf_file['filename'])
book_attachments.append({'url':pdf_file_url, 'text':_('Book in PDF')})
if getattr(monograph, 'epub_file', None):
epub_file_url = static_url('scielobooks:database/%s/%s', request) % (monograph._id, monograph.epub_file['filename'])
book_attachments.append({'url':epub_file_url, 'text':_('Book in epub')})
evaluation = request.rel_db_session.query(rel_models.Evaluation).filter_by(monograph_sbid=monograph._id).one()
parts = catalog_views.get_book_parts(monograph._id, request)
return {'document':monograph,
'document_parts':parts,
'evaluation':evaluation,
'book_attachments':book_attachments,
'main':main,
'user':get_logged_user(request),
'cover_full_url': request.route_url('catalog.cover', sbid=monograph._id),
'cover_thumb_url': request.route_url('catalog.cover_thumbnail', sbid=monograph._id),
'add_part_url': request.route_url('staff.new_part', sbid=monograph._id),
'general_stuff': {'breadcrumb': [
(_('Dashboard'), request.route_url('staff.panel')),
(monograph.title, None),
]
}
}
开发者ID:alvesjnr,项目名称:scielobooks,代码行数:45,代码来源:views.py
示例7: static_url
def static_url(self):
"""
provides the base of the static URL
.. code-block:: xml
<link rel="shortcut" href="${url.static_url}images/icon.png" />
"""
return static_url('atemplate:static/', self.request)
开发者ID:koansys,项目名称:pyramid_egg_template,代码行数:9,代码来源:rglobals.py
示例8: view_entry
def view_entry(request):
doc = request.db.get(request.matchdict['id'])
img_url = static_url('pyramidattachs:attachments/%s/%s', request) % (doc['_id'], doc['attachment']['filename'])
return render_to_response('templates/view.pt',
{'title':doc['title'],
'attach':img_url,
'about':doc['description'],
'_id': doc['_id']},
request=request)
开发者ID:alvesjnr,项目名称:isisdm,代码行数:11,代码来源:views.py
示例9: static_url_filter
def static_url_filter(ctx, path, **kw):
"""A filter from ``path`` to a string representing the absolute URL.
This filter calls :py:func:`pyramid.url.static_url`.
Example::
<link rel="stylesheet" href="{{'yourapp:static/css/style.css'|static_url}}" />
"""
request = ctx.get('request') or get_current_request()
return static_url(path, request, **kw)
开发者ID:Pylons,项目名称:pyramid_jinja2,代码行数:11,代码来源:filters.py
示例10: view_root_object_render
def view_root_object_render(context, request):
"""
Only called if the object doesn't inherit from Renderable
"""
if request.params.get("render", "") == "xml":
o = context.obj
xmlfile = R.TXMLFile("test.xml", "recreate")
o.Write()
xmlfile.Close()
with open("test.xml") as fd:
content = fd.read()
return Response(content, content_type="text/plain")
return HTTPFound(location=static_url('weboot:static/close_32.png', request))
开发者ID:pwaller,项目名称:WebOOT,代码行数:15,代码来源:object.py
示例11: cover
def cover(request):
sbid = request.matchdict['sbid']
try:
monograph = request.db.get(sbid)
if 'thumbnail' in request.path:
img = request.db.fetch_attachment(monograph,monograph['cover_thumbnail']['filename'], stream=True)
else:
img = request.db.fetch_attachment(monograph,monograph['cover']['filename'], stream=True)
except (couchdbkit.ResourceNotFound, KeyError):
img = urllib2.urlopen(static_url('scielobooks:static/images/fakecover.jpg', request))
response = Response(content_type='image/jpeg')
response.app_iter = img
return response
开发者ID:alvesjnr,项目名称:scielobooks,代码行数:16,代码来源:views.py
示例12: cover
def cover(request):
sbid = request.matchdict["sbid"]
try:
monograph = request.db.get(sbid)
if "thumbnail" in request.path:
img = request.db.fetch_attachment(monograph, monograph["cover_thumbnail"]["filename"], stream=True)
else:
img = request.db.fetch_attachment(monograph, monograph["cover"]["filename"], stream=True)
except (couchdbkit.ResourceNotFound, KeyError):
img = urllib2.urlopen(static_url("scielobooks:static/images/fakecover.jpg", request))
response = Response(content_type="image/jpeg")
response.app_iter = img
return response
开发者ID:rondinelisaad,项目名称:scielobooks,代码行数:16,代码来源:views.py
示例13: StaticUrl
def StaticUrl(self, file):
"""
Generates the url for a static file.
*file* is the filename to look the url up for. E.g. for the default static directory use ::
<link tal:attributes="href view.StaticUrl('layout2.css')"
rel="stylesheet" type="text/css" media="all" />
to reference a file in a different directory you must include the python module like ::
<link tal:attributes="href view.StaticUrl('my_app.design:static/layout2.css')"
rel="stylesheet" type="text/css" media="all" />
returns url
"""
if not u":" in file and self.viewModule and self.viewModule.static:
file = u"%s/%s" % (self.viewModule.static, file)
return static_url(file, self.request)
开发者ID:adroullier,项目名称:nive,代码行数:18,代码来源:views.py
示例14: template_globals
def template_globals(event):
"""Adds stuff we use all the time to template context.
There is no need to add *request* since it is already there.
"""
request = event["request"]
settings = request.registry.settings
# A nicer "route_url": no need to pass it the request object.
event["url"] = lambda name, *a, **kw: route_url(name, request, *a, **kw)
event["base_path"] = settings.get("base_path", "/")
event["static_url"] = lambda s: static_url(s, request)
event["appname"] = settings.get("app.name", "Application")
localizer = get_localizer(request)
translate = localizer.translate
pluralize = localizer.pluralize
event["_"] = lambda text, mapping=None: translate(text, domain=package_name, mapping=mapping)
event["plur"] = lambda singular, plural, n, mapping=None: pluralize(
singular, plural, n, domain=package_name, mapping=mapping
)
开发者ID:leofigs,项目名称:bag,代码行数:18,代码来源:starter.py
示例15: template_globals
def template_globals(event):
'''Adds stuff we use all the time to template context.
There is no need to add *request* since it is already there.
'''
request = event['request']
settings = request.registry.settings
# A nicer "route_url": no need to pass it the request object.
event['url'] = lambda name, *a, **kw: \
route_url(name, request, *a, **kw)
event['base_path'] = settings.get('base_path', '/')
event['static_url'] = lambda s: static_url(s, request)
event['appname'] = settings.get('app.name', 'Application')
localizer = get_localizer(request)
translate = localizer.translate
pluralize = localizer.pluralize
event['_'] = lambda text, mapping=None: \
translate(text, domain=package_name, mapping=mapping)
event['plur'] = lambda singular, plural, n, mapping=None: \
pluralize(singular, plural, n,
domain=package_name, mapping=mapping)
开发者ID:dmckeone,项目名称:bag,代码行数:20,代码来源:starter.py
示例16: add_globals
def add_globals(event):
'''Add *context_url* and *static_url* functions to the template
renderer global namespace for easy generation of url's within
templates.
'''
request = event['request']
def context_url(s, context=None,request=request):
if context is None:
context = request.context
url = resource_url(context,request)
if not url.endswith('/'):
url += '/'
return url + s
def gen_url(route_name=None, request=request, **kw):
if not route_name:
local_request = get_current_request()
route_name = local_request.matched_route.name
url = route_url(route_name, request, **kw)
return url
event['gen_url'] = gen_url
event['context_url'] = context_url
event['static_url'] = lambda x: static_url(x, request)
开发者ID:robert118,项目名称:ztq,代码行数:22,代码来源:views.py
示例17: template_globals
def template_globals(event):
'''Adds stuff we use all the time to template context.
There is no need to add *request* since it is already there.
'''
request = event['request']
settings = request.registry.settings
# A nicer "route_url": no need to pass it the request object.
event['url'] = lambda name, *a, **kw: \
route_url(name, request, *a, **kw)
event['base_path'] = settings.get('base_path', '/')
event['static_url'] = lambda s: static_url(s, request)
event['locale_name'] = get_locale_name(request) # to set xml:lang
event['enabled_locales'] = settings['enabled_locales']
event['appname'] = settings.get('app.name', 'Application')
# http://docs.pylonsproject.org/projects/pyramid_cookbook/dev/i18n.html
localizer = get_localizer(request)
translate = localizer.translate
pluralize = localizer.pluralize
event['_'] = lambda text, mapping=None: \
translate(text, domain=package_name, mapping=mapping)
event['plur'] = lambda singular, plural, n, mapping=None: \
pluralize(singular, plural, n,
domain=package_name, mapping=mapping)
开发者ID:it3s,项目名称:mootiro_web,代码行数:23,代码来源:pyramid_starter.py
示例18: home_view
def home_view(request, input_filepath, output_basename_generator):
settings = request.registry.settings
converted_path = settings['convertit.converted_path']
input_mimetype = get_input_mimetype(request, input_filepath)
output_mimetype = request.GET.get('to', 'application/pdf')
output_basename = output_basename_generator(request, output_mimetype)
output_filepath = os.path.join(converted_path, output_basename)
remove_old_files(request)
convert = get_converter(request, input_mimetype, output_mimetype)
try:
convert(input_filepath, output_filepath)
except Exception as e:
message = "Sorry, there was an error fetching the document. Reason: %s"
return HTTPBadRequest(message % str(e))
return HTTPFound(static_url(output_filepath, request),
content_disposition='attachement; filename=%s' %
output_basename)
开发者ID:D3f0,项目名称:convertit,代码行数:23,代码来源:views.py
示例19: StaticUrl
def StaticUrl(self, file):
"""
Generates the url for a static file.
*file* is the filename to look the url up for. E.g. for the default static directory use ::
<link tal:attributes="href view.StaticUrl('layout2.css')"
rel="stylesheet" type="text/css" media="all" >
to reference a file in a different directory you must include the python module like ::
<link tal:attributes="href view.StaticUrl('my_app.design:static/layout2.css')"
rel="stylesheet" type="text/css" media="all" >
absolute http urls can also be used based on the url prefix http, https and / ::
<link tal:attributes="href view.StaticUrl('/assets/layout2.css')"
rel="stylesheet" type="text/css" media="all" >
<link tal:attributes="href view.StaticUrl('http://myserver.com/assets/layout2.css')"
rel="stylesheet" type="text/css" media="all" >
<link tal:attributes="href view.StaticUrl('https://myserver.com/assets/layout2.css')"
rel="stylesheet" type="text/css" media="all" >
returns url
"""
if file is None:
return u""
if file.startswith((u"http://",u"https://",u"/")):
return file
if not u":" in file and self.viewModule and self.viewModule.static:
if self.viewModule.static.endswith((u"/",u":")):
file = self.viewModule.static + file
else:
file = u"%s/%s" % (self.viewModule.static, file)
if file.startswith((u"http://",u"https://",u"/")):
return file
return static_url(file, self.request)
开发者ID:nive,项目名称:nive,代码行数:36,代码来源:views.py
示例20: home_view
def home_view(request, input_filepath, output_basename_generator):
settings = request.registry.settings
converted_path = settings["convertit.converted_path"]
input_mimetype = get_input_mimetype(request, input_filepath)
output_mimetype = request.GET.get("to", "application/pdf")
output_basename = output_basename_generator(request, output_mimetype)
output_filepath = os.path.join(converted_path, output_basename)
remove_old_files(request)
convert = get_converter(request, input_mimetype, output_mimetype)
try:
convert(input_filepath, output_filepath)
except Exception as e:
message = "Sorry, there was an error converting the document. Reason: %s"
log.error(message % str(e))
return HTTPInternalServerError(body=message % str(e), content_type="text/plain")
return HTTPFound(
static_url(output_filepath, request), content_disposition="attachement; filename=%s" % output_basename
)
开发者ID:makinacorpus,项目名称:convertit,代码行数:24,代码来源:views.py
注:本文中的pyramid.url.static_url函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论