comparison gpp/gcalendar/admin.py @ 456:5be072292e2d

Working on #220. Can't test locally, so committing in increments.
author Brian Neal <bgneal@gmail.com>
date Fri, 01 Jul 2011 00:43:44 +0000
parents 5b2114cec3e3
children 7b7332037396
comparison
equal deleted inserted replaced
455:e44dd53885dc 456:5be072292e2d
13 from django.shortcuts import render_to_response 13 from django.shortcuts import render_to_response
14 from django.template import RequestContext 14 from django.template import RequestContext
15 15
16 import gdata.client 16 import gdata.client
17 17
18 from gcalendar.models import Event 18 from gcalendar.models import Event, AccessToken
19 from gcalendar.forms import PasswordForm 19 from gcalendar.forms import PasswordForm
20 from gcalendar.calendar import Calendar 20 from gcalendar.calendar import Calendar
21 from gcalendar.calendar import CalendarError 21 from gcalendar.calendar import CalendarError
22 from gcalendar import oauth 22 from gcalendar import oauth
23 23
132 return HttpResponseRedirect(auth_url) 132 return HttpResponseRedirect(auth_url)
133 133
134 def get_access_token(self, request): 134 def get_access_token(self, request):
135 """ 135 """
136 This view is called by Google after the user has authorized us access to 136 This view is called by Google after the user has authorized us access to
137 their data. We call into the oauth module to upgrade the oauth token to 137 their data. We call into the oauth module to upgrade the oauth token to
138 an access token. We then save the access token in the database and 138 an access token. We then save the access token in the database and
139 redirect back to our admin Google sync view. 139 redirect back to our admin Google sync view.
140 140
141 """ 141 """
142 try: 142 try:
143 access_token = oauth.get_access_token(request) 143 access_token = oauth.get_access_token(request)
144 except gdata.client.Error, e: 144 except gdata.client.Error, e:
145 messages.error(request, str(e)) 145 messages.error(request, str(e))
146 else: 146 else:
147 # TODO: save access token 147 try:
148 pass 148 token = AccessToken.objects.get(id=1)
149 except AccessToken.DoesNotExist:
150 token = AccessToken()
151
152 token.token = gdata.gauth.TokenToBlob(access_token)
153 token.auth_date = datetime.datetime.now()
154 token.save()
149 155
150 return HttpResponseRedirect(reverse('admin:gcalendar-google_sync')) 156 return HttpResponseRedirect(reverse('admin:gcalendar-google_sync'))
151 157
152 158
153 admin.site.register(Event, EventAdmin) 159 admin.site.register(Event, EventAdmin)
160 admin.site.register(AccessToken)