diff 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
line wrap: on
line diff
--- a/gpp/gcalendar/admin.py	Thu Jun 30 02:40:48 2011 +0000
+++ b/gpp/gcalendar/admin.py	Fri Jul 01 00:43:44 2011 +0000
@@ -15,7 +15,7 @@
 
 import gdata.client
 
-from gcalendar.models import Event
+from gcalendar.models import Event, AccessToken
 from gcalendar.forms import PasswordForm
 from gcalendar.calendar import Calendar
 from gcalendar.calendar import CalendarError
@@ -134,7 +134,7 @@
     def get_access_token(self, request):
         """
         This view is called by Google after the user has authorized us access to
-        their data. We call into the oauth module to upgrade the oauth token to 
+        their data. We call into the oauth module to upgrade the oauth token to
         an access token. We then save the access token in the database and
         redirect back to our admin Google sync view.
 
@@ -144,10 +144,17 @@
         except gdata.client.Error, e:
             messages.error(request, str(e))
         else:
-            # TODO: save access token
-            pass
+            try:
+                token = AccessToken.objects.get(id=1)
+            except AccessToken.DoesNotExist:
+                token = AccessToken()
+
+            token.token = gdata.gauth.TokenToBlob(access_token)
+            token.auth_date = datetime.datetime.now()
+            token.save()
 
         return HttpResponseRedirect(reverse('admin:gcalendar-google_sync'))
 
 
 admin.site.register(Event, EventAdmin)
+admin.site.register(AccessToken)