Start implementing reply context! It's ugly and doesn't actually link the original post yet but you *can* see the original post's author and content :3

This commit is contained in:
Danielle McLean 2017-11-16 21:52:42 +11:00
parent fb9e9a24c9
commit e72a6b01f0
Signed by: 00dani
GPG Key ID: 5A5D2D1AFF12EEC5
7 changed files with 78 additions and 13 deletions

View File

@ -43,6 +43,7 @@ django-rq = "*"
ronkyuu = "*"
cachecontrol = "*"
hiredis = "*"
"mf2util" = "*"
[dev-packages]

17
Pipfile.lock generated
View File

@ -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",

View File

@ -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),
),
]

View File

@ -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

View File

@ -1,5 +1,18 @@
{% load friendly_url humanize jsonify markdown shortlink %}<article class="card h-entry">
{% load bleach friendly_url humanize jsonify markdown shortlink %}<article class="card h-entry">
{% if entry.photo %}<img class="card-img-top u-photo" src="{{ entry.photo.url }}" />{% endif %}
{% if entry.in_reply_to %}{% with reply=entry.reply_context %}
<article class="card-header media u-in-reply-to h-cite">
<a class="align-self-center p-author h-card" href="{{ reply.author.url }}">
<img class="mr-3 rounded" width="100" src="{{ reply.author.photo }}"
alt="{{ reply.author.name }}" title="{{ reply.author.name }}" />
</a>
<div class="media-body">
{% if reply.name %}<h4 class="p-name">{{ reply.name }}</h4>{% endif %}
<div class="e-content{% if not reply.name %} p-name{% endif %}">{{ reply.content | bleach }}</div>
</div>
</article>{% endwith %}{% endif %}
<div class="card-body">
{% if entry.name %}<h4 class="card-title p-name">{{ entry.name }}</h4>{% endif %}
<div class="e-content{% if not entry.name %} p-name{% endif %}">{{ entry.content | markdown }}</div>

View File

@ -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(),

View File

@ -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