diff options
-rw-r--r-- | INSTALL.md | 7 | ||||
-rw-r--r-- | glifestream/bookmarklet/views.py | 4 | ||||
-rw-r--r-- | glifestream/settings-sample.py | 81 | ||||
-rw-r--r-- | glifestream/stream/templatetags/media.py | 27 | ||||
-rw-r--r-- | glifestream/templates/base.html | 7 | ||||
-rw-r--r-- | glifestream/urls.py | 6 | ||||
-rw-r--r-- | requirements.txt | 1 |
7 files changed, 87 insertions, 46 deletions
@@ -16,6 +16,9 @@ Optional (but recommended): - 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 @@ -48,7 +51,7 @@ Installation instructions 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 @@ -80,8 +83,8 @@ 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> 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,4 +1,4 @@ -# 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 @@ -15,6 +15,7 @@ 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 @@ -30,6 +31,7 @@ def js(request, **args): content_type='application/javascript') +@never_cache def frame(request, **args): page = { 'base_url': settings.BASE_URL, 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 @@ -67,35 +67,6 @@ BASE_URL = 'http://localhost:8000' # 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' @@ -123,6 +94,7 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib.staticfiles', + 'pipeline', 'glifestream.gauth', 'glifestream.apis', 'glifestream.stream', @@ -130,6 +102,57 @@ INSTALLED_APPS = ( '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. 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,4 +1,4 @@ -# 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 @@ -31,26 +31,41 @@ class MediaUrl (template.Node): 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 @@ -67,4 +82,4 @@ def static_hash(parser, token): 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,4 +1,4 @@ -{% 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> @@ -12,9 +12,8 @@ <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> diff --git a/glifestream/urls.py b/glifestream/urls.py index 39788d2..958fafc 100644 --- a/glifestream/urls.py +++ b/glifestream/urls.py @@ -1,4 +1,4 @@ -# 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 @@ -75,7 +75,5 @@ urlpatterns = patterns( 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,4 +1,5 @@ Django >=1.7.6 +django-pipeline >=1.4 mysqlclient >=1.3.4 feedparser Pillow >=2.2.1,<2.99 |