aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojciech Polak <polak@gnu.org>2015-03-22 19:27:28 +0100
committerWojciech Polak <polak@gnu.org>2015-03-22 20:31:44 +0100
commit6f7034f53940ea5796c51a498376e03c6b4e16e1 (patch)
tree6d8f77619a398f27b8d1e1ee8c63864ca85622c0
parent4c1aa9d64a61c2ae452fb2e097ada7389721ae7d (diff)
downloadglifestream-6f7034f53940ea5796c51a498376e03c6b4e16e1.tar.gz
glifestream-6f7034f53940ea5796c51a498376e03c6b4e16e1.tar.bz2
Switch to django-pipeline.
-rw-r--r--INSTALL.md7
-rw-r--r--glifestream/bookmarklet/views.py4
-rw-r--r--glifestream/settings-sample.py81
-rw-r--r--glifestream/stream/templatetags/media.py27
-rw-r--r--glifestream/templates/base.html7
-rw-r--r--glifestream/urls.py6
-rw-r--r--requirements.txt1
7 files changed, 87 insertions, 46 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 13d5fdd..159b8ac 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -13,12 +13,15 @@ Optional (but recommended):
- Pillow -- Python Imaging Library
https://pypi.python.org/pypi/Pillow
- workerpool -- a multithreaded job distribution module
https://pypi.python.org/pypi/workerpool
+- django-pipeline -- Pipeline is an asset packaging library for Django
+ https://pypi.python.org/pypi/django-pipeline/
+
- requests-oauthlib -- OAuthlib authentication support for Requests
https://pypi.python.org/pypi/requests-oauthlib
- python-markdown -- a text-to-HTML converter
http://pypi.python.org/pypi/Markdown/
@@ -45,13 +48,13 @@ Installation instructions
2. Copy `settings-sample.py` to `settings.py` and edit your local site
configuration.
3. Run `python manage.py syncdb`
4. Run `python manage.py compilemessages` (if you have 'gettext' installed)
5. Run `./worker.py --init-files-dirs`
-Make sure that `static/thumbs/*` and `static/upload` directories exist
+Make sure that `media/thumbs/*` and `media/upload` directories exist
and all have write permissions by your webserver.
Use `glifestream/worker.py` to automatically fetch external streams
(via cron), list available streams or remove old entries. See
`worker.py --help`.
@@ -77,14 +80,14 @@ Production server with mod_wsgi
Apache configuration:
```
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / /usr/local/django/glifestream/wsgi.py
+Alias /media "/usr/local/django/glifestream/media"
Alias /static "/usr/local/django/glifestream/static"
-Alias /admin_static "/usr/local/django/contrib/admin/media"
<Directory "/usr/local/django/glifestream/">
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript text/css text/html
</IfModule>
AllowOverride All
diff --git a/glifestream/bookmarklet/views.py b/glifestream/bookmarklet/views.py
index f90ab3b..b1bb271 100644
--- a/glifestream/bookmarklet/views.py
+++ b/glifestream/bookmarklet/views.py
@@ -1,7 +1,7 @@
-# gLifestream Copyright (C) 2009, 2010, 2014 Wojciech Polak
+# gLifestream Copyright (C) 2009, 2010, 2014, 2015 Wojciech Polak
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
@@ -12,12 +12,13 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
from django.shortcuts import render_to_response
+from django.views.decorators.cache import never_cache
from glifestream.stream.models import Service
def js(request, **args):
page = {
'base_url': settings.BASE_URL,
@@ -27,12 +28,13 @@ def js(request, **args):
page['base_url'] = page['base_url'].replace('http://', 'https://')
return render_to_response('bookmarklet.js', {'page': page},
content_type='application/javascript')
+@never_cache
def frame(request, **args):
page = {
'base_url': settings.BASE_URL,
}
if request.is_secure():
page['base_url'] = page['base_url'].replace('http://', 'https://')
diff --git a/glifestream/settings-sample.py b/glifestream/settings-sample.py
index 0fc93ae..78cc203 100644
--- a/glifestream/settings-sample.py
+++ b/glifestream/settings-sample.py
@@ -64,41 +64,12 @@ CACHES = {
BASE_URL = 'http://localhost:8000'
# The URL where requests are redirected for login.
# For HTTPS use an absolute URL.
LOGIN_URL = '/login'
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../media'))
-
-# URL that handles the media served from MEDIA_ROOT.
-# Make sure to use a trailing slash.
-# Examples: "http://media.lawrence.com", "http://example.com/media/"
-# Setting an absolute URL is recommended in a production use.
-MEDIA_URL = '/media/'
-
-# Absolute path to the directory static files should be collected to.
-# Don't put anything in this directory yourself; store your static files
-# in apps' "static/" subdirectories and in STATICFILES_DIRS.
-# Example: "/var/www/example.com/static/"
-STATIC_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../static'))
-
-# URL prefix for admin media. Make sure to use a trailing slash.
-# Examples: "http://foo.com/media/", "/media/".
-STATIC_URL = '/static/'
-
-STATICFILES_FINDERS = (
- 'django.contrib.staticfiles.finders.FileSystemFinder',
- 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
-)
-STATICFILES_DIRS = (
- os.path.join(SITE_ROOT, 'static'),
-)
-
-
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'YOUR-SECRET-KEY'
MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -120,19 +91,71 @@ TEMPLATE_DIRS = (
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.staticfiles',
+ 'pipeline',
'glifestream.gauth',
'glifestream.apis',
'glifestream.stream',
'glifestream.usettings',
'glifestream.bookmarklet',
)
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../media'))
+
+# URL that handles the media served from MEDIA_ROOT.
+# Make sure to use a trailing slash.
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+# Setting an absolute URL is recommended in a production use.
+MEDIA_URL = '/media/'
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/var/www/example.com/static/"
+STATIC_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../static'))
+
+# URL prefix for admin media. Make sure to use a trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+STATIC_URL = '/static/'
+
+STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+ 'pipeline.finders.CachedFileFinder',
+ 'pipeline.finders.PipelineFinder',
+)
+STATICFILES_DIRS = (
+ os.path.join(SITE_ROOT, 'static'),
+)
+
+PIPELINE_DISABLE_WRAPPER = True
+PIPELINE_JS_COMPRESSOR = None
+PIPELINE_CSS_COMPRESSOR = None
+
+PIPELINE_JS = {
+ 'main': {
+ 'source_filenames': (
+ 'js/jquery.js',
+ 'js/glifestream.js',
+ ),
+ 'output_filename': 'js/main.js',
+ },
+ 'tinymce': {
+ 'source_filenames': (
+ 'js/tinymce/tinymce.min.js',
+ ),
+ 'output_filename': 'js/tinymce.js',
+ }
+}
+
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
diff --git a/glifestream/stream/templatetags/media.py b/glifestream/stream/templatetags/media.py
index 4af3ba4..be77e56 100644
--- a/glifestream/stream/templatetags/media.py
+++ b/glifestream/stream/templatetags/media.py
@@ -1,7 +1,7 @@
-# gLifestream Copyright (C) 2009, 2010, 2013 Wojciech Polak
+# gLifestream Copyright (C) 2009, 2010, 2013, 2015 Wojciech Polak
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
@@ -28,32 +28,47 @@ class MediaUrl (template.Node):
url = settings.MEDIA_URL
if 'is_secure' in ctx and ctx['is_secure']:
url = url.replace('http://', 'https://')
return url
+class StaticUrl (template.Node):
+
+ def render(self, ctx):
+ url = settings.STATIC_URL
+ if 'is_secure' in ctx and ctx['is_secure']:
+ url = url.replace('http://', 'https://')
+ return url
+
+
@register.tag
-def static(parser, token):
+def media(parser, token):
"""Return the string contained in the setting MEDIA_URL."""
return MediaUrl()
-class MediaUrlHash (template.Node):
+@register.tag
+def static(parser, token):
+ """Return the string contained in the setting STATIC_URL."""
+ return StaticUrl()
+
+
+class StaticUrlHash (template.Node):
def __init__(self, path):
self.path = path
self.hash = None
try:
- f = open(os.path.join(settings.MEDIA_ROOT, path))
+ f = open(os.path.join(settings.STATIC_ROOT, path))
self.hash = hashlib.md5(f.read()).hexdigest()[:5]
f.close()
except:
pass
def render(self, ctx):
- url = settings.MEDIA_URL
+ url = settings.STATIC_URL
if 'is_secure' in ctx and ctx['is_secure']:
url = url.replace('http://', 'https://')
url += self.path
if self.hash:
url += '?v=' + self.hash
return url
@@ -64,7 +79,7 @@ def static_hash(parser, token):
"""Return a static URL for the given relative static file path."""
try:
tag_name, path = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError(
"%r tag requires a single argument" % token.contents.split()[0])
- return MediaUrlHash(path)
+ return StaticUrlHash(path)
diff --git a/glifestream/templates/base.html b/glifestream/templates/base.html
index 8ddfdc7..5ba9105 100644
--- a/glifestream/templates/base.html
+++ b/glifestream/templates/base.html
@@ -1,7 +1,7 @@
-{% load i18n static %}{% load url from future %}{% load firstof from future %}<!DOCTYPE html>
+{% load i18n media static pipeline %}{% load url from future %}{% load firstof from future %}<!DOCTYPE html>
<html>
<head>
<title>{% firstof page.title "Lifestream" %}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">{% if not page.exactentry and page.description %}
@@ -9,15 +9,14 @@
<meta name="generator" content="gLifestream">
<meta name="robots" content="{{ page.robots }}">
<link rel="shortcut icon" href="{{ page.favicon }}">{% if page.canonical_link %}
<link rel="canonical" href="{{ page.canonical_link }}">{% endif %}
<link rel="alternate" type="application/atom+xml" title="Webfeed" href="{% if page.exactentry %}{% url 'index' %}{% endif %}?format=atom">
<link rel="stylesheet" type="text/css" href="{% get_static_prefix %}themes/{% firstof page.theme "default" %}/style.css">
- <script type="text/javascript" src="{% static "js/jquery.js" %}"></script>
- <script type="text/javascript" src="{% static "js/glifestream.js" %}"></script>{% if authed %}
- <script type="text/javascript" src="{% static "js/tinymce/tinymce.min.js" %}"></script>{% endif %}
+ {% javascript 'main' %}{% if authed %}
+ <script type="text/javascript" src="{% static_hash js/tinymce/tinymce.min.js %}"></script>{% endif %}
</head>
<body>
<div id="main">
<header id="head">
diff --git a/glifestream/urls.py b/glifestream/urls.py
index 39788d2..958fafc 100644
--- a/glifestream/urls.py
+++ b/glifestream/urls.py
@@ -1,7 +1,7 @@
-# gLifestream Copyright (C) 2009, 2010, 2013, 2014 Wojciech Polak
+# gLifestream Copyright (C) 2009, 2010, 2013, 2014, 2015 Wojciech Polak
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
@@ -72,10 +72,8 @@ urlpatterns = patterns(
(r'^admin/', include(admin.site.urls)),
)
urlpatterns += patterns(
'',
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
- {'document_root': settings.MEDIA_ROOT}),
- (r'^static/(?P<path>.*)$', 'django.views.static.serve',
- {'document_root': settings.STATIC_ROOT}),
+ {'document_root': settings.MEDIA_ROOT})
)
diff --git a/requirements.txt b/requirements.txt
index 62fed94..ea46429 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,7 +1,8 @@
Django >=1.7.6
+django-pipeline >=1.4
mysqlclient >=1.3.4
feedparser
Pillow >=2.2.1,<2.99
workerpool
python-memcached
python-openid >=2.2.5

Return to:

Send suggestions and report system problems to the System administrator.