/usr/lib/python3/dist-packages/pyramid_jinja2/filters.py is in python3-pyramid-jinja2 2.7+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | from pyramid.url import resource_url, route_url, static_url
from pyramid.url import route_path, static_path
from pyramid.threadlocal import get_current_request
from jinja2 import contextfilter
__all__ = [
'resource_url_filter',
'model_url_filter',
'route_url_filter',
'route_path_filter',
'static_url_filter',
'static_path_filter',
]
@contextfilter
def resource_url_filter(ctx, model, *elements, **kw):
"""A filter from ``model`` to a string representing the absolute URL.
This filter calls :py:func:`pyramid.url.resource_url`.
Example::
<a href="{{'my_traversable_object'|resource_url}}">
See my object
</a>
You can also specify optional view name attached at the end of a path::
<a href="{{'my_traversable_object'|resource_url('edit')}}">
Edit my object
</a>
"""
request = ctx.get('request') or get_current_request()
return resource_url(model, request, *elements, **kw)
@contextfilter
def model_url_filter(ctx, model, *elements, **kw):
"""A filter from ``model`` to a string representing the absolute URL.
This filter calls :py:func:`pyramid.url.resource_url`.
.. note ::
This is being deprecated.
See :py:func:`pyramid_jinja2.filters.resource_url`
"""
request = ctx.get('request') or get_current_request()
return resource_url(model, request, *elements, **kw)
@contextfilter
def model_path_filter(ctx, model, *elements, **kw):
"""A filter from ``model`` to a string representing the relative URL.
This filter calls :py:meth:`pyramid.request.Request.resource_path`.
"""
request = ctx.get('request') or get_current_request()
return request.resource_path(model, *elements, **kw)
@contextfilter
def route_url_filter(ctx, route_name, *elements, **kw):
"""A filter from ``route_name`` to a string representing the absolute URL.
This filter calls :py:func:`pyramid.url.route_url`.
Example::
<a href="{{'login'|route_url}}">
Sign in
</a>
"""
request = ctx.get('request') or get_current_request()
return route_url(route_name, request, *elements, **kw)
@contextfilter
def route_path_filter(ctx, route_name, *elements, **kw):
"""A filter from ``route_name`` to a string representing the relative URL.
This filter calls :py:func:`pyramid.url.route_path`.
"""
request = ctx.get('request') or get_current_request()
return route_path(route_name, request, *elements, **kw)
@contextfilter
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)
@contextfilter
def static_path_filter(ctx, path, **kw):
"""A filter from ``path`` to a string representing the relative URL.
This filter calls :py:func:`pyramid.url.static_path`.
"""
request = ctx.get('request') or get_current_request()
return static_path(path, request, **kw)
|