Skip to content

Commit f2b3e72

Browse files
committed
Downgraded tastypie from 0.12.1 to 0.11.1 for compatibility with Django 1.6 and south.
- Legacy-Id: 8753
1 parent 00e4818 commit f2b3e72

14 files changed

Lines changed: 131 additions & 190 deletions

File tree

tastypie/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
__author__ = 'Daniel Lindsley & the Tastypie core team'
5-
__version__ = (0, 12, 1)
5+
__version__ = (0, 11, 1)

tastypie/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from tastypie.utils import trailing_slash, is_valid_jsonp_callback_value
1010
from tastypie.utils.mime import determine_format, build_content_type
1111

12+
1213
class Api(object):
1314
"""
1415
Implements a registry to tie together the various resources that make up

tastypie/authentication.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django.utils.http import same_origin
1212
from django.utils.translation import ugettext as _
1313
from tastypie.http import HttpUnauthorized
14-
from tastypie.compat import get_user_model, get_username_field
14+
from tastypie.compat import User, username_field
1515

1616
try:
1717
from hashlib import sha1
@@ -180,6 +180,7 @@ def is_authenticated(self, request, **kwargs):
180180
Should return either ``True`` if allowed, ``False`` if not or an
181181
``HttpResponse`` if you need something custom.
182182
"""
183+
from tastypie.compat import User
183184

184185
try:
185186
username, api_key = self.extract_credentials(request)
@@ -189,9 +190,6 @@ def is_authenticated(self, request, **kwargs):
189190
if not username or not api_key:
190191
return self._unauthorized()
191192

192-
username_field = get_username_field()
193-
User = get_user_model()
194-
195193
try:
196194
lookup_kwargs = {username_field: username}
197195
user = User.objects.get(**lookup_kwargs)
@@ -282,8 +280,7 @@ def get_identifier(self, request):
282280
283281
This implementation returns the user's username.
284282
"""
285-
286-
return getattr(request.user, get_username_field())
283+
return getattr(request.user, username_field)
287284

288285

289286
class DigestAuthentication(Authentication):
@@ -369,9 +366,6 @@ def is_authenticated(self, request, **kwargs):
369366
return True
370367

371368
def get_user(self, username):
372-
username_field = get_username_field()
373-
User = get_user_model()
374-
375369
try:
376370
lookup_kwargs = {username_field: username}
377371
user = User.objects.get(**lookup_kwargs)

tastypie/compat.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
from __future__ import unicode_literals
22
from django.conf import settings
3+
from django.core.exceptions import ImproperlyConfigured
34
import django
45

5-
__all__ = ['get_user_model', 'get_username_field', 'AUTH_USER_MODEL']
6+
__all__ = ['User', 'AUTH_USER_MODEL']
67

78
AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
89

910
# Django 1.5+ compatibility
1011
if django.VERSION >= (1, 5):
11-
def get_user_model():
12-
from django.contrib.auth import get_user_model as django_get_user_model
13-
14-
return django_get_user_model()
15-
16-
def get_username_field():
17-
return get_user_model().USERNAME_FIELD
12+
try:
13+
from django.contrib.auth import get_user_model
14+
User = get_user_model()
15+
username_field = User.USERNAME_FIELD
16+
except ImproperlyConfigured:
17+
# The the users model might not be read yet.
18+
# This can happen is when setting up the create_api_key signal, in your
19+
# custom user module.
20+
User = None
21+
username_field = None
1822
else:
19-
def get_user_model():
20-
from django.contrib.auth.models import User
21-
22-
return User
23-
24-
def get_username_field():
25-
return 'username'
23+
from django.contrib.auth.models import User
24+
username_field = 'username'

tastypie/contrib/gis/resources.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# See COPYING file in this directory.
22
# Some code originally from django-boundaryservice
33
from __future__ import unicode_literals
4-
5-
import json
6-
74
try:
85
from urllib.parse import unquote
96
except ImportError:
@@ -12,6 +9,8 @@
129
from django.contrib.gis.db.models import GeometryField
1310
from django.contrib.gis.geos import GEOSGeometry
1411

12+
import json
13+
1514
from tastypie.fields import ApiField, CharField
1615
from tastypie import resources
1716

tastypie/fields.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from tastypie.exceptions import ApiFieldError, NotFound
1111
from tastypie.utils import dict_strip_unicode_keys, make_aware
1212

13-
import debug
1413

1514
class NOT_PROVIDED:
1615
def __str__(self):
@@ -231,6 +230,7 @@ class IntegerField(ApiField):
231230
def convert(self, value):
232231
if value is None:
233232
return None
233+
234234
return int(value)
235235

236236

@@ -543,7 +543,6 @@ def to_class(self):
543543
# to rely on). Try to throw a useful error.
544544
raise ImportError("Tastypie requires a Python-style path (<module.module.Class>) to lazy load related resources. Only given '%s'." % self.to)
545545

546-
import debug
547546
self._to_class = getattr(module, class_name, None)
548547

549548
if self._to_class is None:
@@ -708,7 +707,6 @@ def __init__(self, to, attribute, related_name=None, default=NOT_PROVIDED,
708707

709708
def dehydrate(self, bundle, for_list=True):
710709
foreign_obj = None
711-
error_to_raise = None
712710

713711
if isinstance(self.attribute, six.string_types):
714712
attrs = self.attribute.split('__')
@@ -720,19 +718,14 @@ def dehydrate(self, bundle, for_list=True):
720718
foreign_obj = getattr(foreign_obj, attr, None)
721719
except ObjectDoesNotExist:
722720
foreign_obj = None
723-
724721
elif callable(self.attribute):
725-
previous_obj = bundle.obj
726722
foreign_obj = self.attribute(bundle)
727-
723+
728724
if not foreign_obj:
729725
if not self.null:
730-
if callable(self.attribute):
731-
raise ApiFieldError("The related resource for resource %s could not be found." % (previous_obj))
732-
else:
733-
raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't allow a null value." % (previous_obj, self.instance_name))
734-
735-
return None
726+
raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't allow a null value." % (previous_obj, attr))
727+
728+
return None
736729

737730
self.fk_resource = self.get_related_resource(foreign_obj)
738731
fk_bundle = Bundle(obj=foreign_obj, request=bundle.request)

tastypie/management/commands/backfill_api_keys.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import print_function
22
from __future__ import unicode_literals
33
from django.core.management.base import NoArgsCommand
4-
from tastypie.compat import get_user_model
4+
from tastypie.compat import User
55
from tastypie.models import ApiKey
66

77

@@ -12,7 +12,6 @@ def handle_noargs(self, **options):
1212
"""Goes through all users and adds API keys for any that don't have one."""
1313
self.verbosity = int(options.get('verbosity', 1))
1414

15-
User = get_user_model()
1615
for user in User.objects.all().iterator():
1716
try:
1817
api_key = ApiKey.objects.get(user=user)
Lines changed: 95 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,97 @@
1-
# -*- coding: utf-8 -*-
1+
# encoding: utf-8
22
from __future__ import unicode_literals
3+
import datetime
4+
from south.db import db
5+
from south.v2 import SchemaMigration
6+
from django.db import models
7+
from tastypie.compat import AUTH_USER_MODEL
38

4-
from django.db import models, migrations
5-
from django.conf import settings
6-
import tastypie.utils.timezone
7-
8-
9-
class Migration(migrations.Migration):
10-
11-
dependencies = [
12-
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
13-
]
14-
15-
operations = [
16-
migrations.CreateModel(
17-
name='ApiAccess',
18-
fields=[
19-
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
20-
('identifier', models.CharField(max_length=255)),
21-
('url', models.CharField(default='', max_length=255, blank=True)),
22-
('request_method', models.CharField(default='', max_length=10, blank=True)),
23-
('accessed', models.PositiveIntegerField()),
24-
],
25-
options={
26-
},
27-
bases=(models.Model,),
28-
),
29-
migrations.CreateModel(
30-
name='ApiKey',
31-
fields=[
32-
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
33-
('key', models.CharField(default='', max_length=128, db_index=True, blank=True)),
34-
('created', models.DateTimeField(default=tastypie.utils.timezone.now)),
35-
('user', models.OneToOneField(related_name='api_key', to=settings.AUTH_USER_MODEL)),
36-
],
37-
options={
38-
'abstract': False,
39-
},
40-
bases=(models.Model,),
41-
),
42-
]
9+
10+
class Migration(SchemaMigration):
11+
12+
def forwards(self, orm):
13+
14+
# Adding model 'ApiAccess'
15+
db.create_table('tastypie_apiaccess', (
16+
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
17+
('identifier', self.gf('django.db.models.fields.CharField')(max_length=255)),
18+
('url', self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True)),
19+
('request_method', self.gf('django.db.models.fields.CharField')(default='', max_length=10, blank=True)),
20+
('accessed', self.gf('django.db.models.fields.PositiveIntegerField')()),
21+
))
22+
db.send_create_signal('tastypie', ['ApiAccess'])
23+
24+
# Adding model 'ApiKey'
25+
db.create_table('tastypie_apikey', (
26+
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
27+
('user', self.gf('django.db.models.fields.related.OneToOneField')(related_name='api_key', unique=True, to=orm[AUTH_USER_MODEL])),
28+
('key', self.gf('django.db.models.fields.CharField')(default='', max_length=256, blank=True)),
29+
('created', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
30+
))
31+
db.send_create_signal('tastypie', ['ApiKey'])
32+
33+
34+
def backwards(self, orm):
35+
36+
# Deleting model 'ApiAccess'
37+
db.delete_table('tastypie_apiaccess')
38+
39+
# Deleting model 'ApiKey'
40+
db.delete_table('tastypie_apikey')
41+
42+
43+
models = {
44+
'auth.group': {
45+
'Meta': {'object_name': 'Group'},
46+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
47+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
48+
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
49+
},
50+
'auth.permission': {
51+
'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
52+
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
53+
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
54+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
55+
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
56+
},
57+
AUTH_USER_MODEL: {
58+
'Meta': {'object_name': AUTH_USER_MODEL.split('.')[-1]},
59+
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
60+
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
61+
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
62+
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
63+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
64+
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
65+
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
66+
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
67+
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
68+
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
69+
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
70+
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
71+
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
72+
},
73+
'contenttypes.contenttype': {
74+
'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
75+
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
76+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
77+
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
78+
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
79+
},
80+
'tastypie.apiaccess': {
81+
'Meta': {'object_name': 'ApiAccess'},
82+
'accessed': ('django.db.models.fields.PositiveIntegerField', [], {}),
83+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
84+
'identifier': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
85+
'request_method': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '10', 'blank': 'True'}),
86+
'url': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'})
87+
},
88+
'tastypie.apikey': {
89+
'Meta': {'object_name': 'ApiKey'},
90+
'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
91+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
92+
'key': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '256', 'blank': 'True'}),
93+
'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'api_key'", 'unique': 'True', 'to': "orm['%s']" % AUTH_USER_MODEL})
94+
}
95+
}
96+
97+
complete_apps = ['tastypie']
File renamed without changes.

tastypie/models.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import time
44
from django.conf import settings
55
from django.db import models
6-
from django.utils.encoding import python_2_unicode_compatible
76
from tastypie.utils import now
87

98
try:
@@ -12,16 +11,16 @@
1211
import sha
1312
sha1 = sha.sha
1413

15-
@python_2_unicode_compatible
14+
1615
class ApiAccess(models.Model):
1716
"""A simple model for use with the ``CacheDBThrottle`` behaviors."""
1817
identifier = models.CharField(max_length=255)
1918
url = models.CharField(max_length=255, blank=True, default='')
2019
request_method = models.CharField(max_length=10, blank=True, default='')
2120
accessed = models.PositiveIntegerField()
2221

23-
def __str__(self):
24-
return "%s @ %s" % (self.identifier, self.accessed)
22+
def __unicode__(self):
23+
return u"%s @ %s" % (self.identifier, self.accessed)
2524

2625
def save(self, *args, **kwargs):
2726
self.accessed = int(time.time())

0 commit comments

Comments
 (0)