Permalink
Browse files

Drop support for Django 1.3.

Move to Django 1.4+ file layout, remove any old-Django workarounds,
tidy up settings.
  • Loading branch information...
1 parent bae42a0 commit a0e3ab5530638b106e6959b1786b98850bb2d3d4 @dracos dracos committed Oct 9, 2013
View
@@ -8,7 +8,6 @@ notifications:
language: python
env:
- - MODULES="Django==1.3.7 psycopg2==2.4.1"
- MODULES="Django>=1.4,<1.5"
- MODULES="Django>=1.5,<1.6"
- MODULES="git+https://github.com/django/django.git@stable/1.6.x#egg=django"
@@ -27,4 +26,4 @@ install:
- sudo /etc/init.d/postgresql reload
- "echo -e 'MAPIT_DB_NAME: template_postgis\nMAPIT_DB_USER: postgres\nDJANGO_SECRET_KEY: secret' > conf/general.yml"
script:
- - python -Wall project/manage.py test mapit
+ - python -Wall manage.py test mapit
@@ -36,8 +36,8 @@ find . -name '*.pyc' -delete
bin/mapit_make_css
# get the database up to speed
-project/manage.py syncdb --noinput
-project/manage.py migrate
+python manage.py syncdb --noinput
+python manage.py migrate
# gather all the static files in one place
-project/manage.py collectstatic --noinput
+python manage.py collectstatic --noinput
@@ -3,7 +3,7 @@
import sys
if __name__ == "__main__":
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
from django.core.management import execute_from_command_line
View
@@ -1,44 +0,0 @@
-# Django's gzip middleware, patched to alter the ETag as it should do.
-
-import re
-
-from django.utils.text import compress_string
-from django.utils.cache import patch_vary_headers
-
-re_accepts_gzip = re.compile(r'\bgzip\b')
-
-class GZipMiddleware(object):
- """
- This middleware compresses content if the browser allows gzip compression.
- It sets the Vary header accordingly, so that caches will base their storage
- on the Accept-Encoding header.
- """
- def process_response(self, request, response):
- # It's not worth compressing non-OK or really short responses.
- if response.status_code != 200 or len(response.content) < 200:
- return response
-
- patch_vary_headers(response, ('Accept-Encoding',))
-
- # Avoid gzipping if we've already got a content-encoding.
- if response.has_header('Content-Encoding'):
- return response
-
- # MSIE have issues with gzipped respones of various content types.
- if "msie" in request.META.get('HTTP_USER_AGENT', '').lower():
- ctype = response.get('Content-Type', '').lower()
- if not ctype.startswith("text/") or "javascript" in ctype:
- return response
-
- ae = request.META.get('HTTP_ACCEPT_ENCODING', '')
- if not re_accepts_gzip.search(ae):
- return response
-
- # Added to Django's function
- if response.has_header('ETag'):
- response['ETag'] = re.sub('"$', ';gzip"', response['ETag'])
-
- response.content = compress_string(response.content)
- response['Content-Encoding'] = 'gzip'
- response['Content-Length'] = str(len(response.content))
- return response
View
@@ -3,16 +3,11 @@
from django.test import TestCase
from django.contrib.gis.geos import Polygon
-import settings
-
from mapit.models import Type, Area, Geometry, Generation
class AreaViewsTest(TestCase):
@classmethod
def setUpClass(self):
- self.old_srid = settings.MAPIT_AREA_SRID
- settings.MAPIT_AREA_SRID = 4326
-
self.generation = Generation.objects.create(
active=True,
description="Test generation",
@@ -81,7 +76,3 @@ def test_areas_by_point(self):
def test_front_page(self):
response = self.client.get('/')
-
- @classmethod
- def tearDownClass(self):
- settings.MAPIT_AREA_SRID = self.old_srid
View
@@ -1,7 +1,4 @@
-try:
- from django.conf.urls import patterns
-except:
- from django.conf.urls.defaults import patterns, handler404
+from django.conf.urls import patterns
from mapit.shortcuts import render
View
@@ -3,23 +3,18 @@
import yaml
import django
-# Make sure the application in this repository is on the path
-package_dir = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
-path = os.path.abspath( os.path.join( package_dir, '..' ) )
-
-# We don't want two copies of this on the path, so remove it if it's
-# already there.
-while path in sys.path:
- sys.path.remove(path)
-
-sys.path.insert(0, path)
+# Path to here is something like
+# /data/vhost/<vhost>/<repo>/<project_name>/settings.py
+PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
+PROJECT_ROOT = os.path.abspath(os.path.join(PROJECT_DIR, '..'))
+PARENT_DIR = os.path.abspath(os.path.join(PROJECT_ROOT, '..'))
# The mySociety deployment system works by having a conf directory at the root
# of the repo, containing a general.yml file of options. Use that file if
# present. Obviously you can just edit any part of this file, it is a normal
# Django settings.py file.
try:
- config = yaml.load( open(os.path.normpath(package_dir + "/../conf/general.yml"), 'r') )
+ config = yaml.load( open(os.path.join(PROJECT_ROOT, 'conf', 'general.yml'), 'r') )
except:
config = {}
@@ -46,13 +41,22 @@
# (Note that even if DEBUG is true, output_json still sets a
# Cache-Control header with max-age of 28 days.)
if DEBUG:
- CACHE_BACKEND = 'dummy://'
+ CACHES = {
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
+ }
+ }
CACHE_MIDDLEWARE_SECONDS = 0
else:
- CACHE_BACKEND = 'memcached://127.0.0.1:11211/?timeout=86400'
+ CACHES = {
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+ 'LOCATION': '127.0.0.1:11211',
+ 'TIMEOUT': 86400,
+ }
+ }
CACHE_MIDDLEWARE_SECONDS = 86400
CACHE_MIDDLEWARE_KEY_PREFIX = config.get('MAPIT_DB_NAME')
- CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
if config.get('BUGS_EMAIL'):
SERVER_EMAIL = config['BUGS_EMAIL']
@@ -75,6 +79,8 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = config.get('DJANGO_SECRET_KEY', '')
+ALLOWED_HOSTS = ['*']
+
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
@@ -98,17 +104,52 @@
# to load the internationalization machinery.
USE_I18N = True
-STATIC_URL = '/static/'
-STATIC_ROOT = os.path.join( path, '..', 'collected_static' )
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale.
+USE_L10N = True
+
+# If you set this to False, Django will not use timezone-aware datetimes.
+USE_TZ = False
-# No uploaded media
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
+# 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.join( PARENT_DIR, 'collected_static' )
+
+# URL prefix for static files.
+# Example: "http://example.com/static/", "http://static.example.com/"
+STATIC_URL = '/static/'
+
+# Additional locations of static files
+STATICFILES_DIRS = (
+ # Put strings here, like "/home/html/static" or "C:/www/django/static".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
# Needs adapting to new class version
+ #'django.template.loaders.app_directories.Loader',
'mapit.loader.load_template_source',
)
@@ -119,7 +160,7 @@
USE_ETAGS = False
MIDDLEWARE_CLASSES = (
- 'mapit.middleware.gzip.GZipMiddleware' if django.get_version() < '1.4' else 'django.middleware.gzip.GZipMiddleware',
+ 'django.middleware.gzip.GZipMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
@@ -130,12 +171,16 @@
'mapit.middleware.ViewExceptionMiddleware',
)
-ROOT_URLCONF = 'urls'
+ROOT_URLCONF = 'project.urls'
-# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
-# Always use forward slashes, even on Windows.
-# Don't forget to use absolute paths, not relative paths.
-TEMPLATE_DIRS = ()
+# Python dotted path to the WSGI application used by Django's runserver.
+WSGI_APPLICATION = 'project.wsgi.application'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
View
@@ -1,8 +1,4 @@
-try:
- from django.conf.urls import patterns, include
-except:
- from django.conf.urls.defaults import patterns, include, handler404
-
+from django.conf.urls import patterns, include
from django.contrib import admin
admin.autodiscover()
View
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+import os, sys
+
+file_dir = os.path.realpath(os.path.dirname(__file__))
+sys.path.insert(0, os.path.normpath(os.path.join(file_dir, '..')))
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
+
+from django.core.wsgi import get_wsgi_application
+application = get_wsgi_application()
File renamed without changes.
View
@@ -1,5 +1,5 @@
python-memcached
-Django
+Django>=1.4
PyYAML
psycopg2
BeautifulSoup
View
@@ -1,24 +0,0 @@
-#!/usr/bin/python
-
-import os, sys
-
-file_dir = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
-paths = (
- os.path.normpath(os.path.join(file_dir)),
- os.path.normpath(os.path.join(file_dir, '..', 'project'))
-)
-for path in paths:
- if path not in sys.path:
- sys.path.append(path)
-
-import settings
-
-if settings.DEBUG:
- import wsgi_monitor
- wsgi_monitor.start(interval=1.0)
-
-os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
-
-import django.core.handlers.wsgi
-application = django.core.handlers.wsgi.WSGIHandler()
-

0 comments on commit a0e3ab5

Please sign in to comment.