From 17000129e35b10c9d08497a669fd72f8233f065a Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Sat, 24 Nov 2012 23:19:03 +0100 Subject: Every (base) test should now pass with python3. --- rest_framework/authtoken/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rest_framework/authtoken') diff --git a/rest_framework/authtoken/models.py b/rest_framework/authtoken/models.py index 4da2aa62..7f5a75a3 100644 --- a/rest_framework/authtoken/models.py +++ b/rest_framework/authtoken/models.py @@ -19,8 +19,8 @@ class Token(models.Model): return super(Token, self).save(*args, **kwargs) def generate_key(self): - unique = str(uuid.uuid4()) - return hmac.new(unique, digestmod=sha1).hexdigest() + unique = uuid.uuid4() + return hmac.new(unique.bytes, digestmod=sha1).hexdigest() def __unicode__(self): return self.key -- cgit v1.2.3 From 4cdb6b2959f6d13417c48781d53c4e7e685934e7 Mon Sep 17 00:00:00 2001 From: Stephan Groß Date: Mon, 4 Mar 2013 13:53:39 +0100 Subject: Fix authtoken migration --- rest_framework/authtoken/migrations/0001_initial.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'rest_framework/authtoken') diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index f4e052e4..b0c81bf1 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import SchemaMigration from django.db import models +from rest_framework.settings import api_settings + try: from django.contrib.auth import get_user_model @@ -15,6 +17,8 @@ else: class Migration(SchemaMigration): + depends_on = api_settings.REQUIRED_MIGRATIONS + def forwards(self, orm): # Adding model 'Token' db.create_table('authtoken_token', ( @@ -45,7 +49,7 @@ class Migration(SchemaMigration): 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, "%s.%s" % (User._meta.app_label, User._meta.module_name): { - 'Meta': {'object_name': 'User'}, + 'Meta': {'object_name': User._meta.module_name}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), -- cgit v1.2.3 From d6391359f5cf4be394cf5785edab882f28cb225a Mon Sep 17 00:00:00 2001 From: Stephan Groß Date: Mon, 4 Mar 2013 14:04:03 +0100 Subject: Fix fix migrate authtoken --- rest_framework/authtoken/migrations/0001_initial.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'rest_framework/authtoken') diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index b0c81bf1..b7c563af 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -17,8 +17,6 @@ else: class Migration(SchemaMigration): - depends_on = api_settings.REQUIRED_MIGRATIONS - def forwards(self, orm): # Adding model 'Token' db.create_table('authtoken_token', ( -- cgit v1.2.3 From 27175c2cf50022af5c4683ba0283506c5f9a5fc6 Mon Sep 17 00:00:00 2001 From: Stephan Groß Date: Mon, 4 Mar 2013 17:04:55 +0100 Subject: Update migration --- rest_framework/authtoken/migrations/0001_initial.py | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'rest_framework/authtoken') diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index b7c563af..21b35f15 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -48,19 +48,7 @@ class Migration(SchemaMigration): }, "%s.%s" % (User._meta.app_label, User._meta.module_name): { 'Meta': {'object_name': User._meta.module_name}, - 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), - 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), - 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) }, 'authtoken.token': { 'Meta': {'object_name': 'Token'}, -- cgit v1.2.3 From 214e201ff87baea9f13ae3dccd9f905484de68ef Mon Sep 17 00:00:00 2001 From: Stephan Groß Date: Mon, 4 Mar 2013 17:12:02 +0100 Subject: Update migration --- rest_framework/authtoken/migrations/0001_initial.py | 1 - 1 file changed, 1 deletion(-) (limited to 'rest_framework/authtoken') diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index 21b35f15..d5965e40 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -48,7 +48,6 @@ class Migration(SchemaMigration): }, "%s.%s" % (User._meta.app_label, User._meta.module_name): { 'Meta': {'object_name': User._meta.module_name}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), }, 'authtoken.token': { 'Meta': {'object_name': 'Token'}, -- cgit v1.2.3 From c5b98f0d106758298edf045e7bb44ecd7e4b9629 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 8 Mar 2013 20:56:30 +0000 Subject: authtoken abstract if not installed. Fixes #705. --- rest_framework/authtoken/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'rest_framework/authtoken') diff --git a/rest_framework/authtoken/models.py b/rest_framework/authtoken/models.py index 7f5a75a3..52c45ad1 100644 --- a/rest_framework/authtoken/models.py +++ b/rest_framework/authtoken/models.py @@ -2,6 +2,7 @@ import uuid import hmac from hashlib import sha1 from rest_framework.compat import User +from django.conf import settings from django.db import models @@ -13,6 +14,14 @@ class Token(models.Model): user = models.OneToOneField(User, related_name='auth_token') created = models.DateTimeField(auto_now_add=True) + class Meta: + # Work around for a bug in Django: + # https://code.djangoproject.com/ticket/19422 + # + # Also see corresponding ticket: + # https://github.com/tomchristie/django-rest-framework/issues/705 + abstract = 'rest_framework.authtoken' not in settings.INSTALLED_APPS + def save(self, *args, **kwargs): if not self.key: self.key = self.generate_key() -- cgit v1.2.3