diff --git a/.travis.yml b/.travis.yml index 6d116d9..65b295f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,21 +5,19 @@ sudo: false python: - "3.6" - "3.7" + - "3.8" env: matrix: - - DJANGO=2.0 - - DJANGO=2.1 - DJANGO=2.2 + - DJANGO=3.0 + - DJANGO=3.1 - DJANGO=master addons: postgresql: '9.6' matrix: - exclude: - - { python: "3.7", env: DJANGO=2.0 } - include: - { python: "3.6", env: TOXENV=flake8 } diff --git a/MANIFEST.in b/MANIFEST.in index a5021c6..ddffd89 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include README.rst include LICENSE +recursive-include requirements * diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 4b0d013..d9383b6 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -1,6 +1,12 @@ Release Notes ============= +v2.0.0 +------ +* Add support Django 3.0, 3.1 +* Add support for python 3.8 +* Drop support for Django 2.1 + v1.2.0 ------ * Add Django 2.1 diff --git a/querybuilder/query.py b/querybuilder/query.py index 119ddd3..e521c0b 100644 --- a/querybuilder/query.py +++ b/querybuilder/query.py @@ -4,15 +4,11 @@ from django.db.models import Q, AutoField from django.db.models.query import QuerySet from django.db.models.constants import LOOKUP_SEP -try: - # Django 1.9 - from django.apps import apps - get_model = apps.get_model -except ImportError: # pragma: no cover - # Django < 1.9 - from django.db.models import get_model +from django.apps import apps +get_model = apps.get_model import six + from querybuilder.fields import FieldFactory, CountField, MaxField, MinField, SumField, AvgField from querybuilder.helpers import set_value_for_keypath from querybuilder.tables import TableFactory, ModelTable, QueryTable diff --git a/querybuilder/tests/json_tests.py b/querybuilder/tests/json_tests.py index e565421..670532a 100644 --- a/querybuilder/tests/json_tests.py +++ b/querybuilder/tests/json_tests.py @@ -1,4 +1,5 @@ import unittest +from django import VERSION from django.test.testcases import TestCase from django.test.utils import override_settings from querybuilder.fields import JsonField @@ -45,7 +46,12 @@ def test_one(self): 'querybuilder_tests_metricrecord WHERE (querybuilder_tests_metricrecord.data->>\'two\' = %(A0)s)' ) ) - self.assertEqual(query.select(), [{'my_two_alias': 'two'}]) + + # Django 3.1 changes the raw queryset behavior so querybuilder isn't going to change that behavior + if VERSION[0] == 3 and VERSION[1] == 1: + self.assertEqual(query.select(), [{'my_two_alias': '"two"'}]) + else: + self.assertEqual(query.select(), [{'my_two_alias': 'two'}]) query = Query().from_table(MetricRecord, fields=[one_field]).where(**{ one_field.get_where_key(): '1' @@ -57,7 +63,12 @@ def test_one(self): 'querybuilder_tests_metricrecord WHERE (querybuilder_tests_metricrecord.data->>\'one\' = %(A0)s)' ) ) - self.assertEqual(query.select(), [{'my_one_alias': 1}]) + + # Django 3.1 changes the raw queryset behavior so querybuilder isn't going to change that behavior + if VERSION[0] == 3 and VERSION[1] == 1: + self.assertEqual(query.select(), [{'my_one_alias': '1'}]) + else: + self.assertEqual(query.select(), [{'my_one_alias': 1}]) query = Query().from_table(MetricRecord, fields=[one_field]).where(**{ one_field.get_where_key(): '2' @@ -93,11 +104,11 @@ def test_one(self): record = JsonQueryset(model=MetricRecord).filter(**{'data->two': 'one'}).first() self.assertIsNone(record) - record = JsonQueryset(model=MetricRecord).filter(**{'data->two': 'two'}).first() - self.assertEqual(record.data['two'], 'two') + records = list(JsonQueryset(model=MetricRecord).filter(**{'data->two': 'two'})) + self.assertEqual(records[0].data['two'], 'two') - record = JsonQueryset(model=MetricRecord).filter(**{'data->one': '1'}).first() - self.assertEqual(record.data['one'], 1) + records = list(JsonQueryset(model=MetricRecord).filter(**{'data->one': '1'})) + self.assertEqual(records[0].data['one'], 1) record = JsonQueryset(model=MetricRecord).filter(**{'data->one': '2'}).first() self.assertIsNone(record) diff --git a/querybuilder/tests/models.py b/querybuilder/tests/models.py index 8dc83d9..cc87117 100644 --- a/querybuilder/tests/models.py +++ b/querybuilder/tests/models.py @@ -1,7 +1,10 @@ try: - from django.contrib.postgres.fields import JSONField + from django.db.models import JSONField except ImportError: - from jsonfield import JSONField + try: + from django.contrib.postgres.fields import JSONField + except ImportError: + from jsonfield import JSONField from django.db import models diff --git a/querybuilder/version.py b/querybuilder/version.py index 58d478a..afced14 100644 --- a/querybuilder/version.py +++ b/querybuilder/version.py @@ -1 +1 @@ -__version__ = '1.2.0' +__version__ = '2.0.0' diff --git a/requirements/requirements.txt b/requirements/requirements.txt new file mode 100644 index 0000000..a9cf3ca --- /dev/null +++ b/requirements/requirements.txt @@ -0,0 +1,4 @@ +Django>=2.2 +pytz>=2015.6 +fleming>=0.6.0 +six diff --git a/setup.py b/setup.py index 78b7a0f..5c26b9d 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,14 @@ def get_version(): raise RuntimeError('Unable to find version string in {0}.'.format(VERSION_FILE)) +def get_lines(file_path): + return open(file_path, 'r').read().split('\n') + + +install_requires = get_lines('requirements/requirements.txt') +tests_require = get_lines('requirements/requirements-testing.txt') + + setup( name='django-query-builder', version=get_version(), @@ -31,29 +39,19 @@ def get_version(): 'Programming Language :: Python', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Framework :: Django', - 'Framework :: Django :: 2.0', - 'Framework :: Django :: 2.1', 'Framework :: Django :: 2.2', + 'Framework :: Django :: 3.0', + 'Framework :: Django :: 3.1', 'Development Status :: 5 - Production/Stable', ], license='MIT', - install_requires=[ - 'Django>=1.11', - 'pytz>=2015.6', - 'fleming>=0.4.4', - 'six', - ], - tests_require=[ - 'psycopg2', - 'django-nose>=1.4', - 'django-dynamic-fixture', - 'jsonfield==0.9.20', - 'mock' - ], + install_requires=install_requires, + tests_require=tests_require, test_suite='run_tests.run_tests', include_package_data=True, ) diff --git a/tox.ini b/tox.ini index 0dc3bce..0b15b2f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,18 +1,18 @@ [tox] envlist = flake8 - py{36}-django20 - py{36,37}-django21 py{36,37}-django22 - py{36,37}-djangomaster + py{36,37,38}-django30 + py{36,37,38}-django31 + py{36,37,38}-djangomaster [testenv] setenv = DB = postgres deps = - django20: Django>=2.0,<2.1 - django21: Django>=2.1,<2.2 - django22: Django>=2.2,<2.3 + django22: Django>=2.2,<3.0 + django30: Django>=3.0,<3.1 + django31: Django>=3.1,<3.2 djangomaster: https://github.com/django/django/archive/master.tar.gz -rrequirements/requirements-testing.txt commands = @@ -25,7 +25,7 @@ commands = flake8 querybuilder [travis:env] DJANGO = - 2.0: django20 - 2.1: django21 2.2: django22 + 3.0: django30 + 3.1: django31 master: djangomaster