Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Django 1.8 support #335

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
20 changes: 10 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ python:
sudo: false

env:
- DJANGO=1.5.12 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.6.10 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.7.6 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.8.16 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.8.18 ENABLE_SQLITE=1 ENABLE_POSTGRES=0 ENABLE_MYSQL=0 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.8.18 ENABLE_SQLITE=0 ENABLE_POSTGRES=1 ENABLE_MYSQL=0 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.8.18 ENABLE_SQLITE=0 ENABLE_POSTGRES=0 ENABLE_MYSQL=1 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.10.7 ENABLE_SQLITE=1 ENABLE_POSTGRES=0 ENABLE_MYSQL=0 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.10.7 ENABLE_SQLITE=0 ENABLE_POSTGRES=1 ENABLE_MYSQL=0 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.10.7 ENABLE_SQLITE=0 ENABLE_POSTGRES=0 ENABLE_MYSQL=1 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.11.1 ENABLE_SQLITE=1 ENABLE_POSTGRES=0 ENABLE_MYSQL=0 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.11.1 ENABLE_SQLITE=0 ENABLE_POSTGRES=1 ENABLE_MYSQL=0 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
- DJANGO=1.11.1 ENABLE_SQLITE=0 ENABLE_POSTGRES=0 ENABLE_MYSQL=1 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado

services:
- memcached
Expand All @@ -32,13 +37,8 @@ before_script:
- mysql -u root -e 'CREATE DATABASE IF NOT EXISTS avocado;'

script:
- coverage run test_suite.py --sqlite --mysql --postgres
- coverage run test_suite.py #--sqlite --mysql --postgres

after_success:
- pip install -q coveralls
- coveralls

matrix:
exclude:
- python: "2.6"
env: DJANGO=1.7.6 POSTGRES_TEST_USER=postgres POSTGRES_TEST_NAME=avocado MYSQL_TEST_USER=root MYSQL_TEST_NAME=avocado
3 changes: 2 additions & 1 deletion avocado/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def clean(self):

class Meta(object):
model = DataField
exclude = []


class DataFieldAdmin(PublishedAdmin):
Expand Down Expand Up @@ -172,7 +173,7 @@ def create_dataconcept_multi(self, request, queryset):
DataConcept.objects.create_from_field(datafield)
create_dataconcept_multi.short_description = 'Create Data Concept for Each'

@transaction.commit_on_success
@transaction.atomic
def create_dataconcept_single(self, request, queryset):
fields = list(queryset)

Expand Down
2 changes: 1 addition & 1 deletion avocado/core/cache/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


class CacheManager(models.Manager):
def get_query_set(self):
def get_queryset(self):
return CacheQuerySet(self.model)
2 changes: 1 addition & 1 deletion avocado/core/cache/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def filter(self, *args, **kwargs):
break

if pk is not None:
key = cache_key_func([opts.app_label, opts.module_name, pk])
key = cache_key_func([opts.app_label, opts.model_name, pk])
cache = get_cache(settings.DATA_CACHE)
obj = cache.get(key)

Expand Down
10 changes: 5 additions & 5 deletions avocado/core/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class PassThroughManager(models.Manager):
"""Inherit from this Manager to enable you to call any methods from your
custom QuerySet class from your manager. Simply define your QuerySet
class, and return an instance of it from your manager's `get_query_set`
class, and return an instance of it from your manager's `get_queryset`
method.

Alternately, if you don't need any extra methods on your manager that
Expand All @@ -31,15 +31,15 @@ def __init__(self, queryset_cls=None):
def __getattr__(self, name):
if name in self._deny_methods:
raise AttributeError(name)
return getattr(self.get_query_set(), name)
return getattr(self.get_queryset(), name)

def get_query_set(self):
def get_queryset(self):
if self._queryset_cls is not None:
kwargs = {'model': self.model}
if hasattr(self, '_db'):
kwargs['using'] = self._db
return self._queryset_cls(**kwargs)
return super(PassThroughManager, self).get_query_set()
return super(PassThroughManager, self).get_queryset()


class PublishedQuerySet(CacheQuerySet):
Expand All @@ -50,5 +50,5 @@ def published(self):


class PublishedManager(PassThroughManager):
def get_query_set(self):
def get_queryset(self):
return PublishedQuerySet(self.model, using=self._db)
2 changes: 1 addition & 1 deletion avocado/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_heuristic_flags(field):

def parse_field_key(key):
"Returns a field lookup based on a variety of key types."
if isinstance(key, int):
if isinstance(key, int) or isinstance(key, long):
return {'pk': key}

keys = ('app_name', 'model_name', 'field_name')
Expand Down
2 changes: 1 addition & 1 deletion avocado/history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Revision(models.Model):

# The user that created the revision
user = models.ForeignKey(User, null=True, blank=True,
related_name='+revision')
related_name='revision')
session_key = models.CharField(max_length=40, null=True, blank=True)

# The timestamp of the revision
Expand Down
8 changes: 4 additions & 4 deletions avocado/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ def contribute_to_class(self, model, name):
super(DataFieldManager, self).contribute_to_class(model, name)
setattr(model, name, DataFieldManagerDescriptor(self))

def get_query_set(self):
def get_queryset(self):
return DataFieldQuerySet(self.model, using=self._db)

def get_by_natural_key(self, app_name, model_name=None, field_name=None):
queryset = self.get_query_set()
queryset = self.get_queryset()
if type(app_name) is int:
return queryset.get(id=app_name)

Expand All @@ -246,7 +246,7 @@ def get_by_natural_key(self, app_name, model_name=None, field_name=None):

class DataConceptManager(PublishedManager, DataConceptSearchMixin):
"Manager for the `DataConcept` model."
def get_query_set(self):
def get_queryset(self):
return DataConceptQuerySet(self.model, using=self._db)

@transaction.atomic
Expand Down Expand Up @@ -276,7 +276,7 @@ class DataCategoryManager(PublishedManager):
class DataClassBaseManager(models.Manager):
def get_default_template(self):
try:
return self.get_query_set().get(default=True, template=True)
return self.get_queryset().get(default=True, template=True)
except self.model.DoesNotExist:
pass

Expand Down
40 changes: 13 additions & 27 deletions avocado/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.db import migrations, models
import datetime
import avocado.query.oldparsers.datacontext
import jsonfield.fields
Expand All @@ -12,9 +12,9 @@
class Migration(migrations.Migration):

dependencies = [
('sites', '0001_initial'),
('contenttypes', '0002_remove_content_type_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('contenttypes', '0001_initial'),
('sites', '0001_initial'),
]

operations = [
Expand All @@ -36,7 +36,6 @@ class Migration(migrations.Migration):
'ordering': ('parent__order', 'parent__name', 'order', 'name'),
'verbose_name_plural': 'data categories',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DataConcept',
Expand All @@ -63,7 +62,6 @@ class Migration(migrations.Migration):
'ordering': ('category__order', 'category__name', 'order', 'name'),
'permissions': (('view_dataconcept', 'Can view dataconcept'),),
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DataConceptField',
Expand All @@ -79,7 +77,6 @@ class Migration(migrations.Migration):
options={
'ordering': ('order', 'name'),
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DataContext',
Expand All @@ -95,14 +92,13 @@ class Migration(migrations.Migration):
('template', models.BooleanField(default=False)),
('default', models.BooleanField(default=False)),
('session_key', models.CharField(max_length=40, null=True, blank=True)),
('accessed', models.DateTimeField(default=datetime.datetime(2015, 3, 10, 12, 40, 54, 775124), editable=False)),
('accessed', models.DateTimeField(default=datetime.datetime(2017, 1, 11, 22, 1, 1, 250639), editable=False)),
('parent', models.ForeignKey(related_name='forks', blank=True, to='avocado.DataContext', null=True)),
('user', models.ForeignKey(related_name='datacontext+', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'abstract': False,
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DataField',
Expand Down Expand Up @@ -132,13 +128,12 @@ class Migration(migrations.Migration):
('data_version', models.IntegerField(default=1, help_text=b'The current version of the underlying data for this field as of the last modification/update.')),
('order', models.FloatField(null=True, db_column=b'_order', blank=True)),
('category', models.ForeignKey(blank=True, to='avocado.DataCategory', null=True)),
('sites', models.ManyToManyField(related_name='fields+', to='sites.Site', blank=True)),
('sites', models.ManyToManyField(related_name='_datafield_sites_+', to='sites.Site', blank=True)),
],
options={
'ordering': ('category__order', 'category__name', 'order', 'name'),
'permissions': (('view_datafield', 'Can view datafield'),),
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DataQuery',
Expand All @@ -158,13 +153,12 @@ class Migration(migrations.Migration):
('context_json', jsonfield.fields.JSONField(default=dict, null=True, blank=True, validators=[avocado.query.oldparsers.datacontext.validate])),
('view_json', jsonfield.fields.JSONField(default=dict, null=True, blank=True, validators=[avocado.query.oldparsers.dataview.validate])),
('parent', models.ForeignKey(related_name='forks', blank=True, to='avocado.DataQuery', null=True)),
('shared_users', models.ManyToManyField(related_name='shareddataquery+', to=settings.AUTH_USER_MODEL)),
('shared_users', models.ManyToManyField(related_name='_dataquery_shared_users_+', to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(related_name='dataquery+', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'verbose_name_plural': 'data queries',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DataView',
Expand All @@ -180,14 +174,13 @@ class Migration(migrations.Migration):
('template', models.BooleanField(default=False)),
('default', models.BooleanField(default=False)),
('session_key', models.CharField(max_length=40, null=True, blank=True)),
('accessed', models.DateTimeField(default=datetime.datetime(2015, 3, 10, 12, 40, 54, 776427), editable=False)),
('accessed', models.DateTimeField(default=datetime.datetime(2017, 1, 11, 22, 1, 1, 252000), editable=False)),
('parent', models.ForeignKey(related_name='forks', blank=True, to='avocado.DataView', null=True)),
('user', models.ForeignKey(related_name='dataview+', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'abstract': False,
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Log',
Expand All @@ -201,9 +194,6 @@ class Migration(migrations.Migration):
('content_type', models.ForeignKey(blank=True, to='contenttypes.ContentType', null=True)),
('user', models.ForeignKey(related_name='+', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Revision',
Expand All @@ -216,34 +206,30 @@ class Migration(migrations.Migration):
('deleted', models.BooleanField(default=False)),
('changes', jsonfield.fields.JSONField(null=True, blank=True)),
('content_type', models.ForeignKey(to='contenttypes.ContentType')),
('user', models.ForeignKey(related_name='+revision', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('user', models.ForeignKey(related_name='revision', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'ordering': ('-timestamp',),
'get_latest_by': 'timestamp',
},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name='datafield',
unique_together=set([('app_name', 'model_name', 'field_name')]),
),
migrations.AddField(
model_name='dataconceptfield',
name='field',
field=models.ForeignKey(related_name='concept_fields', to='avocado.DataField'),
preserve_default=True,
),
migrations.AddField(
model_name='dataconcept',
name='fields',
field=models.ManyToManyField(related_name='concepts', through='avocado.DataConceptField', to='avocado.DataField'),
preserve_default=True,
),
migrations.AddField(
model_name='dataconcept',
name='sites',
field=models.ManyToManyField(related_name='concepts+', to='sites.Site', blank=True),
preserve_default=True,
field=models.ManyToManyField(related_name='_dataconcept_sites_+', to='sites.Site', blank=True),
),
migrations.AlterUniqueTogether(
name='datafield',
unique_together=set([('app_name', 'model_name', 'field_name')]),
),
]
11 changes: 9 additions & 2 deletions avocado/query/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import django
from django.core.cache import get_cache
from django.db import connections, DEFAULT_DB_ALIAS, DatabaseError
from django.db import (connections, DEFAULT_DB_ALIAS, DatabaseError,
OperationalError)
from django_rq import get_queue

from avocado.conf import settings
Expand Down Expand Up @@ -175,7 +176,13 @@ def _cancel_query(name, db, pid):

# Kills the query, but not the connection. Owners of the thread
# are allowed to kill their own queries.
c.execute('KILL QUERY %s', (pid,))
try:
c.execute('KILL QUERY %s', (pid,))
except OperationalError as oe:
# Ignore 1094, "Unknown thread id", as it must have
# finished already
if oe.args[0] != 1094:
raise oe

# TODO; any way to confirm it was actually killed?
# > SELECT 1 FROM information_schema.processlist WHERE id = %s
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Django==1.8.16
django-guardian==1.2.5
Django>=1.5,<1.11
django-guardian==1.4.6
django-haystack==2.3.1
Whoosh==2.6.0
jsonfield==1.0.0
Expand Down
10 changes: 4 additions & 6 deletions test_suite.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'

import django
if hasattr(django, 'setup'):
django.setup()

from django.core import management

os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'

apps = []

Expand Down Expand Up @@ -46,4 +41,7 @@
'tests.cases.validation.tests'
]

if hasattr(django, 'setup'):
django.setup()

management.call_command('test', *apps)
4 changes: 2 additions & 2 deletions tests/cases/core/tests/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ def test_arguments(self):
class CacheManagerTestCase(TestCase):
@override_settings(AVOCADO_DATA_CACHE_ENABLED=True)
def test(self):
self.assertEqual(Foo.objects.get_query_set().count(), 0)
self.assertEqual(Foo.objects.get_queryset().count(), 0)

for i in range(10):
f = Foo()
f.save()

self.assertEqual(Foo.objects.get_query_set().count(), 10)
self.assertEqual(Foo.objects.get_queryset().count(), 10)


class CachedMethodTestCase(TestCase):
Expand Down
Loading