From a2523fae1ce751dd4ef6d4caa8c969382d0f667c Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 17 Jul 2023 19:00:29 -0400 Subject: [PATCH] mark history: do not change actual mark when deleting history; refine some visual --- .../templates/_item_user_mark_history.html | 25 +++ catalog/templates/_item_user_pieces.html | 168 ++++++------------ common/static/scss/_common.scss | 6 + common/static/scss/_mark.scss | 50 ++---- journal/models.py | 15 +- journal/tests.py | 16 +- journal/urls.py | 2 +- journal/views.py | 9 +- 8 files changed, 123 insertions(+), 168 deletions(-) create mode 100644 catalog/templates/_item_user_mark_history.html diff --git a/catalog/templates/_item_user_mark_history.html b/catalog/templates/_item_user_mark_history.html new file mode 100644 index 00000000..856ec87f --- /dev/null +++ b/catalog/templates/_item_user_mark_history.html @@ -0,0 +1,25 @@ + +
+ +

清除标记历史不会删除或改变现有标记

+
diff --git a/catalog/templates/_item_user_pieces.html b/catalog/templates/_item_user_pieces.html index 6c0f1e96..e04e2fdc 100644 --- a/catalog/templates/_item_user_pieces.html +++ b/catalog/templates/_item_user_pieces.html @@ -4,24 +4,28 @@ 我的标签 {% if not mark.tags %} - - - + + + + + {% endif %} - - - + {% if mark.tags %} + + + + - + {% endif %}
{% for tag in mark.tags %} @@ -35,13 +39,15 @@ 我的短评 {% if not mark.comment %} - - - + + + + + {% endif %} @@ -97,10 +103,12 @@ 我的评论 {% if not review %} - - - + + + + + {% endif %} @@ -119,7 +127,7 @@ + {% if mark.review.metadata.shared_link %} href="{{ mark.review.metadata.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}> {{ mark.review.created_time|date }} @@ -134,13 +142,15 @@
我的收藏单 - - - + + + + +
@@ -154,85 +164,17 @@ {% endfor %}
-
-
- 标记历史 - {% if mark.logs %} +{% if mark.logs %} +
+
+ 标记历史 - 编辑 + + + - {% endif %} -
- {% if mark.logs %} -
    - {% for log in mark.logs %} -
  • -
    - {% csrf_token %} -
    - {{ log.timestamp|date }} - {{ log.action_label }} - - - -
    -
    -
  • - {% endfor %} -
-
- -
- {% else %} - 暂无 - {% endif %} -
- +
+
{% include '_item_user_mark_history.html' %}
+
+{% endif %} diff --git a/common/static/scss/_common.scss b/common/static/scss/_common.scss index 2ba16a24..9fa4e803 100644 --- a/common/static/scss/_common.scss +++ b/common/static/scss/_common.scss @@ -141,6 +141,12 @@ details { } } +.hide-action { + .action { + display: none !important; + } +} + form img { max-height: 20vh; } diff --git a/common/static/scss/_mark.scss b/common/static/scss/_mark.scss index bd7eaf52..f9de8e9d 100644 --- a/common/static/scss/_mark.scss +++ b/common/static/scss/_mark.scss @@ -13,50 +13,36 @@ // make log list like a timeline list // source: https://dev.to/peterc/how-to-create-joined-bulletpoint-lists-with-css-bbc-news-style-1eem -ul.log-list { +#log-list ul { + li { - list-style: disc; + list-style: none; + padding-bottom: 1rem; + border-left: 1px solid var(--pico-range-active-border-color); position: relative; - margin: 0; - padding-bottom: 0.5em; - padding-left: 0.8em; + padding-left: 0.75em; + margin-left: 1em; + margin-bottom: 0; // The actual line being placed before each list item, tweak width and color as appropriate &:before { - background-color: var(--pico-color); - width: 2px; - content: ''; + content: ""; + width: 0.5em; + height: 0.5em; + border: 1px solid var(--pico-range-active-border-color); + background: var(--pico-background-color); + border-radius: 50%; position: absolute; - top: 0; - bottom: 0; - left: -0.75em; + left: -0.275em; + top: 0.5em; } - // Start the line further down on the first list item - &:first-child:before { - top: 15px; - } - - // Stop the line short on the final list item - &:last-child:before { - height: 15px; - } - - // Hide the line when there's only one item - &:only-child:before { - content: none; + &:last-child { + padding-bottom: 0; } } } -.log-info { - margin-right: 0.5em; -} - -.log-info-container { - display: flex; - align-items: center; -} @media (max-width: 768px) { .mark-line { diff --git a/journal/models.py b/journal/models.py index 2cb00207..2a427c31 100644 --- a/journal/models.py +++ b/journal/models.py @@ -1238,23 +1238,16 @@ class Mark: self.shelfmember.save() def delete(self, silence=False): - self.logs.delete() # When deleting a mark, all logs of the mark are deleted first. + # self.logs.delete() # When deleting a mark, all logs of the mark are deleted first. self.update(None, None, None, 0, silence=silence) def delete_log(self, log_id): ShelfLogEntry.objects.filter( owner=self.owner, item=self.item, id=log_id ).delete() - last_log = ( - ShelfLogEntry.objects.exclude(shelf_type=None) - .filter(owner=self.owner, item=self.item) - .order_by("id") - .last() - ) - if not last_log: - self.update(None, None, None, 0, silence=True) - else: - self.update(last_log.shelf_type, None, None, 0, silence=True) + + def delete_all_logs(self): + self.logs.delete() @property def logs(self): diff --git a/journal/tests.py b/journal/tests.py index 64471cee..bce22287 100644 --- a/journal/tests.py +++ b/journal/tests.py @@ -105,14 +105,14 @@ class ShelfTest(TestCase): first_log = log.first() Mark(user, book1).delete_log(first_log.id) self.assertEqual(log.count(), 4) - # test delete mark -> leave one log: 移除标记 - Mark(user, book1).delete() - self.assertEqual(log.count(), 1) - # test delete all logs - shelf_manager.move_item(book1, ShelfType.PROGRESS) - self.assertEqual(log.count(), 2) - Mark(user, book1).delete(silence=True) - self.assertEqual(log.count(), 0) + # # test delete mark -> leave one log: 移除标记 + # Mark(user, book1).delete() + # self.assertEqual(log.count(), 1) + # # test delete all logs + # shelf_manager.move_item(book1, ShelfType.PROGRESS) + # self.assertEqual(log.count(), 2) + # Mark(user, book1).delete(silence=True) + # self.assertEqual(log.count(), 0) class TagTest(TestCase): diff --git a/journal/urls.py b/journal/urls.py index 050e8c39..39c78d37 100644 --- a/journal/urls.py +++ b/journal/urls.py @@ -22,7 +22,7 @@ urlpatterns = [ path("unlike/", unlike, name="unlike"), path("mark/", mark, name="mark"), path("comment/", comment, name="comment"), - path("mark_log//", mark_log, name="mark_log"), + path("mark_log//", mark_log, name="mark_log"), path( "add_to_collection/", add_to_collection, name="add_to_collection" ), diff --git a/journal/views.py b/journal/views.py index ed269c56..889b65bf 100644 --- a/journal/views.py +++ b/journal/views.py @@ -268,9 +268,12 @@ def mark_log(request, item_uuid, log_id): item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid)) mark = Mark(request.user, item) if request.method == "POST": - if request.POST.get("delete", default=False): - mark.delete_log(log_id) - return HttpResponseRedirect(request.META.get("HTTP_REFERER")) + if request.GET.get("delete", default=False): + if log_id: + mark.delete_log(log_id) + else: + mark.delete_all_logs() + return render(request, "_item_user_mark_history.html", {"mark": mark}) raise BadRequest()