Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add django 1.8 support #165

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ env:
- MODULES="Django>=1.5,<1.6"
- MODULES="Django>=1.6,<1.7"
- MODULES="Django>=1.7,<1.8"
- MODULES="git+https://github.com/django/django.git@stable/1.8.x#egg=django"

# Django 1.4 did not support Python 3.
matrix:
exclude:
- python: "3.2"
env: MODULES="Django>=1.4,<1.5"
allow_failures:
- env: MODULES="git+https://github.com/django/django.git@stable/1.8.x#egg=django"

install:
- sudo rm /etc/apt/sources.list.d/ubuntugis-stable-source.list
- sudo apt-get update -qq
- sudo apt-get install -qq python-gdal gdal-bin binutils
- ln -s /usr/lib/python2.7/dist-packages/osgeo ~/virtualenv/python2.7/lib/python2.7/site-packages/
- ln -s /usr/lib/python2.7/dist-packages/GDAL-1.7.3.egg-info ~/virtualenv/python2.7/lib/python2.7/site-packages/
- pip install $MODULES --use-mirrors
- pip install -r requirements.txt --use-mirrors
- sudo apt-get install -qq gdal-bin binutils
- pip install $MODULES
- CFLAGS="-O0" pip install -e .
# The below is for Django 1.4 compatibility. If you don't need that, you could
# just do the before_script step commented out below.
- createdb -E UTF8 template_postgis &&
Expand Down
16 changes: 16 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
v1.3, 2015-02-12
* Ubuntu Trusty Tahr support. #156
* Django 1.8 support. #165
* Stream JSON output, and HTML lists of areas, to use much less memory on
very large responses. #164
* Italy country app, thanks Guglielmo Celata. #147 #153
* South Africa country app, thanks Mark Longair. #155
* Add setting for whether this installation uses postcodes.
* Add HTML version of /generations endpoint.
* Bugfixes:
* Fix nginx example config for static file serving. #162
* Catch invalid SRID exceptions, and return 400. #157
* Cache 0, not '0', to avoid a LocMem incr error.
* Move country specific examples to country app templates.
* Improve handling of bad /areas/ URLs, such as </areas/,123>.

v1.2.1, 2014-12-16
* Fix bug when importing non-ASCII named geometry data.

Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include LICENSE.txt README.rst requirements.txt
include LICENSE.txt README.rst
recursive-include project *.py
recursive-include mapit *.html *.json *.sql
recursive-include mapit/static *
Expand Down
9 changes: 3 additions & 6 deletions conf/packages
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ postgresql-9.1-postgis | postgresql-8.4-postgis | postgresql-8.3-postgis
libgdal1 | libgdal1-1.6.0 | libgdal1-1.5.0
memcached
python-virtualenv
ruby-sass
libapache2-mod-wsgi

python-django
python-django-south
python-psycopg2
python-shapely
python-yaml
python-memcache
python-gdal

libapache2-mod-wsgi
ruby-sass
python-shapely
3 changes: 1 addition & 2 deletions conf/packages.debian-squeeze
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ postgresql-8.4-postgis
libgdal1-1.6.0
memcached
python-virtualenv
libhaml-ruby

python-django
python-django-south
python-psycopg2
python-shapely
python-yaml
Expand Down
2 changes: 0 additions & 2 deletions conf/packages.debian-wheezy
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ memcached
python-virtualenv
ruby-sass

python-django
python-django-south
python-psycopg2
python-shapely
python-yaml
Expand Down
2 changes: 0 additions & 2 deletions conf/packages.ubuntu-precise
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ memcached
python-virtualenv
ruby-sass

python-django
python-django-south
python-psycopg2
python-shapely
python-yaml
Expand Down
2 changes: 0 additions & 2 deletions conf/packages.ubuntu-trusty
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ memcached
python-virtualenv
ruby-sass

python-django
python-django-south
python-psycopg2
python-shapely
python-yaml
Expand Down
2 changes: 1 addition & 1 deletion conf/post_deploy_actions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ source $virtualenv_activate
curl -L -s https://raw.github.com/mysociety/commonlib/master/bin/get_pip.bash | bash

# Install all the packages
pip install -r requirements.txt
pip install -e .

# make sure that there is no old code (the .py files may have been git deleted)
find . -name '*.pyc' -delete
Expand Down
16 changes: 14 additions & 2 deletions mapit/djangopatch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import django
import inspect

# Django 1.8 changed how templates operate.
if django.get_version() >= '1.8':
from django.template.loader import render_to_string
else:
from django.template import loader, RequestContext
def render_to_string(template_name, context=None, request=None):
context_instance = RequestContext(request) if request else None
return loader.render_to_string(template_name, context, context_instance)

# Django 1.6 renamed Manager's get_query_set to get_queryset, and the old
# function will be removed entirely in 1.8. We work back to 1.4, so use a
# metaclass to not worry about it.
if django.VERSION < (1, 6):
if django.get_version() < '1.6':
class GetQuerySetMetaclass(type):
def __new__(cls, name, bases, attrs):
new_class = super(GetQuerySetMetaclass, cls).__new__(cls, name, bases, attrs)
Expand All @@ -21,9 +30,12 @@ def __new__(cls, name, bases, attrs):
setattr(base, old_method_name, new_method)

return new_class
else:
elif django.get_version() < '1.8':
# Nothing to do, make an empty metaclass
from django.db.models.manager import RenameManagerMethods

class GetQuerySetMetaclass(RenameManagerMethods):
pass
else:
class GetQuerySetMetaclass(type):
pass
5 changes: 2 additions & 3 deletions mapit/middleware/view_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
# and output it as either HTML or JSON appropriately

from django import http
from django.template import RequestContext
from django.template.loader import render_to_string
from mapit.shortcuts import output_json
from mapit.djangopatch import render_to_string


class ViewException(Exception):
Expand All @@ -27,6 +26,6 @@ def process_exception(self, request, exception):
return response_type(render_to_string(
'mapit/%s.html' % code,
{'error': message},
context_instance=RequestContext(request)
request=request
))
return output_json({'error': message}, code=code)
20 changes: 9 additions & 11 deletions mapit/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
from django.db import connection
from django.conf import settings
from django.shortcuts import get_object_or_404 as orig_get_object_or_404
from django.shortcuts import render_to_response
from django.template import loader, RequestContext, Context
from django.template import loader
from django.utils.six.moves import map
from django.utils.encoding import smart_str
from django.utils.translation import ugettext as _

from mapit.iterables import defaultiter
from mapit.djangopatch import render_to_string

# In 1.8, we no longer need to pass a Context() so stub it out
if django.get_version() < '1.8':
from django.template import Context
else:
Context = lambda x: x

from django.core.serializers.json import DjangoJSONEncoder
# Assuming at least python 2.6, in Django < 1.6, the above class is either a
Expand All @@ -37,18 +43,10 @@ def default(self, o):
return super(GEOS_JSONEncoder, self).default(o)


def render(request, template_name, context=None):
if context is None:
context = {}
return render_to_response(
template_name, context, context_instance=RequestContext(request)
)


def output_html(request, title, areas, **kwargs):
kwargs['json_url'] = request.get_full_path().replace('.html', '')
kwargs['title'] = title
tpl = loader.render_to_string('mapit/data.html', kwargs, context_instance=RequestContext(request))
tpl = render_to_string('mapit/data.html', kwargs, request=request)
wraps = tpl.split('!!!DATA!!!')

indent_areas = kwargs.get('indent_areas', False)
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/api/area.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load url from future %}
{% load url from compat %}
<section id="api-by_area_id">
<h3><em>lookup</em> by area</h3>
<dl>
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/api/areas.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load url from future %}
{% load url from compat %}
<section id="api-multiple_areas">
<h3><em>lookup</em> multiple areas</h3>
<dl>
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/api/generations.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n %}
{% load url from future %}
{% load url from compat %}

<section id="api-generations">
<h3>Generations</h3>
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/api/point.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load url from future %}
{% load url from compat %}
<section id="api-by_point">
<h3><em>lookup by</em> point</h3>
<dl>
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/api/postcode.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load url from future %}
{% load url from compat %}
<section id="api-by_postcode">
<h3><em>lookup by</em> postcode</h3>
<dl>
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/area.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "mapit/base.html" %}
{% load url from future %}
{% load url from compat %}

{% block title %}{{ area.name }}{% endblock title %}

Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/areas_item.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load url from future %}
{% load url from compat %}
<li{% if indent_areas %} class="{{ area.css_indent_class }}"{% endif %}>
<h3><a href="{% url "mapit_index" %}area/{{ area.id }}.html">{{ area.name }}</a></h3>
<p>ID {{ area.id }}, {{ area.type.description }}
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load url from future %}
{% load url from compat %}
{% load static from staticfiles %}
<!DOCTYPE HTML>
<html lang="en-gb">
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/example-postcode.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "mapit/base.html" %}
{% load url from future %}
{% load url from compat %}

{% block title %}Example postcode in {{ area.name }}{% endblock title %}

Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/generations.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "mapit/base.html" %}
{% load i18n %}
{% load url from future %}
{% load url from compat %}

{% block title %}{% trans 'Generations' %}{% endblock title %}

Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "mapit/base.html" %}
{% load url from future %}
{% load url from compat %}
{% load static from staticfiles %}

{% block fulltitle %}
Expand Down
2 changes: 1 addition & 1 deletion mapit/templates/mapit/postcode.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "mapit/base.html" %}
{% load url from future %}
{% load url from compat %}

{% block title %}Results for &ldquo;{{ postcode.postcode }}&rdquo;{% endblock title %}

Expand Down
Empty file added mapit/templatetags/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions mapit/templatetags/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import django
from django.template import Library

if django.get_version() >= '1.5':
from django.template.defaulttags import url as django_url
else:
from django.templatetags.future import url as django_url

register = Library()

@register.tag
def url(parser, token):
return django_url(parser, token)
Loading