From c0b9c0e09ee45c2b61b6eecae5876bf7d97bed30 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 14 Jan 2023 09:28:42 -0500 Subject: [PATCH] fix template action link issue --- journal/templatetags/user_actions.py | 6 +- .../activity/feature_collection.html | 41 ++++++------ .../templates/activity/like_collection.html | 59 ++++++++--------- social/templates/activity/mark_item.html | 63 ++++++++++--------- social/templates/activity/review_item.html | 49 ++++++++------- 5 files changed, 113 insertions(+), 105 deletions(-) diff --git a/journal/templatetags/user_actions.py b/journal/templatetags/user_actions.py index b16eec7f..e6fe090e 100644 --- a/journal/templatetags/user_actions.py +++ b/journal/templatetags/user_actions.py @@ -19,9 +19,11 @@ def wish_item_action(context, item): @register.simple_tag(takes_context=True) def like_piece_action(context, piece): user = context["request"].user + action = {} if user and user.is_authenticated: action = { - "taken": Like.objects.filter(target=piece, owner=user).first() is not None, + "taken": piece.owner == user + or Like.objects.filter(target=piece, owner=user).first() is not None, "url": reverse("journal:like", args=[piece.uuid]), } - return action + return action diff --git a/social/templates/activity/feature_collection.html b/social/templates/activity/feature_collection.html index 800c2ad4..b059a514 100644 --- a/social/templates/activity/feature_collection.html +++ b/social/templates/activity/feature_collection.html @@ -9,12 +9,13 @@ {% load prettydate %} {% load user_actions %} -{% like_piece_action activity.action_object as action %} +{% with activity.action_object.target as collection %} +{% like_piece_action collection as action %}
- - + + - {% if not action.take %} + {% if not action.taken %} {% endif %}
@@ -24,20 +25,22 @@ {% if activity.action_object.metadata.shared_link %} - {{ activity.action_object.created_time|prettydate }} - {% else %} - {{ activity.action_object.created_time|prettydate }} - {% endif %} - - - - {{ activity.owner.display_name }} {% trans '设置了目标' %} - -
- {{ activity.action_object.target.title }} + {{ activity.action_object.created_time|prettydate }} -
-

- -

+ {% else %} + {{ activity.action_object.created_time|prettydate }} + {% endif %} + + + {{ activity.owner.display_name }} {% trans '设置了目标' %} + +
+ {{ collection.title }} + +
+

+ +

+ +{% endwith %} diff --git a/social/templates/activity/like_collection.html b/social/templates/activity/like_collection.html index ef072dca..5dc9da7d 100644 --- a/social/templates/activity/like_collection.html +++ b/social/templates/activity/like_collection.html @@ -14,7 +14,7 @@ - {% if not action.take %} + {% if not action.taken %} {% endif %} @@ -24,34 +24,35 @@ {% if activity.action_object.metadata.shared_link %} - {{ activity.action_object.created_time|prettydate }} - {% else %} - {{ activity.action_object.created_time|prettydate }} - {% endif %} - - - - {{ activity.owner.display_name }} 关注了 - {{ activity.action_object.target.owner.display_name }} - 的收藏单 - -
- {{ activity.action_object.target.title }} - {% if activity.action_object.target.year %}({{ activity.action_object.target.year }}){% endif %} + {{ activity.action_object.created_time|prettydate }} -
-

- {% if activity.review %} - {{ activity.review.title }} - {% endif %} - {% if activity.mark %} - {% if activity.mark.rating %} - + {% else %} + {{ activity.action_object.created_time|prettydate }} {% endif %} + + + + {{ activity.owner.display_name }} 关注了 + {{ activity.action_object.target.owner.display_name }} + 的收藏单 + +

+ {{ activity.action_object.target.title }} + {% if activity.action_object.target.year %}({{ activity.action_object.target.year }}){% endif %} + +
+

+ {% if activity.review %} + {{ activity.review.title }} + {% endif %} + {% if activity.mark %} + {% if activity.mark.rating %} + + {% endif %} - {% if activity.mark.text %} -

{{ activity.mark.text }}

- {% endif %} - {% endif %} -

- \ No newline at end of file + {% if activity.mark.text %} +

{{ activity.mark.text }}

+ {% endif %} + {% endif %} +

+ diff --git a/social/templates/activity/mark_item.html b/social/templates/activity/mark_item.html index 39f5de9c..87c885ba 100644 --- a/social/templates/activity/mark_item.html +++ b/social/templates/activity/mark_item.html @@ -15,7 +15,7 @@ - {% if not action.take %} + {% if not action.taken %} {% endif %} @@ -25,34 +25,35 @@ {% if activity.action_object.metadata.shared_link %} - {{ activity.action_object.created_time|prettydate }} - {% else %} - {{ activity.action_object.created_time|prettydate }} - {% endif %} - - - - {{ activity.owner.display_name }} {{ activity.action_object.mark.action_label }} + {{ activity.action_object.created_time|prettydate }} + + {% else %} + {{ activity.action_object.created_time|prettydate }} + {% endif %} -
- {{ activity.action_object.item.title }} - {% if activity.action_object.item.year %}({{ activity.action_object.item.year }}){% endif %} - - {% for res in activity.action_object.item.external_resources.all %} - - {{ res.site_name.label }} - - {% endfor %} -
-

- {% if activity.action_object.review %} - {{ activity.review.title }} - {% endif %} - {% if activity.action_object.mark.rating %} - - {% endif %} - {% if activity.action_object.mark.text %} -

{{ activity.action_object.mark.text }}

- {% endif %} -

- \ No newline at end of file + + + {{ activity.owner.display_name }} {{ activity.action_object.mark.action_label }} + +
+ {{ activity.action_object.item.title }} + {% if activity.action_object.item.year %}({{ activity.action_object.item.year }}){% endif %} + + {% for res in activity.action_object.item.external_resources.all %} + + {{ res.site_name.label }} + + {% endfor %} +
+

+ {% if activity.action_object.review %} + {{ activity.review.title }} + {% endif %} + {% if activity.action_object.mark.rating %} + + {% endif %} + {% if activity.action_object.mark.text %} +

{{ activity.action_object.mark.text }}

+ {% endif %} +

+ diff --git a/social/templates/activity/review_item.html b/social/templates/activity/review_item.html index 1a515e86..25ab0a23 100644 --- a/social/templates/activity/review_item.html +++ b/social/templates/activity/review_item.html @@ -25,30 +25,31 @@ {% if activity.action_object.metadata.shared_link %} - {{ activity.action_object.created_time|prettydate }} - {% else %} - {{ activity.action_object.created_time|prettydate }} - {% endif %} - - - - {{ activity.owner.display_name }} {% trans '评论了' %} - {{ activity.action_object.item.title }} - {% if activity.action_object.item.year %}({{ activity.action_object.item.year }}){% endif %} + {{ activity.action_object.created_time|prettydate }} + {% else %} + {{ activity.action_object.created_time|prettydate }} + {% endif %} -
- {{ activity.action_object.title }} -
-

- {% if activity.action_object.review %} - {{ activity.review.title }} - {% endif %} - {% if activity.action_object.rating_grade %} - - {% endif %} -

- -

+ + + {{ activity.owner.display_name }} {% trans '评论了' %} + {{ activity.action_object.item.title }} + {% if activity.action_object.item.year %}({{ activity.action_object.item.year }}){% endif %} + + +
+ {{ activity.action_object.title }} +
+

+ {% if activity.action_object.review %} + {{ activity.review.title }} + {% endif %} + {% if activity.action_object.rating_grade %} + + {% endif %} +

+

- \ No newline at end of file +

+