From d891a589719a53490a3a5225152ec1081457e6aa Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 31 Jan 2023 21:21:50 -0500 Subject: [PATCH] comment podcast episodes --- catalog/podcast/models.py | 14 +++- catalog/templates/common_libs.html | 6 +- catalog/templates/edition.html | 2 +- catalog/templates/item_base.html | 2 +- catalog/templates/podcast.html | 69 ++++++++++++------- catalog/templates/podcastepisode.html | 15 ++++ catalog/views.py | 6 ++ common/static/lib/css/collection.css | 30 ++++++++ journal/models.py | 7 +- journal/templates/comment.html | 83 +++++++++++++++++++++++ journal/urls.py | 1 + journal/views.py | 98 ++++++++++++++++++++++++++- mastodon/api.py | 42 +++++++++--- 13 files changed, 329 insertions(+), 46 deletions(-) create mode 100644 catalog/templates/podcastepisode.html create mode 100644 journal/templates/comment.html diff --git a/catalog/podcast/models.py b/catalog/podcast/models.py index 706991cc..939fc61b 100644 --- a/catalog/podcast/models.py +++ b/catalog/podcast/models.py @@ -54,7 +54,8 @@ class Podcast(Item): # pass class PodcastEpisode(Item): category = ItemCategory.Podcast - url_path = "podcastepisode" + url_path = "podcast/episode" + demonstrative = _("这集节目") # uid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True) program = models.ForeignKey(Podcast, models.CASCADE, related_name="episodes") guid = models.CharField(null=True, max_length=1000) @@ -67,6 +68,17 @@ class PodcastEpisode(Item): cover_url = models.CharField(null=True, max_length=1000) duration = models.PositiveIntegerField(null=True) + @property + def parent_item(self): + return self.program + + def get_absolute_url_with_position(self, position=None): + return ( + self.absolute_url + if position is None or position == "" + else f"{self.absolute_url}?position={position}" + ) + class Meta: index_together = [ [ diff --git a/catalog/templates/common_libs.html b/catalog/templates/common_libs.html index f9fa33bf..8e2264c2 100644 --- a/catalog/templates/common_libs.html +++ b/catalog/templates/common_libs.html @@ -13,9 +13,9 @@ {% endif %} {% if jquery %} - + {% else %} - + {% endif %} - + diff --git a/catalog/templates/edition.html b/catalog/templates/edition.html index af058098..e09d946c 100644 --- a/catalog/templates/edition.html +++ b/catalog/templates/edition.html @@ -10,7 +10,7 @@ {% load strip_scheme %} {% load thumb %} -{% block opengraph %} +{% block head %} {% if item.author %} {% endif %} diff --git a/catalog/templates/item_base.html b/catalog/templates/item_base.html index b7746209..211251ea 100644 --- a/catalog/templates/item_base.html +++ b/catalog/templates/item_base.html @@ -21,7 +21,7 @@ - {% block opengraph %} + {% block head %} {% endblock %} {{ site_name }} - {% trans item.category.label %} | {{ item.title }} {% include "common_libs.html" with jquery=0 %} diff --git a/catalog/templates/podcast.html b/catalog/templates/podcast.html index 10193a02..86a8ae58 100644 --- a/catalog/templates/podcast.html +++ b/catalog/templates/podcast.html @@ -10,7 +10,7 @@ {% load strip_scheme %} {% load thumb %} -{% block opengraph %} +{% block head %} {% endblock %} @@ -88,11 +88,12 @@ {% block sidebar %}
-
{% trans '最近更新' %}
+
{% trans '近期单集' %}
{% for ep in item.recent_episodes %}

- {{ ep.title }} + {{ ep.title }} +

{% endfor %}
@@ -122,37 +123,42 @@ {% endblock %} diff --git a/catalog/templates/podcastepisode.html b/catalog/templates/podcastepisode.html new file mode 100644 index 00000000..23226595 --- /dev/null +++ b/catalog/templates/podcastepisode.html @@ -0,0 +1,15 @@ +{% extends "item_base.html" %} +{% load static %} +{% load i18n %} +{% load l10n %} +{% load humanize %} +{% load admin_url %} +{% load mastodon %} +{% load oauth_token %} +{% load truncate %} +{% load strip_scheme %} +{% load thumb %} + +{% block head %} + +{% endblock %} diff --git a/catalog/views.py b/catalog/views.py index 9d13f34d..c326a1e7 100644 --- a/catalog/views.py +++ b/catalog/views.py @@ -50,6 +50,11 @@ def retrieve(request, item_path, item_uuid): return redirect(item.merged_to_item.url) if not skipcheck and item.is_deleted: return HttpResponseNotFound("item not found") + focus_item = None + if request.GET.get("focus"): + focus_item = get_object_or_404( + Item, uid=base62.decode(request.GET.get("focus")) + ) mark = None review = None mark_list = None @@ -87,6 +92,7 @@ def retrieve(request, item_path, item_uuid): item.class_name + ".html", { "item": item, + "focus_item": focus_item, "mark": mark, "review": review, "mark_list": mark_list, diff --git a/common/static/lib/css/collection.css b/common/static/lib/css/collection.css index dad807ae..987ab7e3 100644 --- a/common/static/lib/css/collection.css +++ b/common/static/lib/css/collection.css @@ -195,3 +195,33 @@ progress { .markdownx-editor { font-family: monospace; } + +.icon { + color: lightgray; +} +.icon:hover { + color: #00a1cc; +} +.comment.icon { + box-sizing: unset; + position: absolute; + margin-left: 2px; + margin-top: 4px; + width: 15px; + height: 10px; + border: solid 1px currentColor; + border-radius: 2px; +} +.comment.icon:before { + content: ''; + position: absolute; + left: 3px; + top: 8px; + width: 4px; + height: 4px; + -webkit-transform: rotate(45deg); + transform: rotate(45deg); + background-color: white; + border-bottom: solid 1px currentColor; + border-right: solid 1px currentColor; +} diff --git a/journal/models.py b/journal/models.py index 75edbfaa..c215cd1d 100644 --- a/journal/models.py +++ b/journal/models.py @@ -187,6 +187,9 @@ class Memo(Content): class Comment(Content): text = models.TextField(blank=False, null=False) + focus_item = models.ForeignKey( + Item, on_delete=models.PROTECT, null=True, related_name="focused_comments" + ) @property def html(self): @@ -950,7 +953,9 @@ class Mark: @cached_property def comment(self): - return Comment.objects.filter(owner=self.owner, item=self.item).first() + return Comment.objects.filter( + owner=self.owner, item=self.item, focus_item__isnull=True + ).first() @property def text(self): diff --git a/journal/templates/comment.html b/journal/templates/comment.html new file mode 100644 index 00000000..0c9c3b26 --- /dev/null +++ b/journal/templates/comment.html @@ -0,0 +1,83 @@ +{% load static %} +{% load i18n %} +{% load l10n %} +{% load humanize %} +{% load admin_url %} +{% load mastodon %} +{% load oauth_token %} +{% load truncate %} +{% load highlight %} +{% load thumb %} + +