[extensions-web/feature/static-manifests: 4/4] Added support for ManifestStaticFilesStorage
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web/feature/static-manifests: 4/4] Added support for ManifestStaticFilesStorage
- Date: Sun, 29 Jan 2017 19:14:07 +0000 (UTC)
commit cfbe2eab73509eb963c71bb77936325d11f35616
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Sun Jan 29 23:12:21 2017 +0400
Added support for ManifestStaticFilesStorage
sweettooth/review/templates/review/review.html | 3 +-
sweettooth/settings.py | 6 +++
sweettooth/templates/base.html | 13 +++++---
sweettooth/templates/templatetags/static_paths.py | 36 +++++++++++++++++++++
4 files changed, 52 insertions(+), 6 deletions(-)
---
diff --git a/sweettooth/review/templates/review/review.html b/sweettooth/review/templates/review/review.html
index 95b3b04..1549e18 100644
--- a/sweettooth/review/templates/review/review.html
+++ b/sweettooth/review/templates/review/review.html
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+{% load static from staticfiles %}
{% block title %}Review "{{ extension.name }}" - {{ block.super }}{% endblock %}
@@ -130,7 +131,7 @@
{% block head %}
{{ block.super }}
- <link rel="stylesheet" href="/static/css/review.css" />
+ <link rel="stylesheet" href="{% static 'css/review.css' %}" />
<script>
jQuery(function ($) {
require(['review-main'], function(){});
diff --git a/sweettooth/settings.py b/sweettooth/settings.py
index c5b1f4f..51fc823 100644
--- a/sweettooth/settings.py
+++ b/sweettooth/settings.py
@@ -56,6 +56,7 @@ INSTALLED_APPS = (
'sweettooth.auth',
'sweettooth.review',
'sweettooth.errorreports',
+ 'sweettooth.templates',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
@@ -154,6 +155,8 @@ STATICFILES_DIRS = (
os.path.join(SITE_ROOT, 'static'),
)
+STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
+
ACCOUNT_ACTIVATION_DAYS = 5
LOGIN_URL = '/accounts/login/'
@@ -209,3 +212,6 @@ if not DEBUG and not NO_SECURE_SETTINGS:
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_PROXY_SSL_HEADER = ('HTTPS', 'https')
SECURE_SSL_REDIRECT = True
+
+if DEBUG:
+ STATICFILES_STORAGE = None
diff --git a/sweettooth/templates/__init__.py b/sweettooth/templates/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/sweettooth/templates/base.html b/sweettooth/templates/base.html
index b39bba1..d78f405 100644
--- a/sweettooth/templates/base.html
+++ b/sweettooth/templates/base.html
@@ -1,20 +1,23 @@
<!doctype html>
<html>
<head>
+ {% load static from staticfiles %}
<meta charset="utf-8" />
- <link rel="stylesheet" href="/static/css/style.css" />
- <link rel="shortcut icon" href="/static/images/favicon.png" />
+ <link rel="stylesheet" href="{% static 'css/style.css' %}" />
+ <link rel="shortcut icon" href="{% static 'images/favicon.png' %}" />
<link rel="alternate" type="application/rss+xml"
href="{% url 'extensions-rss-feed' %}" title="Latest extensions in GNOME Shell Extensions" />
<title>{% block title %}GNOME Shell Extensions{% endblock %}</title>
<script>
+ {% load static_paths %}
var require = {
baseUrl: '/static/js/',
+ paths: {% static_paths %},
waitSeconds: 30 // It's fails sometimes with default 7 secs
};
</script>
- <script src="/static/js/require.js"></script>
- <script src="/static/js/jquery.js"></script>
+ <script src="{% static 'js/require.js' %}"></script>
+ <script src="{% static 'js/jquery.js' %}"></script>
<script>
jQuery(function($) {
require(['main'], function(){});
@@ -48,7 +51,7 @@
<!-- header -->
<div id="header" class="container_12">
<div id="logo" class="grid_3">
- <h1><a title="GNOME Shell Extensions" href="/"><img
src="/static/images/gnome-logo-extensions.png" alt="GNOME Shell Extensions" /></a></h1>
+ <h1><a title="GNOME Shell Extensions" href="/"><img src="{% static
'images/gnome-logo-extensions.png' %}" alt="GNOME Shell Extensions" /></a></h1>
</div>
<div id="top_bar" class="grid_9">
<div class="left">
diff --git a/sweettooth/templates/templatetags/__init__.py b/sweettooth/templates/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/sweettooth/templates/templatetags/static_paths.py
b/sweettooth/templates/templatetags/static_paths.py
new file mode 100644
index 0000000..7a93f68
--- /dev/null
+++ b/sweettooth/templates/templatetags/static_paths.py
@@ -0,0 +1,36 @@
+"""
+ GNOME Shell Extensions Repository
+ Copyright (C) 2017 Yuri Konotopov <ykonotopov gnome org>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+"""
+
+from django import template
+from django.contrib.staticfiles.storage import staticfiles_storage
+from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
+import json
+
+register = template.Library()
+js_paths = None
+
+
+@register.simple_tag
+def static_paths():
+ global js_paths
+
+ if isinstance(staticfiles_storage, ManifestStaticFilesStorage):
+ if js_paths is None:
+ js_paths = {};
+
+ for base_file, hashed_file in staticfiles_storage.hashed_files.iteritems():
+ if base_file.endswith('.js') and base_file.startswith('js/'):
+ js_paths[base_file[3:-3]] = hashed_file[3:-3]
+
+ js_paths = json.dumps(js_paths)
+
+ return js_paths
+
+ return "{}"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]