Merge lp:~nataliabidart/django-oauth-backend/django-1.7-1.8 into lp:django-oauth-backend

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 23
Merged at revision: 21
Proposed branch: lp:~nataliabidart/django-oauth-backend/django-1.7-1.8
Merge into: lp:django-oauth-backend
Diff against target: 429 lines (+261/-54)
11 files modified
.bzrignore (+1/-0)
demo/settings.py (+91/-0)
demo/urls.py (+11/-0)
demo/wsgi.py (+14/-0)
manage.py (+10/-0)
oauth_backend/migrations/0001_initial.py (+69/-0)
oauth_backend/models.py (+15/-14)
requirements.txt (+0/-3)
setup.py (+9/-7)
testmanage.py (+0/-30)
tox.ini (+41/-0)
To merge this branch: bzr merge lp:~nataliabidart/django-oauth-backend/django-1.7-1.8
Reviewer Review Type Date Requested Status
Ricardo Kirkner (community) Approve
Review via email: mp+257306@code.launchpad.net

Commit message

- Migration to support Django 1.4-1.8.

To post a comment you must log in.
22. By Natalia Bidart

Fixed lint issues.

Revision history for this message
Ricardo Kirkner (ricardokirkner) :
23. By Natalia Bidart

Applied changes from review.

Revision history for this message
Natalia Bidart (nataliabidart) :
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

Great stuff, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2015-04-24 18:37:20 +0000
4@@ -0,0 +1,1 @@
5+.tox
6
7=== added directory 'demo'
8=== added file 'demo/__init__.py'
9=== added file 'demo/settings.py'
10--- demo/settings.py 1970-01-01 00:00:00 +0000
11+++ demo/settings.py 2015-04-24 18:37:20 +0000
12@@ -0,0 +1,91 @@
13+"""
14+Django settings for demo project.
15+
16+For more information on this file, see
17+https://docs.djangoproject.com/en/1.7/topics/settings/
18+
19+For the full list of settings and their values, see
20+https://docs.djangoproject.com/en/1.7/ref/settings/
21+"""
22+
23+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
24+import os
25+import django
26+
27+BASE_DIR = os.path.dirname(os.path.dirname(__file__))
28+
29+
30+# Quick-start development settings - unsuitable for production
31+# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
32+
33+# SECURITY WARNING: keep the secret key used in production secret!
34+SECRET_KEY = '5x!r)iz$_*xg$)x=r$!5(%e+cmfe93jcx^k!im6k5(z67nm2l('
35+
36+# SECURITY WARNING: don't run with debug turned on in production!
37+DEBUG = True
38+
39+TEMPLATE_DEBUG = True
40+
41+ALLOWED_HOSTS = []
42+
43+
44+# Application definition
45+
46+INSTALLED_APPS = (
47+ 'django.contrib.admin',
48+ 'django.contrib.auth',
49+ 'django.contrib.contenttypes',
50+ 'django.contrib.sessions',
51+ 'django.contrib.messages',
52+ 'django.contrib.staticfiles',
53+ 'oauth_backend',
54+)
55+
56+MIDDLEWARE_CLASSES = [
57+ 'django.contrib.sessions.middleware.SessionMiddleware',
58+ 'django.middleware.common.CommonMiddleware',
59+ 'django.middleware.csrf.CsrfViewMiddleware',
60+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
61+ 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
62+ 'django.contrib.messages.middleware.MessageMiddleware',
63+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
64+]
65+
66+if django.VERSION < (1, 7):
67+ INSTALLED_APPS += ('south',)
68+ MIDDLEWARE_CLASSES.remove(
69+ 'django.contrib.auth.middleware.SessionAuthenticationMiddleware')
70+
71+ROOT_URLCONF = 'demo.urls'
72+
73+WSGI_APPLICATION = 'demo.wsgi.application'
74+
75+
76+# Database
77+# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
78+
79+DATABASES = {
80+ 'default': {
81+ 'ENGINE': 'django.db.backends.sqlite3',
82+ 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
83+ }
84+}
85+
86+# Internationalization
87+# https://docs.djangoproject.com/en/1.7/topics/i18n/
88+
89+LANGUAGE_CODE = 'en-us'
90+
91+TIME_ZONE = 'UTC'
92+
93+USE_I18N = True
94+
95+USE_L10N = True
96+
97+USE_TZ = True
98+
99+
100+# Static files (CSS, JavaScript, Images)
101+# https://docs.djangoproject.com/en/1.7/howto/static-files/
102+
103+STATIC_URL = '/static/'
104
105=== added file 'demo/urls.py'
106--- demo/urls.py 1970-01-01 00:00:00 +0000
107+++ demo/urls.py 2015-04-24 18:37:20 +0000
108@@ -0,0 +1,11 @@
109+from django.conf.urls import patterns, include, url
110+from django.contrib import admin
111+
112+urlpatterns = patterns(
113+ '',
114+ # Examples:
115+ # url(r'^$', 'demo.views.home', name='home'),
116+ # url(r'^blog/', include('blog.urls')),
117+
118+ url(r'^admin/', include(admin.site.urls)),
119+)
120
121=== added file 'demo/wsgi.py'
122--- demo/wsgi.py 1970-01-01 00:00:00 +0000
123+++ demo/wsgi.py 2015-04-24 18:37:20 +0000
124@@ -0,0 +1,14 @@
125+"""
126+WSGI config for demo project.
127+
128+It exposes the WSGI callable as a module-level variable named ``application``.
129+
130+For more information on this file, see
131+https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
132+"""
133+
134+import os
135+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
136+
137+from django.core.wsgi import get_wsgi_application
138+application = get_wsgi_application()
139
140=== added file 'manage.py'
141--- manage.py 1970-01-01 00:00:00 +0000
142+++ manage.py 2015-04-24 18:37:20 +0000
143@@ -0,0 +1,10 @@
144+#!/usr/bin/env python
145+import os
146+import sys
147+
148+if __name__ == "__main__":
149+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
150+
151+ from django.core.management import execute_from_command_line
152+
153+ execute_from_command_line(sys.argv)
154
155=== added directory 'oauth_backend/migrations'
156=== added file 'oauth_backend/migrations/0001_initial.py'
157--- oauth_backend/migrations/0001_initial.py 1970-01-01 00:00:00 +0000
158+++ oauth_backend/migrations/0001_initial.py 2015-04-24 18:37:20 +0000
159@@ -0,0 +1,69 @@
160+# -*- coding: utf-8 -*-
161+from __future__ import unicode_literals
162+
163+from django.db import models, migrations
164+import oauth_backend.models
165+import django.utils.timezone
166+from django.conf import settings
167+
168+
169+class Migration(migrations.Migration):
170+
171+ dependencies = [
172+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
173+ ]
174+
175+ operations = [
176+ migrations.CreateModel(
177+ name='Consumer',
178+ fields=[
179+ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
180+ ('secret', models.CharField(default=oauth_backend.models.generate_random_string_secret, max_length=255, blank=True)),
181+ ('created_at', models.DateTimeField(auto_now_add=True)),
182+ ('updated_at', models.DateTimeField(auto_now=True)),
183+ ('user', models.OneToOneField(related_name='oauth_consumer', to=settings.AUTH_USER_MODEL)),
184+ ],
185+ options={
186+ 'db_table': 'oauth_consumer',
187+ },
188+ bases=(models.Model,),
189+ ),
190+ migrations.CreateModel(
191+ name='Nonce',
192+ fields=[
193+ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
194+ ('nonce', models.CharField(max_length=255, editable=False)),
195+ ('created_at', models.DateTimeField(auto_now_add=True)),
196+ ('consumer', models.ForeignKey(to='oauth_backend.Consumer')),
197+ ],
198+ options={
199+ 'db_table': 'oauth_nonce',
200+ },
201+ bases=(models.Model,),
202+ ),
203+ migrations.CreateModel(
204+ name='Token',
205+ fields=[
206+ ('token', models.CharField(default=oauth_backend.models.generate_random_string_token, max_length=50, serialize=False, primary_key=True)),
207+ ('token_secret', models.CharField(default=oauth_backend.models.generate_random_string_secret, max_length=50)),
208+ ('name', models.CharField(max_length=255, blank=True)),
209+ ('created_at', models.DateTimeField(default=django.utils.timezone.now)),
210+ ('updated_at', models.DateTimeField(default=django.utils.timezone.now)),
211+ ('consumer', models.ForeignKey(to='oauth_backend.Consumer')),
212+ ],
213+ options={
214+ 'db_table': 'oauth_token',
215+ },
216+ bases=(models.Model,),
217+ ),
218+ migrations.AddField(
219+ model_name='nonce',
220+ name='token',
221+ field=models.ForeignKey(to='oauth_backend.Token'),
222+ preserve_default=True,
223+ ),
224+ migrations.AlterUniqueTogether(
225+ name='nonce',
226+ unique_together=set([('nonce', 'token', 'consumer')]),
227+ ),
228+ ]
229
230=== added file 'oauth_backend/migrations/__init__.py'
231=== modified file 'oauth_backend/models.py'
232--- oauth_backend/models.py 2014-01-27 18:36:44 +0000
233+++ oauth_backend/models.py 2015-04-24 18:37:20 +0000
234@@ -6,15 +6,13 @@
235 import string
236 import struct
237
238-from datetime import datetime
239-from functools import partial
240-
241 from oauth.oauth import OAuthToken, OAuthDataStore, OAuthConsumer
242
243 from django.conf import settings
244 from django.contrib.auth.models import User
245 from django.core.cache import cache
246 from django.db import models
247+from django.utils.timezone import now
248
249
250 __all__ = [
251@@ -31,9 +29,7 @@
252
253
254 def _set_seed():
255- if (not hasattr(_set_seed, 'seed') and
256- os.path.exists("/dev/random")):
257-
258+ if (not hasattr(_set_seed, 'seed') and os.path.exists("/dev/random")):
259 data = open("/dev/random").read(struct.calcsize('Q'))
260 random.seed(struct.unpack('Q', data))
261 _set_seed.seed = True
262@@ -45,14 +41,21 @@
263 for x in range(length))
264
265
266+def generate_random_string_secret():
267+ return generate_random_string(CONSUMER_SECRET_LENGTH)
268+
269+
270+def generate_random_string_token():
271+ return generate_random_string(TOKEN_LENGTH)
272+
273+
274 class Consumer(models.Model):
275 """An OAuth consumer (client)."""
276
277 user = models.OneToOneField(User, related_name='oauth_consumer')
278
279 secret = models.CharField(
280- max_length=255, blank=True,
281- default=partial(generate_random_string, CONSUMER_SECRET_LENGTH)
282+ max_length=255, blank=True, default=generate_random_string_secret,
283 )
284
285 created_at = models.DateTimeField(auto_now_add=True)
286@@ -79,18 +82,16 @@
287 consumer = models.ForeignKey(Consumer)
288
289 token = models.CharField(
290- max_length=TOKEN_LENGTH,
291- default=partial(generate_random_string, TOKEN_LENGTH),
292+ max_length=TOKEN_LENGTH, default=generate_random_string_token,
293 primary_key=True)
294
295 token_secret = models.CharField(
296- max_length=TOKEN_SECRET_LENGTH,
297- default=partial(generate_random_string, TOKEN_SECRET_LENGTH))
298+ max_length=TOKEN_SECRET_LENGTH, default=generate_random_string_secret)
299
300 name = models.CharField(max_length=255, blank=True)
301
302- created_at = models.DateTimeField(default=datetime.utcnow)
303- updated_at = models.DateTimeField(default=datetime.utcnow)
304+ created_at = models.DateTimeField(default=now)
305+ updated_at = models.DateTimeField(default=now)
306
307 class Meta:
308 db_table = 'oauth_token'
309
310=== renamed directory 'oauth_backend/migrations' => 'oauth_backend/south_migrations'
311=== removed file 'requirements.txt'
312--- requirements.txt 2014-01-22 19:53:25 +0000
313+++ requirements.txt 1970-01-01 00:00:00 +0000
314@@ -1,3 +0,0 @@
315-django<1.6
316-django-discover-runner==0.4
317-oauth
318
319=== modified file 'setup.py'
320--- setup.py 2013-02-07 12:45:52 +0000
321+++ setup.py 2015-04-24 18:37:20 +0000
322@@ -1,17 +1,19 @@
323 # Copyright 2010 Canonical Ltd. This software is licensed under the
324 # GNU Affero General Public License version 3 (see the file LICENSE).
325
326-from setuptools import setup
327+from setuptools import setup, find_packages
328
329 from oauth_backend import __version__
330
331
332 setup(
333- name = "django-oauth-backend",
334- version = __version__,
335- author = "Canonical ISD Hackers",
336- author_email = "canonical-isd@lists.launchpad.net",
337- license = "AGPLv3",
338- packages = ['oauth_backend', 'oauth_backend.migrations'],
339+ name="django-oauth-backend",
340+ version=__version__,
341+ author='Canonical Ltd',
342+ author_email="canonical-isd@lists.launchpad.net",
343+ license="AGPLv3",
344+ platforms=['any'],
345+ packages=find_packages(),
346+ url='https://launchpad.net/django-oauth-backend',
347 zip_safe = True,
348 )
349
350=== removed file 'testmanage.py'
351--- testmanage.py 2014-01-22 19:53:25 +0000
352+++ testmanage.py 1970-01-01 00:00:00 +0000
353@@ -1,30 +0,0 @@
354-#!/usr/bin/env python
355-
356-import sys
357-
358-from django.conf import settings
359-from django.core.management import execute_from_command_line
360-
361-
362-if not settings.configured:
363- settings.configure(
364- DATABASES={
365- 'default': {
366- 'ENGINE': 'django.db.backends.sqlite3',
367- 'NAME': ':memory:',
368- },
369- },
370- INSTALLED_APPS=(
371- 'django.contrib.auth',
372- 'django.contrib.contenttypes',
373- 'oauth_backend',
374- ),
375- ROOT_URLCONF=None,
376- USE_TZ=False,
377- SECRET_KEY='foobar',
378- TEST_RUNNER='discover_runner.DiscoverRunner',
379- )
380-
381-
382-if __name__ == '__main__':
383- execute_from_command_line(sys.argv)
384
385=== added file 'tox.ini'
386--- tox.ini 1970-01-01 00:00:00 +0000
387+++ tox.ini 2015-04-24 18:37:20 +0000
388@@ -0,0 +1,41 @@
389+[tox]
390+envlist =
391+ py2.7-django1.4, py2.7-django1.5, py2.7-django1.6, py2.7-django1.7, py2.7-django1.8
392+
393+[testenv]
394+commands = python manage.py test oauth_backend
395+deps=
396+ oauth
397+
398+[testenv:py2.7-django1.4]
399+basepython = python2.7
400+deps =
401+ django >= 1.4, < 1.5
402+ {[testenv]deps}
403+ south==1.0
404+
405+[testenv:py2.7-django1.5]
406+basepython = python2.7
407+deps =
408+ django >= 1.5, < 1.6
409+ {[testenv]deps}
410+ south==1.0
411+
412+[testenv:py2.7-django1.6]
413+basepython = python2.7
414+deps =
415+ django >= 1.6, < 1.7
416+ {[testenv]deps}
417+ south==1.0
418+
419+[testenv:py2.7-django1.7]
420+basepython = python2.7
421+deps =
422+ django >= 1.7, < 1.8
423+ {[testenv]deps}
424+
425+[testenv:py2.7-django1.8]
426+basepython = python2.7
427+deps =
428+ django >= 1.8, < 1.9
429+ {[testenv]deps}

Subscribers

People subscribed via source and target branches