summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/syndication/__init__.py0
-rw-r--r--app/syndication/admin.py13
-rw-r--r--app/syndication/medium.py22
-rw-r--r--app/syndication/migrations/0001_initial.py37
-rw-r--r--app/syndication/migrations/__init__.py0
-rw-r--r--app/syndication/models.py27
6 files changed, 99 insertions, 0 deletions
diff --git a/app/syndication/__init__.py b/app/syndication/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/syndication/__init__.py
diff --git a/app/syndication/admin.py b/app/syndication/admin.py
new file mode 100644
index 0000000..b7568a4
--- /dev/null
+++ b/app/syndication/admin.py
@@ -0,0 +1,13 @@
+from django.contrib import admin
+
+from .models import Syndicate, SyndicatedItem
+
+
+@admin.register(Syndicate)
+class SyndicateAdmin(admin.ModelAdmin):
+ pass
+
+
+@admin.register(SyndicatedItem)
+class SyndicatedItemAdmin(admin.ModelAdmin):
+ pass
diff --git a/app/syndication/medium.py b/app/syndication/medium.py
new file mode 100644
index 0000000..b7a1c6d
--- /dev/null
+++ b/app/syndication/medium.py
@@ -0,0 +1,22 @@
+from django.conf import settings
+
+from medium import Client
+
+
+def post_to_medium(item):
+ client = Client(application_id=settings.MEDIUM_CLIENT_ID, application_secret=settings.MEDIUM_CLIENT_SECRET)
+ client.access_token = settings.MEDIUM_INT_TOKEN
+ user = client.get_current_user()
+ head = '<p><i>This was originally posted <a href="%s" rel="canonical">on my own site</a>.</i></p>' % item.content_object.get_absolute_url()
+ body = "%s %s" % (head, item.content_object.body_html)
+ # Create a post.
+ post = client.create_post(
+ user_id=user["id"],
+ title=item.content_object.title,
+ content=body,
+ content_format="html",
+ publish_status="draft"
+ )
+ item.rel_link = post["url"]
+ item.status = 2
+ item.save()
diff --git a/app/syndication/migrations/0001_initial.py b/app/syndication/migrations/0001_initial.py
new file mode 100644
index 0000000..9643d51
--- /dev/null
+++ b/app/syndication/migrations/0001_initial.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9 on 2016-03-29 10:07
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ('contenttypes', '0002_remove_content_type_name'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Syndicate',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200)),
+ ],
+ ),
+ migrations.CreateModel(
+ name='SyndicatedItem',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('object_id', models.PositiveIntegerField()),
+ ('publish_date', models.DateTimeField()),
+ ('status', models.CharField(blank=True, choices=[('1', 'Unsent'), ('2', 'Sent')], max_length=1, null=True)),
+ ('rel_link', models.CharField(blank=True, max_length=300, null=True)),
+ ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
+ ('syndicate', models.ManyToManyField(to='syndication.Syndicate')),
+ ],
+ ),
+ ]
diff --git a/app/syndication/migrations/__init__.py b/app/syndication/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/syndication/migrations/__init__.py
diff --git a/app/syndication/models.py b/app/syndication/models.py
new file mode 100644
index 0000000..5856de1
--- /dev/null
+++ b/app/syndication/models.py
@@ -0,0 +1,27 @@
+from django.db import models
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.contenttypes.fields import GenericForeignKey
+
+
+class Syndicate(models.Model):
+ name = models.CharField(max_length=200)
+
+ def __str__(self):
+ return self.name
+
+
+class SyndicatedItem(models.Model):
+ content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
+ object_id = models.PositiveIntegerField()
+ content_object = GenericForeignKey('content_type', 'object_id')
+ syndicate = models.ManyToManyField(Syndicate)
+ publish_date = models.DateTimeField()
+ STATUS = (
+ ('1', "Unsent"),
+ ('2', "Sent"),
+ )
+ status = models.CharField(max_length=1, choices=STATUS, null=True, blank=True)
+ rel_link = models.CharField(max_length=300, null=True, blank=True)
+
+ def __str__(self):
+ return self.content_object.title