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

View file

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

View file

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

View file

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