diff --git a/src/fobi/base.py b/src/fobi/base.py index 85f4256c..47753489 100644 --- a/src/fobi/base.py +++ b/src/fobi/base.py @@ -638,11 +638,7 @@ class BaseTheme(object): :return list: """ - media_css = self.media_css[:] - if self.plugin_media_css: - media_css += self.plugin_media_css - - media_css = uniquify_sequence(media_css) + media_css = uniquify_sequence(self.media_css + self.plugin_media_css) return media_css @@ -651,11 +647,7 @@ class BaseTheme(object): :return list: """ - media_js = self.media_js[:] - if self.plugin_media_js: - media_js += self.plugin_media_js - - media_js = uniquify_sequence(media_js) + media_js = uniquify_sequence(self.media_js + self.plugin_media_js) return media_js diff --git a/src/fobi/helpers.py b/src/fobi/helpers.py index 293bc690..edf167ba 100644 --- a/src/fobi/helpers.py +++ b/src/fobi/helpers.py @@ -18,6 +18,7 @@ from django.contrib.auth.models import AnonymousUser from django.core.files.base import File # from django.db.utils import DatabaseError from django.http import HttpResponse +from django.templatetags.static import static from django.test.client import RequestFactory from django.utils.encoding import force_text from django.utils.html import format_html_join @@ -188,6 +189,17 @@ def two_dicts_to_string(headers, data, html_element='p'): empty_string = text_type('') +def absolute_path(path): + """ + Given a relative or absolute path to a static asset, return an absolute + path. An absolute path will be returned unchanged while a relative path + will be passed to django.templatetags.static.static(). + """ + if path.startswith(('http://', 'https://', '/')): + return path + return static(path) + + def uniquify_sequence(sequence): """Uniqify sequence. @@ -199,7 +211,8 @@ def uniquify_sequence(sequence): """ seen = set() seen_add = seen.add - return [x for x in sequence if x not in seen and not seen_add(x)] + return [absolute_path(x) + for x in sequence if x not in seen and not seen_add(x)] def get_ignorable_form_values(): diff --git a/src/fobi/templates/fobi/generic/_base.html b/src/fobi/templates/fobi/generic/_base.html index 5c2103f7..3656bbea 100644 --- a/src/fobi/templates/fobi/generic/_base.html +++ b/src/fobi/templates/fobi/generic/_base.html @@ -21,8 +21,8 @@ {% block theme-stylesheets %} {##} - {% for css_file in fobi_theme.get_media_css %} - + {% for css in fobi_theme.get_media_css %} + {% endfor %} {% endblock theme-stylesheets %} @@ -189,7 +189,6 @@ {% endblock main-content-wrapper %} - {% endblock main-wrapper %} {% block javascripts %} @@ -199,11 +198,10 @@ {% block theme-javascripts %} {##} - {% for js_file in fobi_theme.get_media_js %} - + {% for js in fobi_theme.get_media_js %} + {% endfor %} - {% endblock theme-javascripts %} - +