Skip to content

Commit

Permalink
update works: ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and alphatownsman committed Apr 9, 2024
1 parent 86834ed commit c796072
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 27 deletions.
9 changes: 9 additions & 0 deletions catalog/book/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions catalog/sites/douban_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "?"
Expand Down
21 changes: 21 additions & 0 deletions catalog/templates/_item_card_metadata_work.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "_item_card_metadata_base.html" %}
{% load humanize %}
{% load i18n %}
{% block brief %}
<div class="multi-fields">
{% if item.rating %}
<span class="solo-hidden">{{ item.rating | floatformat:1 }} <small>({{ item.rating_count }}人评分)</small></span>
{% endif %}
{% include '_people.html' with people=item.author role='作者' max=2 %}
</div>
{% endblock brief %}
{% block full %}
<div class="multi-fields">
{% if item.other_title %}
{% include '_people.html' with people=item.other_title role='又名' max=5 %}
{% endif %}
</div>
<div>
{% if not hide_brief %}{{ item.brief | linebreaksbr }}{% endif %}
</div>
{% endblock full %}
2 changes: 1 addition & 1 deletion catalog/templates/_item_user_pieces.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h5>
<h5>
我的收藏单
<small>
<span class="action inline">
<span class="action inline item-mark-icon">
<a href="#"
hx-get="{% url 'journal:add_to_collection' item.uuid %}"
class="edit"
Expand Down
76 changes: 57 additions & 19 deletions catalog/templates/_sidebar_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,61 @@ <h5>编辑选项</h5>
</details>
{% endif %}
{% endif %}
{% if item.class_name == 'edition' %}
{% if item.has_works %}
<details>
<summary>{% trans '著作' %}</summary>
这个图书版本属于以下著作
{% for i in item.works.all %}
<li>
<a href="{{ i.url }}?skipcheck=1">{{ i.title }}</a>
</li>
{% endfor %}
<form method="post"
onsubmit="return confirm('本操作不可撤销。确认吗?');"
action="{% url 'catalog:unlink_works' item.url_path item.uuid %}">
{% csrf_token %}
<input class="contrast"
type="submit"
{% if not request.user.is_staff %}disabled{% endif %}
value="{% trans '取消关联到上述著作' %}">
</form>
</details>
{% endif %}
{% if not item.has_works %}
<details>
<summary>{% trans '关联' %}</summary>
<form method="post"
action="{% url 'catalog:link_edition' item.url_path item.uuid %}">
{% csrf_token %}
<input type="url"
name="target_item_url"
placeholder="{{ site_url }}/book/1234/
{% if item.is_deleted and not item.merged_to_item %}disabled{% endif %}
value="">
<input class="contrast" type="submit" value="{% trans '关联到同一著作的另一本书' %}">
</form>
</details>
{% endif %}
{% endif %}
{% endif %}
<details>
<summary>{% trans '修改建议' %}</summary>
<form method="post"
action="{% url 'catalog:suggest' item.url_path item.uuid %}">
{% csrf_token %}
<select name="action" aria-label="Select action..." required>
<option selected disabled value="">请选择建议类型...</option>
<option value="merge">合并到其它条目</option>
<option value="link">关联到其它条目</option>
<option value="type">更改条目类型</option>
<option value="metadata">更正条目信息</option>
<option value="delete">删除条目</option>
<option value="other">其它修改</option>
</select>
<textarea name="detail" required placeholder="建议详情。如提议合并或关联,请包含目标条目网址。"></textarea>
<input type="submit" value="{% trans '提交' %}">
<small>本站由用户共同维护,用户可自主修改部分条目信息。当你不确定自己的修改是否得当或不能做出某种修改时,可在此处向管理员提出建议。管理员会认真考虑处理每一条建议,虽然不保证总是完全采纳;建议也可能被社区其他用户查看或讨论。如果有与具体条目不相关的建议,请访问讨论区或联系我们的社交账号。感谢你的支持和贡献。</small>
</form>
</details>
{% endif %}
<details>
<summary>{% trans '修改建议' %}</summary>
<form method="post"
action="{% url 'catalog:suggest' item.url_path item.uuid %}">
{% csrf_token %}
<select name="action" aria-label="Select action..." required>
<option selected disabled value="">请选择建议类型...</option>
<option value="merge">合并到其它条目</option>
<option value="type">更改条目类型</option>
<option value="metadata">更正条目信息</option>
<option value="delete">删除条目</option>
<option value="other">其它修改</option>
</select>
<textarea name="detail" required placeholder="建议详情。如提议合并,请包含合并目标条目网址。"></textarea>
<input type="submit" value="{% trans '提交' %}">
<small>本站由用户共同维护,用户可自主修改部分条目信息。当你不确定自己的修改是否得当或不能做出某种修改时,可在此处向管理员提出建议。管理员会认真考虑处理每一条建议,虽然不保证总是完全采纳;建议也可能被社区其他用户查看或讨论。如果有与具体条目不相关的建议,请访问讨论区或联系我们的社交账号。感谢你的支持和贡献。</small>
</form>
</details>
{% endif %}
18 changes: 12 additions & 6 deletions catalog/templates/catalog_merge.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@
{% include "_header.html" %}
<main class="container">
<h2>
{% 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 %}
</h2>
<div>
<article class="item-card deleting">{% include "_item_card.html" with item=item %}</article>
<article class="item-card {% if mode == 'merge' %}deleting{% endif %}">
{% include "_item_card.html" with item=item %}
</article>
{% if item.is_deleted %}
<p>
<i class="fa-solid fa-circle-xmark"></i> 条目已被删除
Expand Down Expand Up @@ -78,7 +84,7 @@ <h2>
{% endif %}
</div>
<form method="post"
action="{% url 'catalog:merge' item.url_path item.uuid %}"
{% if mode == "merge" %} action="{% url 'catalog:merge' item.url_path item.uuid %}" {% elif mode == "link" %} action="{% url 'catalog:link_edition' item.url_path item.uuid %}" {% endif %}
onsubmit="return confirm('本操作不可撤销。确认吗?');">
{% csrf_token %}
<input type="hidden"
Expand Down
15 changes: 15 additions & 0 deletions catalog/templates/item_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ <h1>
{% endif %}
{% endfor %}
</div>
<div class="work-tip" style="display:none;">
{% if item.class_name == 'work' %}
<div _="init hide .item-mark-buttons then hide .item-mark-icon then show .work-tip end">
<details open>
<summary>{% trans '本著作包含以下图书版本' %}</summary>
{% for b in item.editions.all %}
<div>
<a href="{{ b.url }}">{{ b.title }}</a>
<small>({{ b.pub_house | default:'' }} {{ b.pub_year | default:'' }})</small>
</div>
{% endfor %}
</details>
</div>
{% endif %}
</div>
<div class="tv-tip" style="display:none;">
这是全剧条目,以下是可标记的单季
{% if item.class_name == 'tvshow' %}
Expand Down
1 change: 1 addition & 0 deletions catalog/templates/work.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
{% load thumb %}
<!-- class specific details -->
{% block details %}{% endblock %}
{% block left_sidebar %}{% endblock %}
<!-- class specific sidebar -->
{% block sidebar %}{% endblock %}
14 changes: 14 additions & 0 deletions catalog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ def _get_all_url_paths():
merge,
name="merge",
),
re_path(
r"^(?P<item_path>"
+ _get_all_url_paths()
+ ")/(?P<item_uuid>[A-Za-z0-9]{21,22})/link_edition$",
link_edition,
name="link_edition",
),
re_path(
r"^(?P<item_path>"
+ _get_all_url_paths()
+ ")/(?P<item_uuid>[A-Za-z0-9]{21,22})/unlink_works$",
unlink_works,
name="unlink_works",
),
re_path(
r"^(?P<item_path>"
+ _get_all_url_paths()
Expand Down
54 changes: 53 additions & 1 deletion catalog/views_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ def merge(request, item_path, item_uuid):
if request.POST.get("sure", 0) != "1":
new_item = Item.get_by_url(request.POST.get("target_item_url"))
return render(
request, "catalog_merge.html", {"item": item, "new_item": new_item}
request,
"catalog_merge.html",
{"item": item, "new_item": new_item, "mode": "merge"},
)
elif request.POST.get("target_item_url"):
new_item = Item.get_by_url(request.POST.get("target_item_url"))
Expand Down Expand Up @@ -313,6 +315,56 @@ def merge(request, item_path, item_uuid):
return redirect(item.url)


@require_http_methods(["POST"])
@login_required
def link_edition(request, item_path, item_uuid):
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
new_item = Item.get_by_url(request.POST.get("target_item_url"))
if (
not new_item
or new_item.is_deleted
or new_item.merged_to_item_id
or item == new_item
):
raise BadRequest(_("Cannot be linked to an item already deleted or merged"))
if item.class_name != "edition" or new_item.class_name != "edition":
raise BadRequest(_("Cannot link items other than editions"))
if request.POST.get("sure", 0) != "1":
new_item = Item.get_by_url(request.POST.get("target_item_url"))
return render(
request,
"catalog_merge.html",
{"item": item, "new_item": new_item, "mode": "link"},
)
_logger.warn(f"{request.user} merges {item} to {new_item}")
item.link_to_related_book(new_item)
discord_send(
"audit",
f"{item.absolute_url}?skipcheck=1\n\n{new_item.absolute_url}\nby [@{request.user.username}]({request.user.absolute_url})",
thread_name=f"[link edition] {item.display_title}",
username=f"@{request.user.username}",
)
return redirect(item.url)


@require_http_methods(["POST"])
@login_required
def unlink_works(request, item_path, item_uuid):
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
if not request.user.is_staff and item.journal_exists():
raise PermissionDenied()
item.unlink_from_all_works()
discord_send(
"audit",
f"{item.absolute_url}?skipcheck=1\nby [@{request.user.username}]({request.user.absolute_url})",
thread_name=f"[unlink works] {item.display_title}",
username=f"@{request.user.username}",
)
return (
redirect(item.url + "?skipcheck=1") if request.user.is_staff else redirect("/")
)


@require_http_methods(["POST"])
@login_required
def suggest(request, item_path, item_uuid):
Expand Down

0 comments on commit c796072

Please sign in to comment.