# HG changeset patch # User Brian Neal # Date 1309481024 0 # Node ID 5be072292e2d554a5cb31f44a483ba1c43048407 # Parent e44dd53885dca6c6aa73008db631d7ca9c83be8e Working on #220. Can't test locally, so committing in increments. diff -r e44dd53885dc -r 5be072292e2d gpp/gcalendar/admin.py --- 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) diff -r e44dd53885dc -r 5be072292e2d gpp/gcalendar/models.py --- a/gpp/gcalendar/models.py Thu Jun 30 02:40:48 2011 +0000 +++ b/gpp/gcalendar/models.py Fri Jul 01 00:43:44 2011 +0000 @@ -1,5 +1,6 @@ """ Models for the gcalendar application. + """ from django.db import models from django.db.models import Q @@ -18,8 +19,8 @@ """Returns a queryset of events that have been approved to update the Google calendar.""" return super(PendingEventManager, self).get_query_set().filter( - Q(status=Event.NEW_APRV) | \ - Q(status=Event.EDIT_APRV) | \ + Q(status=Event.NEW_APRV) | + Q(status=Event.EDIT_APRV) | Q(status=Event.DEL_APRV) ) @@ -98,9 +99,23 @@ forums.tools.create_topic( forum_slug=GIG_FORUM_SLUG, - user=self.user, + user=self.user, topic_name=topic_name, post_body=post_body) self.create_forum_thread = False self.save() + + +class AccessToken(models.Model): + """ + This model represents serialized OAuth access tokens for reading and + updating the Google Calendar. + + """ + auth_date = models.DateTimeField() + token = models.TextField() + + def __unicode__(self): + return u'Access token created on ' + unicode(self.auth_date) + diff -r e44dd53885dc -r 5be072292e2d gpp/templates/admin/gcalendar/change_list.html --- a/gpp/templates/admin/gcalendar/change_list.html Thu Jun 30 02:40:48 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -{% extends "admin/change_list.html" %} -{% block object-tools %} -{% if has_add_permission %} - -{% endif %} -{% endblock %} diff -r e44dd53885dc -r 5be072292e2d gpp/templates/admin/gcalendar/event/change_list.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/admin/gcalendar/event/change_list.html Fri Jul 01 00:43:44 2011 +0000 @@ -0,0 +1,8 @@ +{% extends "admin/change_list.html" %} +{% block object-tools %} +{% if has_add_permission %} + +{% endif %} +{% endblock %}