diff gcalendar/models.py @ 857:9165edfb1709

For issue #80, use new Google Calendar v3 API.
author Brian Neal <bgneal@gmail.com>
date Sat, 22 Nov 2014 13:27:13 -0600
parents 3e1905e523be
children 68c3343f3318
line wrap: on
line diff
--- a/gcalendar/models.py	Thu Nov 20 18:47:54 2014 -0600
+++ b/gcalendar/models.py	Sat Nov 22 13:27:13 2014 -0600
@@ -2,15 +2,12 @@
 Models for the gcalendar application.
 
 """
-import datetime
-
 from django.db import models
 from django.db.models import Q
 from django.contrib.auth.models import User
 
 from core.markup import site_markup
 import forums.tools
-from gcalendar.oauth import serialize_token, deserialize_token
 
 
 GIG_FORUM_SLUG = "gigs"
@@ -72,7 +69,7 @@
         ordering = ('-date_submitted', )
 
     def save(self, *args, **kwargs):
-        self.html = site_markup(self.description)
+        self.html = site_markup(self.description, relative_urls=False)
         super(Event, self).save(*args, **kwargs)
 
     def is_approved(self):
@@ -107,53 +104,3 @@
 
             self.create_forum_thread = False
             self.save()
-
-
-class AccessTokenManager(models.Manager):
-    """
-    A manager for the AccessToken table. Only one access token is saved in the
-    database. This manager provides a convenience method to either return that
-    access token or a brand new one.
-
-    """
-    def get_token(self):
-        try:
-            token = self.get(pk=1)
-        except AccessToken.DoesNotExist:
-            token = AccessToken()
-
-        return token
-
-
-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()
-
-    objects = AccessTokenManager()
-
-    def __unicode__(self):
-        return u'Access token created on ' + unicode(self.auth_date)
-
-    def update(self, access_token, auth_date=None):
-        """
-        This function updates the AccessToken object with the input parameters:
-            access_token - an access token from Google's OAuth dance
-            auth_date - a datetime or None. If None, now() is used.
-
-        """
-        self.auth_date = auth_date if auth_date else datetime.datetime.now()
-        self.token = serialize_token(access_token)
-
-    def access_token(self):
-        """
-        This function returns a Google OAuth access token by deserializing the
-        token field from the database.
-        If the token attribute is empty, None is returned.
-
-        """
-        return deserialize_token(self.token) if self.token else None