diff options
-rw-r--r-- | app/TODO | 17 | ||||
-rw-r--r-- | app/locations/static/admin/js/.DS_Store | bin | 6148 -> 0 bytes | |||
-rw-r--r-- | app/photos/models.py | 8 | ||||
-rw-r--r-- | app/syndication/admin.py | 8 | ||||
-rw-r--r-- | app/syndication/migrations/0002_auto_20160628_2149.py | 31 | ||||
-rw-r--r-- | app/syndication/models.py | 27 | ||||
-rw-r--r-- | app/syndication/syndicators.py | 27 | ||||
-rw-r--r-- | config/requirements.txt | 3 |
8 files changed, 79 insertions, 42 deletions
@@ -1,7 +1,5 @@ universal/ utils: -possibly convert to using Pandoc? Python is pretty good, but using Pandoc directly allows for epub, other formats as well. Plus standardized a bit. - Add resume project page add service worker: @@ -11,18 +9,6 @@ https://adactio.com/journal/9775 http://brucelawson.github.io/manifest/ https://serviceworker-cookbook.herokuapp.com/ -fix amp support by sanitizing html: - -https://github.com/duner/django-bluebox/blob/master/bluebox/converters/sanitizer.py - ---- - -#src - -handle callbacks from paypal to deliver the book and link to files: -https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/ - - --- # photos: @@ -36,5 +22,4 @@ port existing galleries to new structure # notes -revamp notes to be like my own personal instagram - +add syndicated item relationship for autoposting to twitter/facebook diff --git a/app/locations/static/admin/js/.DS_Store b/app/locations/static/admin/js/.DS_Store Binary files differdeleted file mode 100644 index 5008ddf..0000000 --- a/app/locations/static/admin/js/.DS_Store +++ /dev/null diff --git a/app/photos/models.py b/app/photos/models.py index e90a079..81b1e8b 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -78,6 +78,14 @@ class LuxImage(models.Model): if size.width <= 800: return self.get_image_by_size(size) + def get_largest_image(self): + t = [] + for size in self.sizes.all(): + t.append(size.width) + t.sort(key=float) + t.reverse() + return self.get_image_by_size(t[0]) + def get_image_name(self): return self.image.url.split("original/")[1][5:-4] diff --git a/app/syndication/admin.py b/app/syndication/admin.py index 9d88183..b873eb7 100644 --- a/app/syndication/admin.py +++ b/app/syndication/admin.py @@ -1,6 +1,12 @@ from django.contrib import admin -from .models import Syndicate, SyndicatedItem +from .models import Syndicate, SyndicatedItem, FBOAuthToken + + +@admin.register(FBOAuthToken) +class FBOAuthTokenAdmin(admin.ModelAdmin): + list_display = ('__str__', 'expires',) + pass @admin.register(Syndicate) diff --git a/app/syndication/migrations/0002_auto_20160628_2149.py b/app/syndication/migrations/0002_auto_20160628_2149.py new file mode 100644 index 0000000..51812bf --- /dev/null +++ b/app/syndication/migrations/0002_auto_20160628_2149.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-06-28 21:49 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('syndication', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='FBOAuthToken', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('short_token', models.TextField()), + ('long_token', models.TextField(blank=True, null=True)), + ('expires', models.DateTimeField(blank=True)), + ('created', models.DateTimeField(default=django.utils.timezone.now)), + ], + ), + migrations.AlterField( + model_name='syndicateditem', + name='status', + field=models.CharField(choices=[('1', 'Unsent'), ('2', 'Sent')], max_length=1, null=True), + ), + ] 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()) diff --git a/app/syndication/syndicators.py b/app/syndication/syndicators.py index 89280e3..9393d4d 100644 --- a/app/syndication/syndicators.py +++ b/app/syndication/syndicators.py @@ -1,19 +1,13 @@ from django.conf import settings from django.test.client import Client -import urllib -from urllib import parse -from urllib.parse import urlencode -import subprocess -import warnings from twython import Twython from bs4 import BeautifulSoup from medium import Client as MediumClient -from jrnl.models import extract_images -from photos.models import LuxImage import flickrapi import facebook +from photos.models import LuxImage def absolute_urls_for_syndication(s): @@ -99,6 +93,7 @@ def post_to_twitter(obj, ctype): except: status = t.update_status(status=status) + def post_photo_to_flickr(photo): flickr = flickrapi.FlickrAPI(settings.FLICKR_API_KEY, settings.FLICKR_API_SECRET) flickr.auth_url(perms='write') @@ -112,20 +107,10 @@ def post_photo_to_flickr(photo): pass -# Hide deprecation warnings. The facebook module isn't that up-to-date (facebook.GraphAPIError). -warnings.filterwarnings('ignore', category=DeprecationWarning) - - -# Parameters of your app and the id of the profile you want to mess with. - - -# Trying to get an access token. Very awkward. - -def post_photo_to_facebook(obj, ctype): - token = facebook.GraphAPI().get_app_access_token(settings.FACEBOOK_APP_ID, settings.FACEBOOK_APP_SECRET) - graph = facebook.GraphAPI(access_token=token, version='2.2') - - # Try to post something on the wall. +def post_to_facebook(obj, ctype): + from syndication.models import FBOAuthToken + token = FBOAuthToken.objects.latest() + graph = facebook.GraphAPI(access_token=token.long_token, version='2.2') if ctype == "lux image": p = open(obj.get_image_path_by_size("2280"), 'rb') if obj.caption: diff --git a/config/requirements.txt b/config/requirements.txt index 162e67e..0efb8f4 100644 --- a/config/requirements.txt +++ b/config/requirements.txt @@ -1,5 +1,4 @@ bleach==1.4.1 -Django==1.7.7 django-bleach==0.3.0 django-contrib-comments==1.5 django-extensions==1.5.2 @@ -11,8 +10,6 @@ ipython==3.0.0 jsmin==2.1.1 Markdown==2.6.1 oauthlib==0.7.2 -Pillow==2.7.0 -psycopg2==2.6 requests==2.6.0 requests-oauthlib==0.4.2 six==1.9.0 |