From 7952bc4820c0924ceb67169b8dee54a77b34f80a Mon Sep 17 00:00:00 2001 From: qilinz Date: Thu, 13 Jul 2023 14:44:01 +0200 Subject: [PATCH] add mark_history page. add delete all logs --- common/static/scss/_item.scss | 3 -- common/static/scss/_mark.scss | 26 ++++++++++ journal/models.py | 4 +- journal/templates/mark_history.html | 76 +++++++++++++++++++++++++++++ journal/urls.py | 3 ++ journal/views.py | 22 ++++++++- 6 files changed, 128 insertions(+), 6 deletions(-) create mode 100644 journal/templates/mark_history.html diff --git a/common/static/scss/_item.scss b/common/static/scss/_item.scss index b12380bb..1abe0245 100644 --- a/common/static/scss/_item.scss +++ b/common/static/scss/_item.scss @@ -135,9 +135,6 @@ margin: 2rem 0; } - span.log-details { - font-size: 20%; - } @media (min-width: 769px) { diff --git a/common/static/scss/_mark.scss b/common/static/scss/_mark.scss index c71851e1..fdc1c06d 100644 --- a/common/static/scss/_mark.scss +++ b/common/static/scss/_mark.scss @@ -11,6 +11,32 @@ } } +#mark-history-header { + display: flex; + align-items: center; +} + +.log-info { + margin-right: 0.5rem; +} + +#log-delete-all { + margin-left: 2rem; + margin-bottom: 1rem; + align-items: center; + display: inline; + padding: calc(var(--pico-spacing)/6); + border-radius: calc(var(--pico-spacing)/4); + border-width: 2px; + font-size: 80%; + font-weight: lighter; + word-break: keep-all; + opacity: 1; + font-weight: 400; + text-decoration: none; + white-space: nowrap; +} + @media (max-width: 768px) { .mark-line { diff --git a/journal/models.py b/journal/models.py index 3a6c72f8..2cb00207 100644 --- a/journal/models.py +++ b/journal/models.py @@ -1237,9 +1237,9 @@ class Mark: self.shelfmember.metadata["shared_link"] = None self.shelfmember.save() - def delete(self): + def delete(self, silence=False): self.logs.delete() # When deleting a mark, all logs of the mark are deleted first. - self.update(None, None, None, 0) + self.update(None, None, None, 0, silence=silence) def delete_log(self, log_id): ShelfLogEntry.objects.filter( diff --git a/journal/templates/mark_history.html b/journal/templates/mark_history.html new file mode 100644 index 00000000..71d6803e --- /dev/null +++ b/journal/templates/mark_history.html @@ -0,0 +1,76 @@ +{% load static %} +{% load i18n %} +{% load admin_url %} +{% load mastodon %} +{% load oauth_token %} +{% load truncate %} +{% load thumb %} + + + + + + {{ site_name }} - {{ item.title }} - {% trans '标记历史' %} + {% include "common_libs.html" with jquery=0 v2=1 %} + + + + {% include "_header.html" %} +
+
+
+

标记历史

+ {% if mark.logs %} +
+ {% csrf_token %} + + + + + +
+ {% endif %} +
+ {% if mark.logs %} +
+
+ {% for log in mark.logs %} +
+
+ {% csrf_token %} + + {{ log.timestamp|date }} + {{ log.action_label }} + + + + + +
+
+ {% endfor %} +
+
+ {% endif %} +
+ 返回条目 +
+ +
+ + {% include "_footer.html" %} + + diff --git a/journal/urls.py b/journal/urls.py index 050e8c39..ef4cea11 100644 --- a/journal/urls.py +++ b/journal/urls.py @@ -23,6 +23,9 @@ urlpatterns = [ path("mark/", mark, name="mark"), path("comment/", comment, name="comment"), path("mark_log//", mark_log, name="mark_log"), + path( + "mark_history/", mark_history, name="mark_history" + ), path( "add_to_collection/", add_to_collection, name="add_to_collection" ), diff --git a/journal/views.py b/journal/views.py index 5233d6fc..6fd661f4 100644 --- a/journal/views.py +++ b/journal/views.py @@ -159,7 +159,12 @@ def mark(request, item_uuid): ) elif request.method == "POST": if request.POST.get("delete", default=False): - mark.delete() + silence = request.POST.get("silence", False) + mark.delete(silence=silence) + if silence: # this means the mark is deleted from mark_history, thus redirect to item page + return redirect( + reverse("catalog:retrieve", args=[item.url_path, item.uuid]) + ) return HttpResponseRedirect(request.META.get("HTTP_REFERER")) else: visibility = int(request.POST.get("visibility", default=0)) @@ -267,6 +272,21 @@ def mark_log(request, item_uuid, log_id): raise BadRequest() +@login_required +def mark_history(request, item_uuid): + item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid)) + mark = Mark(request.user, item) + if request.method == "GET": + return render( + request, + "mark_history.html", + { + "item": item, + "mark": mark, + }, + ) + + @login_required def comment(request, item_uuid): item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))