Skip to content

Commit adbc979

Browse files
committed
Add support for Django 1.8+
1 parent 30540b2 commit adbc979

File tree

6 files changed

+63
-20
lines changed

6 files changed

+63
-20
lines changed

.travis.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: python
22
python:
33
- "2.6"
44
- "2.7"
5+
sudo: false
56

67
env:
78
global:
@@ -10,21 +11,35 @@ env:
1011
matrix:
1112
- USE_EXTENSIONS=true # no dependencies
1213
- USE_EXTENSIONS=false # no dependencies
13-
- DJANGO_VERSION=1.2.7
14-
- DJANGO_VERSION=1.3.7
15-
- DJANGO_VERSION=1.5.12
16-
- DJANGO_VERSION=1.7.3
17-
- SQLALCHEMY_VERSION=0.7.10
18-
- SQLALCHEMY_VERSION=0.8.7
19-
- SQLALCHEMY_VERSION=0.9.8
20-
- TWISTED_VERSION=14.0.2
14+
# used as part of the pip command
15+
- DJANGO_VERSION=">=1.2,<1.3"
16+
- DJANGO_VERSION=">=1.3,<1.4"
17+
- DJANGO_VERSION=">=1.4,<1.5"
18+
- DJANGO_VERSION=">=1.5,<1.6"
19+
- DJANGO_VERSION=">=1.6,<1.7"
20+
- DJANGO_VERSION=">=1.7,<1.8"
21+
- DJANGO_VERSION=">=1.8,<1.9"
22+
- DJANGO_VERSION=">=1.9,<2.0"
23+
- SQLALCHEMY_VERSION=">=0.7,<0.8"
24+
- SQLALCHEMY_VERSION=">=0.8,<0.9"
25+
- SQLALCHEMY_VERSION=">=0.9,<1.0"
26+
- TWISTED_VERSION=">=14,<15"
27+
- TWISTED_VERSION=">=15,<16"
28+
# special, see install_optional_dependencies.sh
2129
- GAESDK_VERSION=1.9.30
2230

2331
matrix:
2432
exclude:
2533
# Django 1.7 dropped support for python 2.6
2634
- python: "2.6"
27-
env: DJANGO_VERSION=1.7.3
35+
env: DJANGO_VERSION=">=1.7,<1.8"
36+
- python: "2.6"
37+
env: DJANGO_VERSION=">=1.8,<1.9"
38+
- python: "2.6"
39+
env: DJANGO_VERSION=">=1.9,<2.0"
40+
# Twisted 15+ dropped support for Python 2.6
41+
- python: "2.6"
42+
env: TWISTED_VERSION=">=15,<16"
2843
# Google AppEngine SDK dropped support for python 2.6
2944
- python: "2.6"
3045
env: GAESDK_VERSION=1.9.30

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ versions of PyAMF.
66

77
.. contents::
88

9+
0.8 (Unreleased)
10+
----------------
11+
- Add support for Django>=1.8
12+
913
0.7.2 (2015-02-18)
1014
------------------
1115
- Add support for Cython >= 0.15 (should be backward compatible with future

install_optional_dependencies.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ function install_django {
88
return 0
99
fi
1010

11-
pip install "Django==${DJANGO_VERSION}"
11+
pip install "Django${DJANGO_VERSION}"
1212
}
1313

1414
function install_sqlalchemy {
1515
if [ -z "${SQLALCHEMY_VERSION}" ]; then
1616
return 0
1717
fi
1818

19-
pip install "SQLAlchemy==${SQLALCHEMY_VERSION}"
19+
pip install "SQLAlchemy${SQLALCHEMY_VERSION}"
2020
}
2121

2222
function install_twisted {
2323
if [ -z "${TWISTED_VERSION}" ]; then
2424
return 0
2525
fi
2626

27-
pip install "Twisted==${TWISTED_VERSION}"
27+
pip install "Twisted${TWISTED_VERSION}"
2828
}
2929

3030
function install_gae_sdk {

pyamf/adapters/_django_db_models_base.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@
88
@since: 0.4.1
99
"""
1010

11+
import datetime
12+
import sys
13+
1114
from django.db.models.base import Model
1215
from django.db.models import fields
13-
from django.db.models.fields import related, files
16+
from django.db.models.fields import files
1417

15-
import datetime
18+
models = sys.modules['django.db.models']
19+
20+
try:
21+
from django.db.models import related
22+
23+
ForeignObjectRel = related.RelatedObject
24+
except ImportError:
25+
# django 1.8+
26+
from django.db.models.fields import related
27+
28+
ForeignObjectRel = related.ForeignObjectRel
1629

1730
import pyamf
1831

@@ -74,12 +87,12 @@ def getCustomProperties(self):
7487
if isinstance(x, files.FileField):
7588
self.readonly_attrs.update([name])
7689

77-
if isinstance(x, related.RelatedObject):
90+
if isinstance(x, ForeignObjectRel):
7891
continue
7992

80-
if isinstance(x, related.ManyToManyField):
93+
if isinstance(x, models.ManyToManyField):
8194
self.relations[name] = x
82-
elif not isinstance(x, related.ForeignKey):
95+
elif not isinstance(x, models.ForeignKey):
8396
self.fields[name] = x
8497
else:
8598
self.relations[name] = x
@@ -188,7 +201,7 @@ def getEncodableAttributes(self, obj, **kwargs):
188201
if '_%s_cache' % name in obj.__dict__:
189202
attrs[name] = getattr(obj, name)
190203

191-
if isinstance(relation, related.ManyToManyField):
204+
if isinstance(relation, models.ManyToManyField):
192205
attrs[name] = [x for x in getattr(obj, name).all()]
193206
else:
194207
attrs.pop(relation.attname, None)
@@ -237,7 +250,7 @@ def getDecodableAttributes(self, obj, attrs, **kwargs):
237250

238251
if not getattr(obj, pk_attr):
239252
for name, relation in self.relations.iteritems():
240-
if isinstance(relation, related.ManyToManyField):
253+
if isinstance(relation, models.ManyToManyField):
241254
try:
242255
if len(attrs[name]) == 0:
243256
del attrs[name]

pyamf/adapters/tests/django_app/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@
1818
}
1919

2020

21-
INSTALLED_APPS = ('django_app.adapters',)
21+
INSTALLED_APPS = (
22+
'django_app.adapters',
23+
'django.contrib.contenttypes',
24+
'django.contrib.auth',
25+
)
2226
MIDDLEWARE_CLASSES = ()

pyamf/adapters/tests/test_django.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343

4444
models = None
4545

46+
# required for django <1.6 + python2.6
47+
__path__ = []
48+
4649

4750
def init_django():
4851
"""
@@ -63,6 +66,10 @@ def init_django():
6366

6467
from django_app import settings as app_settings
6568

69+
app_settings.INSTALLED_APPS = tuple(
70+
list(app_settings.INSTALLED_APPS) + [__name__]
71+
)
72+
6673
try:
6774
settings.configure(**app_settings.__dict__)
6875
except RuntimeError:

0 commit comments

Comments
 (0)