From 62ae3921a590ed74ed7290d5435064bc37fdcafb Mon Sep 17 00:00:00 2001 From: otherpirate Date: Sat, 8 Jul 2017 11:43:28 -0300 Subject: [PATCH 1/4] [django-sample] Fixing bugs and removing useless imports --- samples/django_sample/manage.py | 2 +- samples/django_sample/plus/models.py | 9 +-------- samples/django_sample/plus/views.py | 11 ++++------- samples/django_sample/settings.py | 4 +++- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/samples/django_sample/manage.py b/samples/django_sample/manage.py index b2f07f15ffa..4146caaabd0 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 6b9f762f87b..46a0225ae0a 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 CredentialsModel(models.Model): 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 979c2b013bf..bc454619a6f 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 -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 @@ def auth_return(request): 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/settings.py b/samples/django_sample/settings.py index ceb4b2922e1..76a16a8d3e5 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' From c33a369abccb6dd7dff7f492150fd8f54cec5791 Mon Sep 17 00:00:00 2001 From: otherpirate Date: Sat, 8 Jul 2017 11:44:28 -0300 Subject: [PATCH 2/4] [django-sample] Adding requirements --- samples/django_sample/requirements.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 samples/django_sample/requirements.txt diff --git a/samples/django_sample/requirements.txt b/samples/django_sample/requirements.txt new file mode 100644 index 00000000000..01ff083243e --- /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 From 6d4e08c1f66d0a1270a8fb541c7497a8db769b5b Mon Sep 17 00:00:00 2001 From: otherpirate Date: Sat, 8 Jul 2017 11:48:05 -0300 Subject: [PATCH 3/4] [django-sample] Adding make file --- samples/django_sample/Makefile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 samples/django_sample/Makefile diff --git a/samples/django_sample/Makefile b/samples/django_sample/Makefile new file mode 100644 index 00000000000..db509c37658 --- /dev/null +++ b/samples/django_sample/Makefile @@ -0,0 +1,18 @@ + +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 \ No newline at end of file From 99b2c3cb64138f5b2b5c14a2d757ecc68cb61ec2 Mon Sep 17 00:00:00 2001 From: otherpirate Date: Sat, 8 Jul 2017 11:55:40 -0300 Subject: [PATCH 4/4] Adding test to Makefile --- samples/django_sample/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/samples/django_sample/Makefile b/samples/django_sample/Makefile index db509c37658..35d29f048e2 100644 --- a/samples/django_sample/Makefile +++ b/samples/django_sample/Makefile @@ -1,4 +1,3 @@ - pip: @pip install -r requirements.txt @@ -15,4 +14,8 @@ setup: pip syncdb run shell: - @python manage.py shell \ No newline at end of file + @python manage.py shell + + +test: + @python manage.py test