new shelf type: dropped

This commit is contained in:
Your Name 2024-01-20 22:52:08 -05:00 committed by Henri Dickson
parent 56b2e411c7
commit fbc23a1e7f
10 changed files with 40 additions and 19 deletions

View file

@ -55,7 +55,7 @@
<div id="item-primary-action" class="right mark">
<div class="item-action item-mark-buttons">
{% for k, v in shelf_labels %}
{% if v %}
{% if v and k != 'dropped' %}
<button class="primary"
data-status="{{ k }}"
hx-get="{% url 'journal:mark' item.uuid %}?shelf_type={{ k }}"

View file

@ -1,3 +1,9 @@
.mark-editor {
[type=checkbox], [type=radio] {
margin-inline-end: .1em;
}
}
#mark_date {
width: unset !important;
}

View file

@ -257,7 +257,7 @@ class DoubanImporter:
mark.shelf_type == shelf_type
or mark.shelf_type == ShelfType.COMPLETE
or (
mark.shelf_type == ShelfType.PROGRESS
mark.shelf_type in [ShelfType.PROGRESS, ShelfType.DROPPED]
and shelf_type == ShelfType.WISHLIST
)
):

View file

@ -82,7 +82,7 @@ class LetterboxdImporter(Task):
mark.shelf_type == shelf_type
or mark.shelf_type == ShelfType.COMPLETE
or (
mark.shelf_type == ShelfType.PROGRESS
mark.shelf_type in [ShelfType.PROGRESS, ShelfType.DROPPED]
and shelf_type == ShelfType.WISHLIST
)
):

View file

@ -67,6 +67,10 @@ class Mark:
)
return ""
@property
def action_label_for_feed(self) -> str:
return re.sub(r"不(.+)了", r"不再\1", str(self.action_label)) # TODO i18n
@property
def shelf_label(self) -> str | None:
return (

View file

@ -8,7 +8,6 @@ from django.utils.translation import gettext_lazy as _
from loguru import logger
from catalog.models import Item, ItemCategory
from takahe.models import Identity, Post
from users.models import APIdentity
from .common import q_item_in_category
@ -22,33 +21,40 @@ class ShelfType(models.TextChoices):
WISHLIST = ("wishlist", "未开始")
PROGRESS = ("progress", "进行中")
COMPLETE = ("complete", "完成")
# DISCARDED = ('discarded', '放弃')
DROPPED = ("dropped", "放弃")
SHELF_LABELS = [
[ItemCategory.Book, ShelfType.WISHLIST, _("想读")],
[ItemCategory.Book, ShelfType.PROGRESS, _("在读")],
[ItemCategory.Book, ShelfType.COMPLETE, _("读过")],
[ItemCategory.Book, ShelfType.DROPPED, _("不读了")],
[ItemCategory.Movie, ShelfType.WISHLIST, _("想看")],
[ItemCategory.Movie, ShelfType.PROGRESS, _("在看")],
[ItemCategory.Movie, ShelfType.COMPLETE, _("看过")],
[ItemCategory.Movie, ShelfType.DROPPED, _("不看了")],
[ItemCategory.TV, ShelfType.WISHLIST, _("想看")],
[ItemCategory.TV, ShelfType.PROGRESS, _("在看")],
[ItemCategory.TV, ShelfType.COMPLETE, _("看过")],
[ItemCategory.TV, ShelfType.DROPPED, _("不看了")],
[ItemCategory.Music, ShelfType.WISHLIST, _("想听")],
[ItemCategory.Music, ShelfType.PROGRESS, _("在听")],
[ItemCategory.Music, ShelfType.COMPLETE, _("听过")],
[ItemCategory.Music, ShelfType.DROPPED, _("不听了")],
[ItemCategory.Game, ShelfType.WISHLIST, _("想玩")],
[ItemCategory.Game, ShelfType.PROGRESS, _("在玩")],
[ItemCategory.Game, ShelfType.COMPLETE, _("玩过")],
[ItemCategory.Game, ShelfType.DROPPED, _("不玩了")],
[ItemCategory.Podcast, ShelfType.WISHLIST, _("想听")],
[ItemCategory.Podcast, ShelfType.PROGRESS, _("在听")],
[ItemCategory.Podcast, ShelfType.COMPLETE, _("听过")],
[ItemCategory.Podcast, ShelfType.DROPPED, _("不听了")],
# disable all shelves for PodcastEpisode
[ItemCategory.Performance, ShelfType.WISHLIST, _("想看")],
# disable progress shelf for Performance
[ItemCategory.Performance, ShelfType.PROGRESS, _("")],
[ItemCategory.Performance, ShelfType.COMPLETE, _("看过")],
[ItemCategory.Performance, ShelfType.DROPPED, _("不看了")],
]
@ -82,7 +88,7 @@ class ShelfMember(ListMember):
@classmethod
def update_by_ap_object(
cls, owner: APIdentity, item: Identity, obj: dict, post_id: int, visibility: int
cls, owner: APIdentity, item: Item, obj: dict, post_id: int, visibility: int
):
p = cls.objects.filter(owner=owner, item=item).first()
if p and p.edited_time >= datetime.fromisoformat(obj["updated"]):
@ -232,12 +238,14 @@ class ShelfManager:
self.owner = owner
qs = Shelf.objects.filter(owner=self.owner)
self.shelf_list = {v.shelf_type: v for v in qs}
if len(self.shelf_list) == 0:
if len(self.shelf_list) < len(ShelfType):
self.initialize()
def initialize(self):
for qt in ShelfType:
self.shelf_list[qt] = Shelf.objects.create(owner=self.owner, shelf_type=qt)
self.shelf_list[qt] = Shelf.objects.get_or_create(
owner=self.owner, shelf_type=qt
)[0]
def locate_item(self, item: Item) -> ShelfMember | None:
return ShelfMember.objects.filter(item=item, owner=self.owner).first()

View file

@ -10,6 +10,7 @@
{% load thumb %}
{% load duration %}
<dialog open
class="mark-editor"
_="on close_dialog add .closing then wait for animationend then remove me">
<article>
<header>
@ -19,7 +20,7 @@
_="on click trigger close_dialog" />
<strong>标记 {{ item.title }}</strong>
</header>
<div class="add-to-list-modal__body">
<div>
<form method="post" action="{% url 'journal:mark' item.uuid %}">
{% csrf_token %}
{% if shelf_labels %}
@ -33,7 +34,7 @@
value="{{ k }}"
required
id="id_status_{{ k }}"
{% if k == "wishlist" %} _="on click add .hidden to .rating-editor" {% else %} _="on click remove .hidden from .rating-editor" {% endif %}
{% if k == "wishlist" or k == "dropped" %} _="on click add .hidden to .rating-editor" {% else %} _="on click remove .hidden from .rating-editor" {% endif %}
{% if shelf_type == k %}checked=""{% endif %}>
<label for="id_status_{{ k }}">{{ v }}</label>
{% endif %}
@ -70,7 +71,7 @@
id="id_text">{{ mark.comment_text|default:"" }}</textarea>
</fieldset>
</div>
<div class="mark-modal__tag">
<div>
<div class="tag-input">
<input name="tags"
type="text"

View file

@ -42,6 +42,8 @@ def profile(request: AuthedHttpRequest, user_name):
for category in visbile_categories:
shelf_list[category] = {}
for shelf_type in ShelfType:
if shelf_type == ShelfType.DROPPED:
continue
label = target.shelf_manager.get_label(shelf_type, category)
if label is not None:
members = target.shelf_manager.get_latest_members(

View file

@ -36,7 +36,7 @@
{% endif %}
</span>
<div class="spacing">
{{ activity.action_object.mark.action_label }}
{{ activity.action_object.mark.action_label_for_feed }}
{% comment %} {{ activity.action_object.item.title }} {% endcomment %}
{% if activity.action_object.mark.rating_grade %}
{{ activity.action_object.mark.rating_grade | rating_star }}

View file

@ -548,7 +548,9 @@ class Takahe:
action_label = "创建"
category = "收藏单"
item_link = collection.absolute_url
pre_conetent = f'{action_label}{category}<a href="{item_link}">《{collection.title}》</a><br>'
pre_conetent = (
f'{action_label}{category} <a href="{item_link}">{collection.title}</a><br>'
)
content = collection.plain_content
if len(content) > 360:
content = content[:357] + "..."
@ -587,7 +589,7 @@ class Takahe:
)
item_link = f"{settings.SITE_INFO['site_url']}/~neodb~{comment.item_url}"
action_label = "评论" if comment.text else "分享"
pre_conetent = f'{action_label}{category}<a href="{item_link}">{comment.item.display_title}</a><br>'
pre_conetent = f'{action_label}{category} <a href="{item_link}">{comment.item.display_title}</a><br>'
spoiler, txt = Takahe.get_spoiler_text(comment.text, comment.item)
content = f"{txt}\n{tags}"
data = {
@ -630,7 +632,7 @@ class Takahe:
stars = _rating_to_emoji(review.rating_grade, 1)
item_link = f"{settings.SITE_INFO['site_url']}/~neodb~{review.item.url}"
pre_conetent = f'发布了关于<a href="{item_link}">{review.item.display_title}</a>的评论:<br><a href="{review.absolute_url}">{review.title}</a>'
pre_conetent = f'发布了关于 <a href="{item_link}">{review.item.display_title}</a> 的评论:<br><a href="{review.absolute_url}">{review.title}</a>'
content = f"{stars}\n{tags}"
data = {
"object": {
@ -671,10 +673,8 @@ class Takahe:
)
stars = _rating_to_emoji(mark.rating_grade, 1)
item_link = f"{settings.SITE_INFO['site_url']}/~neodb~{mark.item.url}"
pre_conetent = (
f'{mark.action_label}<a href="{item_link}">《{mark.item.display_title}》</a>'
)
action = mark.action_label_for_feed
pre_conetent = f'{action} <a href="{item_link}">{mark.item.display_title}</a>'
spoiler, txt = Takahe.get_spoiler_text(mark.comment_text, mark.item)
content = f"{stars} \n{txt}\n{tags}"
data = {