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

Django 1.9 compatibility issues #507

Merged
merged 7 commits into from
Jun 16, 2017
Merged
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
31 changes: 21 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
notifications:
email: false

sudo: false

language: python

services:
Expand All @@ -11,19 +13,28 @@ env:
- CFLAGS="-O0"
matrix:
- TOXENV=flake8
- TOXENV=py-27-1.8
- TOXENV=py-27-1.9
- TOXENV=py-34-1.8
- TOXENV=py-34-1.9
- TOXENV=py27-1.8
- TOXENV=py27-1.10
- TOXENV=py27-1.11
- TOXENV=py34-1.8
- TOXENV=py34-1.10
- TOXENV=py34-1.11

addons:
firefox: latest
apt:
packages:
- ffmpeg
- libavcodec-extra-53
- xvfb

matrix:
allow_failures:
- env: TOXENV=py-27-1.9
- env: TOXENV=py-34-1.9
before_install:
- wget https://github.com/mozilla/geckodriver/releases/download/v0.17.0/geckodriver-v0.17.0-linux64.tar.gz
- mkdir geckodriver
- tar -xzf geckodriver-v0.17.0-linux64.tar.gz -C geckodriver
- export PATH=$PATH:$PWD/geckodriver

install:
- 'if [ $TOXENV != "flake8" ]; then sudo apt-get update -qq; fi'
- 'if [ $TOXENV != "flake8" ]; then sudo apt-get install -qq ffmpeg libavcodec-extra-53 iceweasel xvfb; fi'
- pip install tox

before_script:
Expand Down
37 changes: 22 additions & 15 deletions example_project/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

import os
import sys
from django.conf import global_settings

from .paths import * # noqa

DEBUG = True
TEMPLATE_DEBUG = DEBUG
try:
import debug_toolbar # noqa
DEBUG_TOOLBAR = True
Expand All @@ -33,7 +31,7 @@
}
}

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']

SECRET_KEY = 'secret'

Expand Down Expand Up @@ -81,8 +79,27 @@
if not DEBUG:
loaders = (('django.template.loaders.cached.Loader', loaders),)

TEMPLATE_LOADERS = loaders

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(PROJECT_DIR, 'templates'),
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
'loaders': loaders,
},
},
]
MIDDLEWARE_CLASSES = [
'django.middleware.gzip.GZipMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -107,16 +124,6 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'example_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.
os.path.join(PROJECT_DIR, 'templates'),
)

TEMPLATE_CONTEXT_PROCESSORS = (
tuple(global_settings.TEMPLATE_CONTEXT_PROCESSORS) + ("django.core.context_processors.request",))

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
exclude=.tox,.venvs,south_migrations,migrations,example_project/settings/local.py
exclude=build,.tox,.venvs,south_migrations,migrations,example_project/settings/local.py
ignore=E123,F405
max-line-length=119
15 changes: 8 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def read_file(filename):
filepath = os.path.join(file_dir, filename)
return open(filepath).read()


# Fix for dateutil/SSL py3 support
if sys.version_info >= (3,):
dateutil = 'python-dateutil >= 2'
Expand All @@ -25,7 +26,7 @@ def read_file(filename):
if os.environ.get('TOX'):
django = 'Django >= 1.8.5'
else:
django = 'Django >= 1.8.5, < 1.9'
django = 'Django >= 1.8.5, < 2.0'

setup(
name="django-sayit",
Expand All @@ -42,22 +43,22 @@ def read_file(filename):
'pytz >= 2013d',
'six >= 1.4.1',
django,
'Django-Select2 == 4.3.2',
'mysociety-Django-Select2 == 4.3.2.1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be in a separate commit with an explanation of why we're using our own fork?

'audioread >= 1.0.1',
'elasticsearch >= 0.4',
'django-haystack >= 2.4, < 2.5',
'django-haystack >= 2.5, < 2.6',
'django-bleach >= 0.2.1',
'mysociety-django-popolo >= 0.0.5',
'mysociety-django-sluggable >= 0.2.7',
'django-subdomain-instances >= 1.0',
'easy-thumbnails >= 2.1',
'django-subdomain-instances >= 2.0',
'easy-thumbnails >= 2.4.1',
'unicode-slugify == 0.1.1',
] + ssl,
extras_require={
'test': [
'selenium < 3',
'selenium >= 3',
'mock',
'django-nose == 1.4.2',
'django-nose == 1.4.4',
'Mutagen',
'lxml',
dateutil,
Expand Down
14 changes: 0 additions & 14 deletions speeches/aggregates.py

This file was deleted.

12 changes: 7 additions & 5 deletions speeches/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ def value_from_datadict(self, data, files, name):
# If data is non-trivial and not a MultiValueDict, then an error will
# be thrown, which is a good thing.
if data:
return data.getlist(name)
# Django 1.11 made getlist return a copy (#27198) which would break this,
# so use its internal function in the absence of a larger refactor.
if hasattr(data, '_getlist'):
return data._getlist(name)
else:
return data.getlist(name)

def render(self, name, value, attrs=None, choices=()):
"""Because of the above; if we are given a list here, we don't want it."""
Expand Down Expand Up @@ -134,10 +139,6 @@ def clean(self, value):
class CreateAutoModelSelect2Field(AutoModelSelect2Field):
empty_values = [None, '', [], (), {}]

# If anything tries to run a query on .queryset, it means we've missed
# somewhere where we needed to limit things to the instance
queryset = 'UNUSED'

# instance will be set to an instance in the django-subdomain-instances
# sense by the form
instance = None
Expand Down Expand Up @@ -614,6 +615,7 @@ def clean(self):
_('Timestamps must be distinct'))
previous_timestamp = timestamp


RecordingTimestampFormSet = inlineformset_factory(
Recording,
RecordingTimestamp,
Expand Down
4 changes: 2 additions & 2 deletions speeches/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def save(self, *args, **kwargs):
if needs_conversion:
mp3_filename = audio_helper.make_mp3(self.audio.path)
mp3_file = open(mp3_filename, 'rb')
self.audio.save(mp3_file.name, File(mp3_file), save=False)
self.audio.save(os.path.basename(mp3_file.name), File(mp3_file), save=False)

if duration:
self.audio_duration = audio_helper.get_audio_duration(self.audio.path)
Expand Down Expand Up @@ -878,7 +878,7 @@ def create_or_update_speeches(self, instance):
speech.end_time = next_timestamp.timestamp.time()

audio_file = open(audio_file, 'rb')
speech.audio = File(audio_file)
speech.audio = File(audio_file, name=os.path.basename(audio_file.name))
speech.save()

if new:
Expand Down
25 changes: 10 additions & 15 deletions speeches/search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms

from haystack.forms import SearchForm
from haystack.views import SearchView
from haystack.generic_views import SearchView
from haystack.query import SearchQuerySet

from speeches.models import Speaker, Speech, Section
Expand Down Expand Up @@ -43,22 +43,17 @@ class InstanceSearchView(SearchView):
A subclass that filters the search query set to speeches within the current
request's instace.
"""
def __init__(self, *args, **kwargs):
kwargs['form_class'] = SpeechForm
super(InstanceSearchView, self).__init__(*args, **kwargs)
form_class = SpeechForm

def build_form(self, *args, **kwargs):
def get_queryset(self):
sqs = SearchQuerySet()
sqs = sqs.narrow('instance:"%s"' % self.request.instance.label)
self.searchqueryset = sqs
return super(InstanceSearchView, self).build_form(*args, **kwargs)
return sqs

def extra_context(self):
if not self.query:
return {}
def get_context_data(self, **kwargs):
context = super(InstanceSearchView, self).get_context_data(**kwargs)
if kwargs.get('query'):
person_form = self.get_form(SpeakerForm)
context['speaker_results'] = person_form.search()

self.form_class = SpeakerForm
person_form = self.build_form()
return {
'speaker_results': person_form.search(),
}
return context
4 changes: 2 additions & 2 deletions speeches/templates/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2>{% trans 'Speakers' %}</h2>
{% endif %}
<h2>{% blocktrans %}Mentions of <strong>&ldquo;{{ query }}&rdquo;</strong> in speeches{% endblocktrans %}</h2>
<ul class="unstyled-list search-results-list">
{% for result in page.object_list %}
{% for result in object_list %}
{% if result.model_name == 'speech' %}
{% include 'speeches/speech.html' with speech=result.object highlight=result.highlighted.0 %}
{% elif result.model_name == 'section' %}
Expand All @@ -47,7 +47,7 @@ <h2>{% blocktrans %}Mentions of <strong>&ldquo;{{ query }}&rdquo;</strong> in sp
{% endfor %}
</ul>

{% with page_obj=page %} {% paginate %} {% endwith %}
{% paginate %}

{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
Expand Down
3 changes: 2 additions & 1 deletion speeches/templatetags/pagination_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''):
try:
paginator = context['paginator']
page_obj = context['page_obj']
page_range = paginator.page_range
page_range = list(paginator.page_range)
# Calculate the record range in the current page for display.
records = {'first': 1 + (page_obj.number - 1) * paginator.per_page}
records['last'] = records['first'] + paginator.per_page - 1
Expand Down Expand Up @@ -135,5 +135,6 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''):
except (KeyError, AttributeError):
return {}


register.inclusion_tag('pagination/pagination.html', takes_context=True)(
paginate)
Loading