From c796072f9abd756c82e4a567613a0ad038808417 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 9 Apr 2024 00:45:40 -0400 Subject: [PATCH] update works: ui --- catalog/book/models.py | 9 +++ catalog/sites/douban_book.py | 1 + .../templates/_item_card_metadata_work.html | 21 +++++ catalog/templates/_item_user_pieces.html | 2 +- catalog/templates/_sidebar_edit.html | 76 ++++++++++++++----- catalog/templates/catalog_merge.html | 18 +++-- catalog/templates/item_base.html | 15 ++++ catalog/templates/work.html | 1 + catalog/urls.py | 14 ++++ catalog/views_edit.py | 54 ++++++++++++- 10 files changed, 184 insertions(+), 27 deletions(-) create mode 100644 catalog/templates/_item_card_metadata_work.html diff --git a/catalog/book/models.py b/catalog/book/models.py index 5f3e32b9..0bc573b2 100644 --- a/catalog/book/models.py +++ b/catalog/book/models.py @@ -245,6 +245,15 @@ class Work(Item): # a lazy fix is to remove smaller DoubanBook_Work ids # but ideally deal with 302 in scrape(). + @classmethod + def lookup_id_type_choices(cls): + id_types = [ + IdType.DoubanBook_Work, + IdType.Goodreads_Work, + IdType.WikiData, + ] + return [(i.value, i.label) for i in id_types] + def merge_to(self, to_item): super().merge_to(to_item) for edition in self.editions.all(): diff --git a/catalog/sites/douban_book.py b/catalog/sites/douban_book.py index 054292d6..ee2b4272 100644 --- a/catalog/sites/douban_book.py +++ b/catalog/sites/douban_book.py @@ -238,6 +238,7 @@ def scrape(self): @SiteManager.register class DoubanBook_Work(AbstractSite): + SITE_NAME = SiteName.Douban ID_TYPE = IdType.DoubanBook_Work URL_PATTERNS = [r"\w+://book\.douban\.com/works/(\d+)"] WIKI_PROPERTY_ID = "?" diff --git a/catalog/templates/_item_card_metadata_work.html b/catalog/templates/_item_card_metadata_work.html new file mode 100644 index 00000000..40e93fa5 --- /dev/null +++ b/catalog/templates/_item_card_metadata_work.html @@ -0,0 +1,21 @@ +{% extends "_item_card_metadata_base.html" %} +{% load humanize %} +{% load i18n %} +{% block brief %} +
+ {% if item.rating %} + {{ item.rating | floatformat:1 }} ({{ item.rating_count }}人评分) + {% endif %} + {% include '_people.html' with people=item.author role='作者' max=2 %} +
+{% endblock brief %} +{% block full %} +
+ {% if item.other_title %} + {% include '_people.html' with people=item.other_title role='又名' max=5 %} + {% endif %} +
+
+ {% if not hide_brief %}{{ item.brief | linebreaksbr }}{% endif %} +
+{% endblock full %} diff --git a/catalog/templates/_item_user_pieces.html b/catalog/templates/_item_user_pieces.html index c7919dbf..1ca2b7ee 100644 --- a/catalog/templates/_item_user_pieces.html +++ b/catalog/templates/_item_user_pieces.html @@ -134,7 +134,7 @@
我的收藏单 - + 编辑选项
{% endif %} {% endif %} + {% if item.class_name == 'edition' %} + {% if item.has_works %} +
+ {% trans '著作' %} + 这个图书版本属于以下著作 + {% for i in item.works.all %} +
  • + {{ i.title }} +
  • + {% endfor %} +
    + {% csrf_token %} + +
    +
    + {% endif %} + {% if not item.has_works %} +
    + {% trans '关联' %} +
    + {% csrf_token %} + + +
    +
    + {% endif %} + {% endif %} + {% endif %} +
    + {% trans '修改建议' %} +
    + {% csrf_token %} + + + + 本站由用户共同维护,用户可自主修改部分条目信息。当你不确定自己的修改是否得当或不能做出某种修改时,可在此处向管理员提出建议。管理员会认真考虑处理每一条建议,虽然不保证总是完全采纳;建议也可能被社区其他用户查看或讨论。如果有与具体条目不相关的建议,请访问讨论区或联系我们的社交账号。感谢你的支持和贡献。 +
    +
    {% endif %} -
    - {% trans '修改建议' %} -
    - {% csrf_token %} - - - - 本站由用户共同维护,用户可自主修改部分条目信息。当你不确定自己的修改是否得当或不能做出某种修改时,可在此处向管理员提出建议。管理员会认真考虑处理每一条建议,虽然不保证总是完全采纳;建议也可能被社区其他用户查看或讨论。如果有与具体条目不相关的建议,请访问讨论区或联系我们的社交账号。感谢你的支持和贡献。 -
    -
    -{% endif %} diff --git a/catalog/templates/catalog_merge.html b/catalog/templates/catalog_merge.html index 135d9761..75ae9339 100644 --- a/catalog/templates/catalog_merge.html +++ b/catalog/templates/catalog_merge.html @@ -19,14 +19,20 @@ {% include "_header.html" %}

    - {% if new_item %} - {% trans 'Are you sure to merge?' %} - {% else %} - {% trans 'Are you sure to cancel merge?' %} + {% if mode == "merge" %} + {% if new_item %} + {% trans 'Are you sure to merge?' %} + {% else %} + {% trans 'Are you sure to cancel merge?' %} + {% endif %} + {% elif mode == "link" %} + {% trans 'Are you sure to link?' %} {% endif %}

    -
    {% include "_item_card.html" with item=item %}
    +
    + {% include "_item_card.html" with item=item %} +
    {% if item.is_deleted %}

    条目已被删除 @@ -78,7 +84,7 @@

    {% endif %}

    {% csrf_token %} {% endif %} {% endfor %} +