Эх сурвалжийг харах

HUE-2417 [desktop] Expose staticfiles.static to the mako templates

Erick Tryzelaar 10 жил өмнө
parent
commit
743b3e8

+ 18 - 7
desktop/core/src/desktop/lib/django_mako.py

@@ -17,23 +17,28 @@
 #
 # Adapted from http://code.google.com/p/django-mako/source/browse/trunk/djangomako/shortcuts.py
 
-from django.http import HttpResponse
-from desktop.lib import apputil, i18n
 import os
 import tempfile
-from mako.lookup import TemplateLookup, TemplateCollection
+
 import django.template
-from django import template
+from django.conf import settings
+from django.contrib.staticfiles.storage import staticfiles_storage
+from django.http import HttpResponse
+
+from mako.lookup import TemplateLookup, TemplateCollection
 
-register = template.Library()
+from desktop.lib import apputil, i18n
+
+register = django.template.Library()
 
 ENCODING_ERRORS = 'replace'
 
 # Things to automatically import into all template namespaces
 IMPORTS=[
-  "from desktop.lib.django_mako import url",
   "from django.utils.html import escape",
-  "from desktop.lib.django_mako import csrf_token"
+  "from desktop.lib.django_mako import url",
+  "from desktop.lib.django_mako import csrf_token",
+  "from desktop.lib.django_mako import static",
 ]
 
 class DesktopLookup(TemplateCollection):
@@ -134,3 +139,9 @@ def csrf_token(request):
   """
   csrf_token = unicode(csrf(request)["csrf_token"])
   return str.format("<input type='hidden' name='csrfmiddlewaretoken' value='{0}' />", csrf_token)
+
+def static(path):
+  """
+  Returns the URL to a file using the staticfiles's storage engine
+  """
+  return staticfiles_storage.url(path)