diff --git a/Pipfile b/Pipfile index c092d98..eafb52c 100644 --- a/Pipfile +++ b/Pipfile @@ -43,6 +43,7 @@ django-rq = "*" ronkyuu = "*" cachecontrol = "*" hiredis = "*" +"mf2util" = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index d57a62c..ca0d511 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "a5ea894e51ad2d925b0d24739e2c644164b1edefbd3d363c1225a76c3926c23b" + "sha256": "89f67ee2a974377da512befef558bc9f3a6508ef6a7e8c69d28cfb3c4e7f64b8" }, "host-environment-markers": { "implementation_name": "cpython", @@ -11,7 +11,7 @@ "platform_python_implementation": "CPython", "platform_release": "17.3.0", "platform_system": "Darwin", - "platform_version": "Darwin Kernel Version 17.3.0: Wed Oct 25 22:42:12 PDT 2017; root:xnu-4570.30.81.0.1~1/RELEASE_X86_64", + "platform_version": "Darwin Kernel Version 17.3.0: Sun Oct 29 19:57:25 PDT 2017; root:xnu-4570.30.85~19/RELEASE_X86_64", "python_full_version": "3.6.3", "python_version": "3.6", "sys_platform": "darwin" @@ -107,6 +107,7 @@ "django-annoying": { "hashes": [ "sha256:07267defd06e37ad287053de4ea8c83ab4aae8114628830b7c91b70b63494572", + "sha256:1884f1452e0b9542c7db2ed7d8cc728b9386bc20af7c8e03607fad31a28b7ead", "sha256:5321e6e3481fc455818b935824d9cd78669a9bb6a964baf816d191745c8617a6" ], "version": "==0.10.3" @@ -140,10 +141,10 @@ }, "django-debug-toolbar": { "hashes": [ - "sha256:0b4d2b1ac49a8bc5604518e8e20f56c1c08c0c4873336107e7c773c42537876b", - "sha256:e9f08b94f9423ac76cfc287151182bbaddbe7521ae32bef9f9863e2ac58018d3" + "sha256:4af2a4e1e932dadbda197b18585962d4fc20172b4e5a479490bc659fe998864d", + "sha256:d9ea75659f76d8f1e3eb8f390b47fc5bad0908d949c34a8a3c4c87978eb40a0f" ], - "version": "==1.8" + "version": "==1.9.1" }, "django-favicon-plus": { "hashes": [ @@ -296,6 +297,12 @@ ], "version": "==1.0.5" }, + "mf2util": { + "hashes": [ + "sha256:efb8ea1a275f16396993a3fbe32331b74a8f6985d3f7f47503641cf522f1f614" + ], + "version": "==0.5.0" + }, "msgpack-python": { "hashes": [ "sha256:637b012c9ea021de7a7a75d6ff5e82cfef6694babd7e14bb9a3adcb2a5bd52f0", diff --git a/entries/migrations/0008_auto_20171116_2116.py b/entries/migrations/0008_auto_20171116_2116.py new file mode 100644 index 0000000..c062844 --- /dev/null +++ b/entries/migrations/0008_auto_20171116_2116.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2017-11-16 10:16 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('entries', '0007_auto_20171113_0841'), + ] + + operations = [ + migrations.RenameField( + model_name='entry', + old_name='cite', + new_name='in_reply_to', + ), + migrations.AddField( + model_name='entry', + name='like_of', + field=models.CharField(blank=True, max_length=255), + ), + migrations.AddField( + model_name='entry', + name='repost_of', + field=models.CharField(blank=True, max_length=255), + ), + ] diff --git a/entries/models.py b/entries/models.py index 2220aa2..36e0fcb 100644 --- a/entries/models.py +++ b/entries/models.py @@ -3,6 +3,7 @@ from django.contrib.sites.models import Site from django.db import models from django.urls import reverse from itertools import groupby +from mf2util import interpret from slugify import slugify from textwrap import shorten from urllib.parse import urljoin @@ -12,6 +13,7 @@ from model_utils.models import TimeStampedModel from users.models import Profile from . import kinds +from lemoncurry import requests ENTRY_KINDS = [(k.id, k.id) for k in kinds.all] @@ -34,10 +36,9 @@ class Entry(ModelMeta, TimeStampedModel): photo = models.ImageField(blank=True) content = models.TextField() - # The URL of an entry (anywhere on the web) that should become an embedded - # h-cite. Can become a u-like-of, u-repost-of, or u-in-reply-to depending - # on the post type. - cite = models.CharField(max_length=255, blank=True) + in_reply_to = models.CharField(max_length=255, blank=True) + like_of = models.CharField(max_length=255, blank=True) + repost_of = models.CharField(max_length=255, blank=True) author = models.ForeignKey( get_user_model(), @@ -45,6 +46,15 @@ class Entry(ModelMeta, TimeStampedModel): on_delete=models.CASCADE, ) + @property + def reply_context(self): + if not self.in_reply_to: + return None + return interpret( + requests.mf2(self.in_reply_to).to_dict(), + self.in_reply_to + ) + @property def published(self): return self.created diff --git a/entries/templates/entries/h-entry.html b/entries/templates/entries/h-entry.html index b825d9d..e1aac22 100644 --- a/entries/templates/entries/h-entry.html +++ b/entries/templates/entries/h-entry.html @@ -1,5 +1,18 @@ -{% load friendly_url humanize jsonify markdown shortlink %}
+{% load bleach friendly_url humanize jsonify markdown shortlink %}
{% if entry.photo %}{% endif %} + + {% if entry.in_reply_to %}{% with reply=entry.reply_context %} +
+ + {{ reply.author.name }} + +
+ {% if reply.name %}

{{ reply.name }}

{% endif %} +
{{ reply.content | bleach }}
+
+
{% endwith %}{% endif %} +
{% if entry.name %}

{{ entry.name }}

{% endif %}
{{ entry.content | markdown }}
diff --git a/lemoncurry/requests.py b/lemoncurry/requests.py index acf3d19..f4fc5eb 100644 --- a/lemoncurry/requests.py +++ b/lemoncurry/requests.py @@ -25,6 +25,10 @@ class DjangoCache(BaseCache): else: django_cache.set(key, value) + def delete(self, url): + key = self.key(url) + django_cache.delete(key) + req = CacheControl( requests.Session(), diff --git a/micropub/views.py b/micropub/views.py index 160d631..8b453eb 100644 --- a/micropub/views.py +++ b/micropub/views.py @@ -36,13 +36,13 @@ class MicropubView(View): if 'content' in post: entry.content = post['content'] if 'in-reply-to' in post: - entry.cite = post['in-reply-to'] + entry.in_reply_to = post['in-reply-to'] kind = Reply if 'like-of' in post: - entry.cite = post['like-of'] + entry.like_of = post['like-of'] kind = Like if 'repost-of' in post: - entry.cite = post['repost-of'] + entry.repost_of = post['repost-of'] kind = Repost entry.kind = kind.id