Python 2.6 compatibility - fixes #156

pull/208/head
Matt Westcott 2014-04-24 16:41:58 +01:00
rodzic aa09c442a2
commit 41c5c1c457
18 zmienionych plików z 71 dodań i 24 usunięć

Wyświetl plik

@ -13,7 +13,7 @@ services:
install: install:
- python setup.py install - python setup.py install
- pip install psycopg2 pyelasticsearch elasticutils==0.8.2 wand - pip install psycopg2 pyelasticsearch elasticutils==0.8.2 wand
- pip install coveralls - pip install coveralls unittest2
# Pre-test configuration # Pre-test configuration
before_script: before_script:
- psql -c 'create database wagtaildemo;' -U postgres - psql -c 'create database wagtaildemo;' -U postgres

Wyświetl plik

@ -1,5 +1,7 @@
# Requirements essential for developing wagtail (not needed to run it) # Requirements essential for developing wagtail (not needed to run it)
unittest2==0.5.1
# For coverage and PEP8 linting # For coverage and PEP8 linting
coverage==3.7.1 coverage==3.7.1
flake8==2.1.0 flake8==2.1.0

32
tox.ini
Wyświetl plik

@ -1,26 +1,46 @@
[deps]
dj16=
Django>=1.6,<1.7
pyelasticsearch==0.6.1
elasticutils==0.8.2
unittest2
[tox] [tox]
envlist = envlist =
py26-dj16-postgres,
py26-dj16-sqlite,
py27-dj16-postgres, py27-dj16-postgres,
py27-dj16-sqlite py27-dj16-sqlite
[testenv] [testenv]
commands=./runtests.py commands=./runtests.py
[testenv:py26-dj16-postgres]
basepython=python2.6
deps =
{[deps]dj16}
psycopg2==2.5.2
setenv =
DATABASE_ENGINE=django.db.backends.postgresql_psycopg2
[testenv:py26-dj16-sqlite]
basepython=python2.6
deps =
{[deps]dj16}
setenv =
DATABASE_ENGINE=django.db.backends.sqlite3
[testenv:py27-dj16-postgres] [testenv:py27-dj16-postgres]
basepython=python2.7 basepython=python2.7
deps = deps =
Django>=1.6,<1.7 {[deps]dj16}
psycopg2==2.5.2 psycopg2==2.5.2
pyelasticsearch==0.6.1
elasticutils==0.8.2
setenv = setenv =
DATABASE_ENGINE=django.db.backends.postgresql_psycopg2 DATABASE_ENGINE=django.db.backends.postgresql_psycopg2
[testenv:py27-dj16-sqlite] [testenv:py27-dj16-sqlite]
basepython=python2.7 basepython=python2.7
deps = deps =
Django>=1.6,<1.7 {[deps]dj16}
pyelasticsearch==0.6.1
elasticutils==0.8.2
setenv = setenv =
DATABASE_ENGINE=django.db.backends.sqlite3 DATABASE_ENGINE=django.db.backends.sqlite3

Wyświetl plik

@ -12,7 +12,7 @@ class SearchForm(forms.Form):
if _placeholder is not None: if _placeholder is not None:
placeholder = _placeholder placeholder = _placeholder
else: else:
placeholder = 'Search {}'.format(placeholder_suffix) placeholder = 'Search {0}'.format(placeholder_suffix)
self.fields['q'].widget.attrs = {'placeholder': placeholder} self.fields['q'].widget.attrs = {'placeholder': placeholder}
q = forms.CharField(label=_("Search term"), widget=forms.TextInput()) q = forms.CharField(label=_("Search term"), widget=forms.TextInput())

Wyświetl plik

@ -1,5 +1,9 @@
from django.conf import settings from django.conf import settings
from django.utils.importlib import import_module try:
from importlib import import_module
except ImportError:
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
from django.utils.importlib import import_module
_hooks = {} _hooks = {}

Wyświetl plik

@ -1,5 +1,5 @@
from django.test import TestCase from django.test import TestCase
import unittest import unittest2 as unittest
from wagtail.tests.models import SimplePage, EventPage from wagtail.tests.models import SimplePage, EventPage
from wagtail.tests.utils import login from wagtail.tests.utils import login
from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.models import Page

Wyświetl plik

@ -1,5 +1,11 @@
import sys import sys
from importlib import import_module
try:
from importlib import import_module
except ImportError:
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
from django.utils.importlib import import_module
from django.conf import settings from django.conf import settings
from datetime import datetime from datetime import datetime
from django.utils import six from django.utils import six

Wyświetl plik

@ -2,7 +2,12 @@
# Based on the Django cache framework and wagtailsearch # Based on the Django cache framework and wagtailsearch
# https://github.com/django/django/blob/5d263dee304fdaf95e18d2f0619d6925984a7f02/django/core/cache/__init__.py # https://github.com/django/django/blob/5d263dee304fdaf95e18d2f0619d6925984a7f02/django/core/cache/__init__.py
from importlib import import_module try:
from importlib import import_module
except ImportError:
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
from django.utils.importlib import import_module
from django.utils import six from django.utils import six
import sys import sys
from django.conf import settings from django.conf import settings

Wyświetl plik

@ -1,7 +1,12 @@
from django.conf import settings from django.conf import settings
from django.utils.importlib import import_module
from django.utils.html import escape from django.utils.html import escape
try:
from importlib import import_module
except ImportError:
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
from django.utils.importlib import import_module
class Format(object): class Format(object):
def __init__(self, name, label, classnames, filter_spec): def __init__(self, name, label, classnames, filter_spec):

Wyświetl plik

@ -4,7 +4,7 @@ from django.contrib.auth.models import User, Group, Permission
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
import unittest import unittest2 as unittest
from wagtail.tests.utils import login from wagtail.tests.utils import login
from wagtail.wagtailimages.models import get_image_model from wagtail.wagtailimages.models import get_image_model

Wyświetl plik

@ -109,7 +109,7 @@ def add(request):
theredirect.site = request.site theredirect.site = request.site
theredirect.save() theredirect.save()
messages.success(request, _("Redirect '{0} added.").format(theredirect.title)) messages.success(request, _("Redirect '{0}' added.").format(theredirect.title))
return redirect('wagtailredirects_index') return redirect('wagtailredirects_index')
else: else:
messages.error(request, _("The redirect could not be created due to errors.")) messages.error(request, _("The redirect could not be created due to errors."))

Wyświetl plik

@ -2,7 +2,12 @@
# Based on the Django cache framework # Based on the Django cache framework
# https://github.com/django/django/blob/5d263dee304fdaf95e18d2f0619d6925984a7f02/django/core/cache/__init__.py # https://github.com/django/django/blob/5d263dee304fdaf95e18d2f0619d6925984a7f02/django/core/cache/__init__.py
from importlib import import_module try:
from importlib import import_module
except ImportError:
# for Python 2.6, fall back on django.utils.importlib (deprecated as of Django 1.7)
from django.utils.importlib import import_module
from django.utils import six from django.utils import six
import sys import sys
from django.conf import settings from django.conf import settings

Wyświetl plik

@ -37,7 +37,7 @@ class ElasticSearchResults(object):
results = results.prefetch_related(prefetch) results = results.prefetch_related(prefetch)
# Put results into a dictionary (using primary key as the key) # Put results into a dictionary (using primary key as the key)
results_dict = {str(result.pk): result for result in results} results_dict = dict((str(result.pk), result) for result in results)
# Build new list with items in the correct order # Build new list with items in the correct order
results_sorted = [results_dict[str(pk)] for pk in pk_list if str(pk) in results_dict] results_sorted = [results_dict[str(pk)] for pk in pk_list if str(pk) in results_dict]

Wyświetl plik

@ -40,7 +40,7 @@ class Indexed(object):
if isinstance(indexed_fields, basestring): if isinstance(indexed_fields, basestring):
indexed_fields = [indexed_fields] indexed_fields = [indexed_fields]
if isinstance(indexed_fields, list): if isinstance(indexed_fields, list):
indexed_fields = {field: dict(type="string") for field in indexed_fields} indexed_fields = dict((field, dict(type="string")) for field in indexed_fields)
if not isinstance(indexed_fields, dict): if not isinstance(indexed_fields, dict):
raise ValueError() raise ValueError()

Wyświetl plik

@ -2,7 +2,7 @@ from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
from django.core import management from django.core import management
import unittest import unittest2 as unittest
from wagtail.wagtailsearch import models, get_search_backend from wagtail.wagtailsearch import models, get_search_backend
from wagtail.wagtailsearch.backends.db import DBSearch from wagtail.wagtailsearch.backends.db import DBSearch
from wagtail.wagtailsearch.backends import InvalidSearchBackendError from wagtail.wagtailsearch.backends import InvalidSearchBackendError

Wyświetl plik

@ -3,7 +3,7 @@ from django.core import management
from wagtail.wagtailsearch import models from wagtail.wagtailsearch import models
from wagtail.tests.utils import login from wagtail.tests.utils import login
from StringIO import StringIO from StringIO import StringIO
import unittest import unittest2 as unittest
class TestHitCounter(TestCase): class TestHitCounter(TestCase):

Wyświetl plik

@ -73,11 +73,11 @@ def search(
for result in search_results: for result in search_results:
result_specific = result.specific result_specific = result.specific
search_results_json.append({ search_results_json.append(dict(
attr: getattr(result_specific, attr) (attr, getattr(result_specific, attr))
for attr in json_attrs for attr in json_attrs
if hasattr(result_specific, attr) if hasattr(result_specific, attr)
}) ))
return HttpResponse(json.dumps(search_results_json)) return HttpResponse(json.dumps(search_results_json))
else: else:

Wyświetl plik

@ -5,7 +5,7 @@ when you run "manage.py test".
Replace this with more appropriate tests for your application. Replace this with more appropriate tests for your application.
""" """
import unittest import unittest2 as unittest
from django.test import TestCase from django.test import TestCase