forked from 00dani/lemoncurry
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:
parent
fb9e9a24c9
commit
e72a6b01f0
7 changed files with 78 additions and 13 deletions
30
entries/migrations/0008_auto_20171116_2116.py
Normal file
30
entries/migrations/0008_auto_20171116_2116.py
Normal 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),
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue