本文整理汇总了Python中django.templatetags.static.PrefixNode类的典型用法代码示例。如果您正苦于以下问题:Python PrefixNode类的具体用法?Python PrefixNode怎么用?Python PrefixNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PrefixNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sharewikify
def sharewikify(value):
if value is not None:
WIKI_WORD = r'http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\)\|,]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
wikifier = re.compile(r'\b(%s)\b' % WIKI_WORD)
value = wikifier.sub(r'<a href="\1" target="_blank">\1</a>', value)
# happy :) :-)
emot1 = re.compile(r'\:[\-]?\)', re.VERBOSE)
value = emot1.sub(r'<img src="%simage/emots/tinymce_smiley-smile18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# wink ;) ;-)
emot11 = re.compile(r'\;[\-]?\)', re.VERBOSE)
value = emot11.sub(r'<img src="%simage/emots/tinymce_smiley-wink18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# very sad :-(( :((
emot22 = re.compile(r'\:[\-]?\(\(', re.VERBOSE)
value = emot22.sub(r'<img src="%simage/emots/tinymce_smiley-cry18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# sad :( :-(
emot2 = re.compile(r'\:[\-]?\(', re.VERBOSE)
value = emot2.sub(r'<img src="%simage/emots/tinymce_smiley-frown18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# kiss =* :-* :*
emot3 = re.compile(r'[=\:][\-]?\*', re.VERBOSE)
value = emot3.sub(r'<img src="%simage/emots/tinymce_smiley-kiss18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# big smile :-D :D
emot4 = re.compile(r'\:[\-]?[dD]', re.VERBOSE)
value = emot4.sub(r'<img src="%simage/emots/tinymce_smiley-laughing18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# tongue sticking out :-P :P :-p :p
emot5 = re.compile(r'\:[\-]?[pP]', re.VERBOSE)
value = emot5.sub(r'<img src="%simage/emots/tinymce_smiley-tongue-out18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# surprised / o, no :-o :O
emot6 = re.compile(r'\:[\-]?[oO]', re.VERBOSE)
value = emot6.sub(r'<img src="%simage/emots/tinymce_smiley-surprised18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# embarrassed :">
emot7 = re.compile(r'\:\"\>', re.VERBOSE)
value = emot7.sub(r'<img src="%simage/emots/tinymce_smiley-embarassed18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# wearing sunglasses B-)
emot8 = re.compile(r'B\-\)', re.VERBOSE)
value = emot8.sub(r'<img src="%simage/emots/tinymce_smiley-cool18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# confused :-/ :-\
emot9 = re.compile(r'\:\-[\\/]', re.VERBOSE)
value = emot9.sub(r'<img src="%simage/emots/tinymce_smiley-undecided18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# angry X-( x-( X( x(
emot9 = re.compile(r'[xX][\-]?\(', re.VERBOSE)
value = emot9.sub(r'<img src="%simage/emots/tinymce_smiley-yell18.gif" />' % PrefixNode.handle_simple("STATIC_URL"), value)
# TODO: Beta 4.1
#quote = re.compile(r'\[quote\](.*)\[/quote\]', re.DOTALL)
#value = quote.sub(r'<p class="quote">\1</p>', value)
return value
示例2: render_js_files
def render_js_files(file_location):
"""
Loads js files references from 'file_location' parameter.
Usage::
{% render_js_files file_location %}
Example::
{% render_js_files 'js/general.json' %}
This method is assuming 'file_location' is under settings.STATIC_DIR dir.
"""
result = ""
static_base_path = settings.STATIC_DIR
json_js_files_path = os.path.join(static_base_path, file_location)
json_data = open(json_js_files_path)
data = json.load(json_data)
files_dirs = data['files']
json_data.close()
src_template = "<script src='%s'></script>\n"
for js_file_path in files_dirs:
result += src_template % urljoin(
PrefixNode.handle_simple("STATIC_URL"),
js_file_path)
return result
示例3: get_treemenus_static_prefix
def get_treemenus_static_prefix():
if django.VERSION >= (1, 3):
from django.templatetags.static import PrefixNode
return PrefixNode.handle_simple("STATIC_URL") + 'treemenus/img'
else:
from django.contrib.admin.templatetags.adminmedia import admin_media_prefix
return admin_media_prefix() + 'img/admin/'
示例4: fiduswriter_config_js
def fiduswriter_config_js(context):
"""
Add Fidus Writer config variables to the window object in JavaScript.
Usage::
{% fiduswriter_config_js %}
"""
if apps.is_installed('django.contrib.staticfiles'):
from django.contrib.staticfiles.storage import staticfiles_storage
static_url = staticfiles_storage.base_url
else:
static_url = PrefixNode.handle_simple("STATIC_URL")
if 'WS_PORT' in settings.SERVER_INFO:
ws_port = settings.SERVER_INFO['WS_PORT']
else:
ws_port = ''
if 'WS_SERVER' in settings.SERVER_INFO:
ws_server = settings.SERVER_INFO['WS_SERVER']
else:
ws_server = ''
if 'user' in context:
username = context['user'].get_username()
else:
username = ''
return {
'static_url': static_url,
'ws_port': ws_port,
'ws_server': ws_server,
'username': username
}
示例5: handle_simple
def handle_simple(cls, path):
static_dipstrap = getattr(settings, 'DIPSTRAP_STATIC_URL', '')
if static_dipstrap:
return urljoin(PrefixNode.handle_simple('DIPSTRAP_STATIC_URL'),
path)
else:
return super(DipstrapNode, cls).handle_simple(path)
示例6: admin_media_prefix
def admin_media_prefix():
"""
Returns the string contained in the setting ADMIN_MEDIA_PREFIX.
"""
warnings.warn(
"The admin_media_prefix template tag is deprecated. "
"Use the static template tag instead.", PendingDeprecationWarning)
return PrefixNode.handle_simple("ADMIN_MEDIA_PREFIX")
示例7: flag
def flag(country_code):
filename = ''
for flag in getattr(settings, 'FLAGS'):
if flag[0] == country_code:
filename = flag[1]
path = getattr(settings, 'FLAGS_ROOT') + filename
return urljoin(PrefixNode.handle_simple("STATIC_URL"), path)
示例8: get_thumb
def get_thumb(image, thumb_format):
try:
thumb = image.get_thumb(thumb_format=thumb_format)
except AttributeError:
thumb = ''
if thumb:
return thumb
else:
for default_thumb in settings.IMAGE_THUMB_DEFAULTS:
if default_thumb[0] == thumb_format:
return urljoin(PrefixNode.handle_simple("STATIC_URL"), default_thumb[1])
return ''
示例9: static
def static(path):
"""
Joins the given path with the STATIC_URL setting.
Usage::
{% static path %}
Examples::
{% static "myapp/css/base.css" %}
{% static variable_with_path %}
"""
return urljoin(PrefixNode.handle_simple("STATIC_URL"), path)
示例10: get_static_webadmin_prefix
def get_static_webadmin_prefix(parser, token):
"""
Populates a template variable with the static prefix,
``settings.WEBADMIN_STATIC_URL``.
Usage::
{% get_static_webadmin_prefix [as varname] %}
Examples::
{% get_static_webadmin_prefix %}
{% get_static_webadmin_prefix as STATIC_WEBADMIN_PREFIX %}
"""
return PrefixNode.handle_token(parser, token, "STATIC_WEBADMIN_URL")
示例11: get_static_feedback_prefix
def get_static_feedback_prefix(parser, token):
"""
Populates a template variable with the static prefix,
``settings.FEEDBACK_STATIC_URL``.
Usage::
{% get_static_feedback_prefix [as varname] %}
Examples::
{% get_static_feedback_prefix %}
{% get_static_feedback_prefix as STATIC_FEEDBACK_PREFIX %}
"""
return PrefixNode.handle_token(parser, token, "STATIC_FEEDBACK_URL")
示例12: handle_simple
def handle_simple(cls, path):
return urljoin(PrefixNode.handle_simple("MEDIA_URL"), path)
示例13: icon_src
def icon_src(self, instance):
path = 'img/aldryn_video/video-32x32.png'
prefix = PrefixNode.handle_simple("STATIC_URL") or PrefixNode.handle_simple("MEDIA_URL")
return urljoin(prefix, path)
示例14: handle_simple
def handle_simple(cls, path):
return os.path.join(PrefixNode.handle_simple('STATIC_ROOT'), path)
示例15: admin_media_prefix
def admin_media_prefix():
"""
Returns the string contained in the setting ADMIN_MEDIA_PREFIX.
"""
return PrefixNode.handle_simple("ADMIN_MEDIA_PREFIX")