Merge pull request #97 from minusf/master

allow theme css/js as urls
This commit is contained in:
Artur Barseghyan 2017-11-28 02:04:47 +01:00 committed by GitHub
commit 74621bd69a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 18 deletions

View file

@ -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

View file

@ -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():

View file

@ -21,8 +21,8 @@
{% block theme-stylesheets %}
{#<!-- This is where stylesheets declared in the Python theme are listed -->#}
{% for css_file in fobi_theme.get_media_css %}
<link href="{% static css_file %}" rel="stylesheet" media="all" />
{% for css in fobi_theme.get_media_css %}
<link href="{{ css }}" rel="stylesheet" media="all" />
{% endfor %}
{% endblock theme-stylesheets %}
@ -189,7 +189,6 @@
</div><!--/.container-->
{% endblock main-content-wrapper %}
{% endblock main-wrapper %}
{% block javascripts %}
@ -199,11 +198,10 @@
{% block theme-javascripts %}
{#<!-- This is where javascripts declared in the Python theme are listed -->#}
{% for js_file in fobi_theme.get_media_js %}
<script src="{% static js_file %}"></script>
{% for js in fobi_theme.get_media_js %}
<script src="{{ js }}"></script>
{% endfor %}
{% endblock theme-javascripts %}
</body>
</html>