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
diff --git a/samples/django_sample/Makefile b/samples/django_sample/Makefile
new file mode 100644
index 0000000..35d29f0
--- /dev/null
+++ b/samples/django_sample/Makefile
@@ -0,0 +1,21 @@
+pip:
+ @pip install -r requirements.txt
+
+
+syncdb:
+ @python manage.py syncdb
+
+
+run:
+ @python manage.py runserver 0.0.0.0:8000
+
+
+setup: pip syncdb run
+
+
+shell:
+ @python manage.py shell
+
+
+test:
+ @python manage.py test
diff --git a/samples/django_sample/manage.py b/samples/django_sample/manage.py
index b2f07f1..4146caa 100755
--- a/samples/django_sample/manage.py
+++ b/samples/django_sample/manage.py
@@ -2,7 +2,7 @@
from __future__ import absolute_import
from django.core.management import execute_manager
try:
- from . import settings # Assumed to be in the same directory.
+ import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("""Error: Can't find the file 'settings.py' in the
diff --git a/samples/django_sample/plus/models.py b/samples/django_sample/plus/models.py
index 6b9f762..46a0225 100644
--- a/samples/django_sample/plus/models.py
+++ b/samples/django_sample/plus/models.py
@@ -1,12 +1,8 @@
-import pickle
-import base64
-
from django.contrib import admin
from django.contrib.auth.models import User
from django.db import models
-from oauth2client.contrib.django_orm import FlowField
-from oauth2client.contrib.django_orm import CredentialsField
+from oauth2client.contrib.django_util.models import CredentialsField
class CredentialsModel(models.Model):
@@ -16,6 +12,3 @@
class CredentialsAdmin(admin.ModelAdmin):
pass
-
-
-admin.site.register(CredentialsModel, CredentialsAdmin)
diff --git a/samples/django_sample/plus/views.py b/samples/django_sample/plus/views.py
index 979c2b0..bc45461 100644
--- a/samples/django_sample/plus/views.py
+++ b/samples/django_sample/plus/views.py
@@ -4,8 +4,6 @@
from googleapiclient.discovery import build
from django.contrib.auth.decorators import login_required
-from django.core.urlresolvers import reverse
-from django.http import HttpResponse
from django.http import HttpResponseBadRequest
from django.http import HttpResponseRedirect
from django.shortcuts import render
@@ -13,23 +11,22 @@
from django_sample import settings
from oauth2client.contrib import xsrfutil
from oauth2client.client import flow_from_clientsecrets
-from oauth2client.contrib.django_orm import Storage
+from oauth2client.contrib.django_util.storage import DjangoORMStorage
# CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this
# application, including client_id and client_secret, which are found
# on the API Access tab on the Google APIs
# Console <http://code.google.com/apis/console>
-CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json')
FLOW = flow_from_clientsecrets(
- CLIENT_SECRETS,
+ settings.GOOGLE_OAUTH2_CLIENT_SECRETS_JSON,
scope='https://www.googleapis.com/auth/plus.me',
redirect_uri='http://localhost:8000/oauth2callback')
@login_required
def index(request):
- storage = Storage(CredentialsModel, 'id', request.user, 'credential')
+ storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
credential = storage.get()
if credential is None or credential.invalid == True:
FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY,
@@ -56,6 +53,6 @@
request.user):
return HttpResponseBadRequest()
credential = FLOW.step2_exchange(request.REQUEST)
- storage = Storage(CredentialsModel, 'id', request.user, 'credential')
+ storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
storage.put(credential)
return HttpResponseRedirect("/")
diff --git a/samples/django_sample/requirements.txt b/samples/django_sample/requirements.txt
new file mode 100644
index 0000000..01ff083
--- /dev/null
+++ b/samples/django_sample/requirements.txt
@@ -0,0 +1,11 @@
+Django==1.3
+google-api-python-client==1.6.2
+httplib2==0.10.3
+jsonpickle==0.9.4
+oauth2client==4.1.2
+pyasn1==0.2.3
+pyasn1-modules==0.0.9
+pytz==2017.2
+rsa==3.4.2
+six==1.10.0
+uritemplate==3.0.0
diff --git a/samples/django_sample/settings.py b/samples/django_sample/settings.py
index ceb4b29..76a16a8 100644
--- a/samples/django_sample/settings.py
+++ b/samples/django_sample/settings.py
@@ -79,5 +79,7 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
- 'django_sample.plus'
+ 'plus'
)
+
+GOOGLE_OAUTH2_CLIENT_SECRETS_JSON = 'client_secrets.json'