From 9ad2e9a64931f90c5740962fb3ee3efd014fd81f Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 16 Feb 2017 18:58:36 -0800 Subject: [PATCH 1/3] bringing in necessary components/authentication into userprofile views from todo views. --- neuropy/userprofile/views.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/neuropy/userprofile/views.py b/neuropy/userprofile/views.py index 3e862c4..d06df19 100644 --- a/neuropy/userprofile/views.py +++ b/neuropy/userprofile/views.py @@ -1,14 +1,30 @@ """Views for profile.""" +import os +import httplib2 from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseRedirect from django.urls import reverse_lazy from django.views.generic import DetailView, UpdateView, FormView from userprofile.forms import ProfileForm, MedicationForm from userprofile.models import Profile -from todo.views import create_event_list +from todo.views import create_event_list, calender_insert +from userprofile.models import CredentialsModel +from oauth2client.contrib.django_util.storage import DjangoORMStorage +from oauth2client.contrib import xsrfutil +from neuropy import settings +from oauth2client.client import flow_from_clientsecrets + +CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), '..', 'neuropy', 'client_secret.json') + +FLOW = flow_from_clientsecrets( + CLIENT_SECRETS, + scope='https://www.googleapis.com/auth/calendar', + redirect_uri='http://localhost:8000/oauth2callback' +) + class ProfileView(LoginRequiredMixin, DetailView): """View for profile.""" @@ -38,6 +54,18 @@ def form_valid(self, form): """Return HttpResponse when valid data is posted.""" medication = form.cleaned_data['medication'] priority_list = create_event_list(medication.name, self.request.user.profile) + + storage = DjangoORMStorage(CredentialsModel, 'user_id', request.user, 'credential') + credential = storage.get() + if credential is None or credential.invalid: + FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY, + request.user) + authorize_url = FLOW.step1_get_authorize_url() + return HttpResponseRedirect(authorize_url) + else: + http = httplib2.Http() + http = credential.authorize(http) + self.request.session['some_list'] = priority_list return HttpResponseRedirect(self.get_success_url()) From 27b299dfa5aa1457c16fe85287dc77b349a901b2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 17 Feb 2017 11:31:56 -0800 Subject: [PATCH 2/3] merge conflict --- neuropy/neuropy/templates/neuropy/about.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/neuropy/neuropy/templates/neuropy/about.html b/neuropy/neuropy/templates/neuropy/about.html index 01ffe76..a88bf28 100644 --- a/neuropy/neuropy/templates/neuropy/about.html +++ b/neuropy/neuropy/templates/neuropy/about.html @@ -18,28 +18,28 @@

Sera Smith

-
Image
+
Image
Hi, I am Sera. I was born and raised in Tokyo, Japan until Age 11. I then moved to Seattle where I stayed until graduating from University of Washington with a degree in Criminal Psychology and Classical Japanese. I am bilingual and have 2 Shiba Inu's. I was also a Shiba Inu breeder while living in NV after UW. I am a Python developer.

Amos Bolder

-
Image
+
Image
Hi, I am Amos I love to code. Python rules everything else drools. I am Python developer.
-

Clair Gatenby

-
Image
+

Claire Gatenby

+
Image
I am a born and bred Australian who made the wild decision to quit my job and move to Seattle where I am learning how to code. I dream of using my past life as a scientist and my new skills as a developer to move into bioinformatics. I love cats, staying active, travelling, the outdoors and taking photos. I am Python developer.

Patrick Saunders

-
Image
+
Image
Hi, I am Patrick. I am a new, starry-eyed software developer. I am happiest when his tests are passing or at least when they’re failing in a predictable way. I am Python developer.
@@ -47,7 +47,7 @@

Patrick Saunders

-
+


From 562e0a945b0f0e7df88b62c7bd26ea3e9719a719 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 17 Feb 2017 13:10:50 -0800 Subject: [PATCH 3/3] corpse code and pdb --- neuropy/neuropy/urls.py | 1 - neuropy/todo/tests.py | 1 - neuropy/todo/views.py | 4 ---- 3 files changed, 6 deletions(-) diff --git a/neuropy/neuropy/urls.py b/neuropy/neuropy/urls.py index e7cc171..4987ab6 100644 --- a/neuropy/neuropy/urls.py +++ b/neuropy/neuropy/urls.py @@ -23,7 +23,6 @@ urlpatterns = [ - # url(r'^oauth2/', include(django_util_site.urls)), url(r'^oauth2callback', auth_return), url(r'^admin/', admin.site.urls), url(r'^$', TemplateView.as_view(template_name="neuropy/home.html"), diff --git a/neuropy/todo/tests.py b/neuropy/todo/tests.py index 4a94897..dbc61ae 100644 --- a/neuropy/todo/tests.py +++ b/neuropy/todo/tests.py @@ -588,5 +588,4 @@ def test_schedule_view_returns(self): session.save() html = self.client.get(reverse_lazy('create_sched')).content parsed_html = BeautifulSoup(html, "html5lib") - import pdb; pdb.set_trace() self.assertTrue(len(parsed_html.find_all('div')) == 10) diff --git a/neuropy/todo/views.py b/neuropy/todo/views.py index 4be41e5..3bb7cc4 100644 --- a/neuropy/todo/views.py +++ b/neuropy/todo/views.py @@ -4,7 +4,6 @@ from django.urls import reverse_lazy from django.views.generic import CreateView, UpdateView, ListView, DetailView, TemplateView from django.contrib.auth.mixins import (LoginRequiredMixin, - # PermissionRequiredMixin, UserPassesTestMixin, ) from todo.models import Todo @@ -47,7 +46,6 @@ def form_valid(self, form): class EditTodo(LoginRequiredMixin, UpdateView): """Edit todo.""" - # permission_required = "todo.change_todo" login_required = True model = Todo @@ -149,7 +147,6 @@ def td(time): drug = Medication.objects.get(name=drug_name) peak_end = start_time + datetime.timedelta(hours=td(drug.peak_end)) - # medium_start = start_time + datetime.timedelta(hours=td(drug.post_peak_medium_start)) easy_start = start_time + datetime.timedelta(hours=td(drug.post_peak_easy_start)) events_list = [] @@ -179,7 +176,6 @@ def td(time): events_list.append(dict(priority_dict)) start_time = start_time + datetime.timedelta(hours=event.duration) - print('priority_dict: ', priority_dict) return events_list