add mark info to search results

This commit is contained in:
Your Name 2025-01-01 11:47:13 -05:00 committed by Henri Dickson
parent 11b2c740a2
commit 0dbc12ed62
4 changed files with 24 additions and 27 deletions

View file

@ -47,7 +47,7 @@
</div>
{% endblock full %}
</div>
{% if show_tags %}
{% if not mark and not mark.shelf %}
<div class="tag-list solo-hidden">
{% for tag in item.tags %}
{% if forloop.counter <= 5 %}

View file

@ -27,7 +27,7 @@
{% endif %}
<div class="item-card-list">
{% for item in items %}
{% include '_list_item.html' with show_tags=1 %}
{% include '_list_item.html' %}
{% empty %}
<p>
{% trans "No items matching your search query." %}
@ -50,7 +50,7 @@
</p>
<div class="item-card-list folded" id="dup">
{% for item in dup_items %}
{% include '_list_item.html' with show_tags=1 %}
{% include '_list_item.html' %}
{% endfor %}
</div>
{% endif %}

View file

@ -4,6 +4,9 @@
{% load l10n %}
{% load user_actions %}
{% load duration %}
{% if not mark %}
{% get_mark_for_item item as mark %}
{% endif %}
<article class="entity-sort item-card"
{% if collection_edit %}data-member-id="{{ collection_member.id }}"{% endif %}>
<span class="action">
@ -16,9 +19,8 @@
</a>
</span>
{% elif request.user.is_authenticated and item.class_name != 'collection' %}
{% wish_item_action item as action %}
<span>
{% if not action.taken %}
{% if not mark.shelf_type %}
<a title="{% trans "add mark" %}"
hx-get="{% url 'journal:mark' item.uuid %}?shelf_type=wishlist"
hx-target="body"
@ -41,28 +43,26 @@
{% if mark or collection_edit or collection_member.note %}
<footer>
{% if mark %}
{% if mark.action_label %}
{% if mark.shelf %}
<section>
<div class="action">
<span class="timestamp">{{ mark.created_time|date }}</span>
</div>
<span class="tag-list">
{% for tag in mark.tags %}
{% if forloop.counter <= 5 %}
<span>
<a href="{% url 'common:search' %}?c=journal&amp;q=tag:{{ tag }}">{{ tag }}</a>
</span>
{% endif %}
{% endfor %}
</span>
<div>
{% comment %} <a href="{{mark.owner.url }}" title="@{{ mark.owner.handle }}">{{ mark.owner.display_name }}</a> {% endcomment %}
<span>{{ mark.action_label }}</span>
<span>{{ mark.status_label }}</span>
{% if mark.rating_grade %}{{ mark.rating_grade|rating_star }}{% endif %}
<span>{{ mark.comment.html|safe }}</span>
</div>
{% if mark.tags %}
<div class="tag-list">
{% for tag in mark.tags %}
{% if forloop.counter <= 5 %}
<span>
<a href="{% url 'common:search' %}?tag={{ tag }}">{{ tag }}</a>
</span>
{% endif %}
{% endfor %}
</div>
{% endif %}
<div>{{ mark.comment.html|safe }}</div>
</section>
{% endif %}
{% if mark.review %}

View file

@ -1,21 +1,18 @@
from django import template
from django.urls import reverse
from journal.models.mark import Mark
from takahe.utils import Takahe
register = template.Library()
@register.simple_tag(takes_context=True)
def wish_item_action(context, item):
def get_mark_for_item(context, item):
user = context["request"].user
action = {}
if user and user.is_authenticated and item:
action = {
"taken": user.shelf_manager.locate_item(item) is not None,
"url": reverse("journal:wish", args=[item.uuid]),
}
return action
return (
Mark(user.identity, item) if user and user.is_authenticated and item else None
)
@register.simple_tag(takes_context=True)