Skip to content

Commit 52101a5

Browse files
otherpirateJon Wayne Parrott
authored andcommitted
Fixing django-sample (#413)
* [django-sample] Fixing bugs and removing useless imports * [django-sample] Adding requirements * [django-sample] Adding make file * Adding test to Makefile
1 parent d3a5cf4 commit 52101a5

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

samples/django_sample/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pip:
2+
@pip install -r requirements.txt
3+
4+
5+
syncdb:
6+
@python manage.py syncdb
7+
8+
9+
run:
10+
@python manage.py runserver 0.0.0.0:8000
11+
12+
13+
setup: pip syncdb run
14+
15+
16+
shell:
17+
@python manage.py shell
18+
19+
20+
test:
21+
@python manage.py test

samples/django_sample/manage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import absolute_import
33
from django.core.management import execute_manager
44
try:
5-
from . import settings # Assumed to be in the same directory.
5+
import settings # Assumed to be in the same directory.
66
except ImportError:
77
import sys
88
sys.stderr.write("""Error: Can't find the file 'settings.py' in the
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import pickle
2-
import base64
3-
41
from django.contrib import admin
52
from django.contrib.auth.models import User
63
from django.db import models
74

8-
from oauth2client.contrib.django_orm import FlowField
9-
from oauth2client.contrib.django_orm import CredentialsField
5+
from oauth2client.contrib.django_util.models import CredentialsField
106

117

128
class CredentialsModel(models.Model):
@@ -16,6 +12,3 @@ class CredentialsModel(models.Model):
1612

1713
class CredentialsAdmin(admin.ModelAdmin):
1814
pass
19-
20-
21-
admin.site.register(CredentialsModel, CredentialsAdmin)

samples/django_sample/plus/views.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,29 @@
44

55
from googleapiclient.discovery import build
66
from django.contrib.auth.decorators import login_required
7-
from django.core.urlresolvers import reverse
8-
from django.http import HttpResponse
97
from django.http import HttpResponseBadRequest
108
from django.http import HttpResponseRedirect
119
from django.shortcuts import render
1210
from django_sample.plus.models import CredentialsModel
1311
from django_sample import settings
1412
from oauth2client.contrib import xsrfutil
1513
from oauth2client.client import flow_from_clientsecrets
16-
from oauth2client.contrib.django_orm import Storage
14+
from oauth2client.contrib.django_util.storage import DjangoORMStorage
1715

1816
# CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this
1917
# application, including client_id and client_secret, which are found
2018
# on the API Access tab on the Google APIs
2119
# Console <http://code.google.com/apis/console>
22-
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json')
2320

2421
FLOW = flow_from_clientsecrets(
25-
CLIENT_SECRETS,
22+
settings.GOOGLE_OAUTH2_CLIENT_SECRETS_JSON,
2623
scope='https://www.googleapis.com/auth/plus.me',
2724
redirect_uri='http://localhost:8000/oauth2callback')
2825

2926

3027
@login_required
3128
def index(request):
32-
storage = Storage(CredentialsModel, 'id', request.user, 'credential')
29+
storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
3330
credential = storage.get()
3431
if credential is None or credential.invalid == True:
3532
FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY,
@@ -56,6 +53,6 @@ def auth_return(request):
5653
request.user):
5754
return HttpResponseBadRequest()
5855
credential = FLOW.step2_exchange(request.REQUEST)
59-
storage = Storage(CredentialsModel, 'id', request.user, 'credential')
56+
storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
6057
storage.put(credential)
6158
return HttpResponseRedirect("/")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Django==1.3
2+
google-api-python-client==1.6.2
3+
httplib2==0.10.3
4+
jsonpickle==0.9.4
5+
oauth2client==4.1.2
6+
pyasn1==0.2.3
7+
pyasn1-modules==0.0.9
8+
pytz==2017.2
9+
rsa==3.4.2
10+
six==1.10.0
11+
uritemplate==3.0.0

samples/django_sample/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,7 @@
7979
'django.contrib.contenttypes',
8080
'django.contrib.sessions',
8181
'django.contrib.sites',
82-
'django_sample.plus'
82+
'plus'
8383
)
84+
85+
GOOGLE_OAUTH2_CLIENT_SECRETS_JSON = 'client_secrets.json'

0 commit comments

Comments
 (0)