diff options
author | luxagraf <sng@luxagraf.net> | 2016-07-11 10:59:20 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2016-07-11 10:59:20 -0400 |
commit | 36c090402e9916b1920bbf48de306135e44a354f (patch) | |
tree | 992dc91915f7f3600050275edf260119b700427d /app/syndication/models.py | |
parent | 7ed163bdaa586e799e0f48901f2df801f0444e86 (diff) |
added facebook token auth stuff
Diffstat (limited to 'app/syndication/models.py')
-rw-r--r-- | app/syndication/models.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/app/syndication/models.py b/app/syndication/models.py index 32b8dd3..946b5cf 100644 --- a/app/syndication/models.py +++ b/app/syndication/models.py @@ -1,4 +1,7 @@ from django.db import models +from django.utils import timezone +from django.conf import settings +import datetime from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey from django.db.models.signals import post_save @@ -7,6 +10,28 @@ from django.dispatch import receiver from .syndicators import post_to_medium, build_facebook_feed, post_to_twitter, post_photo_to_flickr +class FBOAuthToken(models.Model): + short_token = models.TextField() + long_token = models.TextField(null=True, blank=True) + expires = models.DateTimeField(blank=True) + created = models.DateTimeField(default=timezone.now) + + def __str__(self): + return str(self.expires) + + def long_token_link(self): + token_url = "https://graph.facebook.com/oauth/access_token?client_id=%s&client_secret=%s&grant_type=fb_exchange_token&fb_exchange_token=%s" % (settings.FACEBOOK_APP_ID, settings.FACEBOOK_APP_SECRET, self.short_token) + return token_url + + class Meta: + ordering = ('-expires',) + get_latest_by = 'expires' + + def save(self, *args, **kwargs): + self.expires = self.created + datetime.timedelta(60) + super(FBOAuthToken, self).save() + + class Syndicate(models.Model): name = models.CharField(max_length=200) @@ -28,7 +53,7 @@ class SyndicatedItem(models.Model): rel_link = models.CharField(max_length=300, null=True, blank=True) def __str__(self): - return self.content_object.title + return str(self.content_object) def syndicated_to(self): return ','.join(str(synd) for synd in self.syndicate.all()) |