Mercurial > public > sg101
changeset 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 | e44dd53885dc |
children | 7b7332037396 |
files | gpp/gcalendar/admin.py gpp/gcalendar/models.py gpp/templates/admin/gcalendar/change_list.html gpp/templates/admin/gcalendar/event/change_list.html |
diffstat | 4 files changed, 37 insertions(+), 15 deletions(-) [+] |
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)
--- 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) +
--- 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 %} -<ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">Add {{ name }}</a></li> -<li><a href="google_sync/">Google Sync</a></li> -</ul> -{% endif %} -{% endblock %}
--- /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 %} +<ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">Add {{ name }}</a></li> +<li><a href="google_sync/">Google Sync</a></li> +</ul> +{% endif %} +{% endblock %}