More templatetag files

This commit is contained in:
Mouse Reeve 2021-05-11 15:14:42 -07:00
parent 58da17d694
commit ac2b63d0cd
40 changed files with 107 additions and 92 deletions

View file

@ -1,6 +1,6 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load markdown %}
{% load humanize %} {% load humanize %}
{% block title %}{{ author.name }}{% endblock %} {% block title %}{{ author.name }}{% endblock %}
@ -66,7 +66,7 @@
{% endif %} {% endif %}
<div class="column"> <div class="column">
{% if author.bio %} {% if author.bio %}
{{ author.bio | to_markdown | safe }} {{ author.bio|to_markdown|safe }}
{% endif %} {% endif %}
</div> </div>
</div> </div>

View file

@ -257,7 +257,7 @@
{% include 'snippets/stars.html' with rating=rating.rating %} {% include 'snippets/stars.html' with rating=rating.rating %}
</div> </div>
<div> <div>
<a href="{{ rating.remote_id }}">{{ rating.published_date | naturaltime }}</a> <a href="{{ rating.remote_id }}">{{ rating.published_date|naturaltime }}</a>
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,6 +1,5 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %}
{% block title %}{% blocktrans with book_title=work.title %}Editions of {{ book_title }}{% endblocktrans %}{% endblock %} {% block title %}{% blocktrans with book_title=work.title %}Editions of {{ book_title }}{% endblocktrans %}{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load utilities %}
{% block title %}{% trans "Compose status" %}{% endblock %} {% block title %}{% trans "Compose status" %}{% endblock %}
{% block content %} {% block content %}

View file

@ -1,5 +1,6 @@
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load utilities %}
{% load markdown %}
{% load humanize %} {% load humanize %}
<div class="card is-stretchable"> <div class="card is-stretchable">
@ -19,7 +20,7 @@
<div> <div>
{% if user.summary %} {% if user.summary %}
{{ user.summary | to_markdown | safe | truncatechars_html:40 }} {{ user.summary|to_markdown|safe|truncatechars_html:40 }}
{% else %}&nbsp;{% endif %} {% else %}&nbsp;{% endif %}
</div> </div>
</div> </div>

View file

@ -1,6 +1,6 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load markdown %}
{% block title %}{% trans "Welcome" %}{% endblock %} {% block title %}{% trans "Welcome" %}{% endblock %}
@ -49,7 +49,7 @@
{% else %} {% else %}
<h2 class="title">{% trans "This instance is closed" %}</h2> <h2 class="title">{% trans "This instance is closed" %}</h2>
<p>{{ site.registration_closed_text | safe}}</p> <p>{{ site.registration_closed_text|safe}}</p>
{% if site.allow_invite_requests %} {% if site.allow_invite_requests %}
{% if request_received %} {% if request_received %}
@ -64,7 +64,7 @@
<label for="id_request_email" class="label">{% trans "Email address:" %}</label> <label for="id_request_email" class="label">{% trans "Email address:" %}</label>
<input type="email" name="email" maxlength="255" class="input" required="" id="id_request_email"> <input type="email" name="email" maxlength="255" class="input" required="" id="id_request_email">
{% for error in request_form.email.errors %} {% for error in request_form.email.errors %}
<p class="help is-danger">{{ error | escape }}</p> <p class="help is-danger">{{ error|escape }}</p>
{% endfor %} {% endfor %}
</div> </div>
<button type="submit" class="button is-link">{% trans "Submit" %}</button> <button type="submit" class="button is-link">{% trans "Submit" %}</button>
@ -80,7 +80,7 @@
{% include 'user/user_preview.html' with user=request.user %} {% include 'user/user_preview.html' with user=request.user %}
{% if request.user.summary %} {% if request.user.summary %}
<div class="box content"> <div class="box content">
{{ request.user.summary | to_markdown | safe }} {{ request.user.summary|to_markdown|safe }}
</div> </div>
{% endif %} {% endif %}
</div> </div>

View file

@ -1,5 +1,5 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% load markdown %}
{% load i18n %} {% load i18n %}
{% if book %} {% if book %}

View file

@ -1,7 +1,6 @@
{% extends 'feed/feed_layout.html' %} {% extends 'feed/feed_layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %}
{% load humanize %}
{% block panel %} {% block panel %}
<h1 class="title"> <h1 class="title">

View file

@ -1,6 +1,5 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %}
{% block title %}{% trans "Updates" %}{% endblock %} {% block title %}{% trans "Updates" %}{% endblock %}

View file

@ -1,4 +1,4 @@
{% load bookwyrm_tags %} {% load status_display %}
<div class="block"> <div class="block">
{% with depth=depth|add:1 %} {% with depth=depth|add:1 %}

View file

@ -1,12 +1,13 @@
{% extends 'lists/list_layout.html' %} {% extends 'lists/list_layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% load markdown %}
{% block panel %} {% block panel %}
{% if request.user == list.user and pending_count %} {% if request.user == list.user and pending_count %}
<div class="block content"> <div class="block content">
<p> <p>
<a href="{% url 'list-curate' list.id %}">{{ pending_count }} book{{ pending_count | pluralize }} awaiting your approval</a> <a href="{% url 'list-curate' list.id %}">{{ pending_count }} book{{ pending_count|pluralize }} awaiting your approval</a>
</p> </p>
</div> </div>
{% endif %} {% endif %}

View file

@ -1,4 +1,4 @@
{% load bookwyrm_tags %} {% load markdown %}
<div class="columns is-multiline"> <div class="columns is-multiline">
{% for list in lists %} {% for list in lists %}
<div class="column is-one-quarter"> <div class="column is-one-quarter">

View file

@ -1,6 +1,5 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %}
{% block title %}{{ list.name }}{% endblock %} {% block title %}{{ list.name }}{% endblock %}

View file

@ -1,5 +1,5 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load bookwyrm_tags %} {% load utilities %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans "Lists" %}{% endblock %} {% block title %}{% trans "Lists" %}{% endblock %}

View file

@ -1,6 +1,5 @@
{% extends 'settings/admin_layout.html' %} {% extends 'settings/admin_layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %}
{% load humanize %} {% load humanize %}
{% block title %}{% blocktrans with report_id=report.id username=report.user.username %}Report #{{ report_id }}: {{ username }}{% endblocktrans %}{% endblock %} {% block title %}{% blocktrans with report_id=report.id username=report.user.username %}Report #{{ report_id }}: {{ username }}{% endblocktrans %}{% endblock %}
@ -29,7 +28,7 @@
<a href="{{ comment.user.local_path }}">{{ comment.user.display_name }}</a> <a href="{{ comment.user.local_path }}">{{ comment.user.display_name }}</a>
</div> </div>
<div class="card-footer-item"> <div class="card-footer-item">
{{ comment.created_date | naturaltime }} {{ comment.created_date|naturaltime }}
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,7 +1,7 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load i18n %} {% load i18n %}
{% load humanize %}
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% load humanize %}
{% block title %}{% trans "Notifications" %}{% endblock %} {% block title %}{% trans "Notifications" %}{% endblock %}

View file

@ -1,5 +1,4 @@
{% extends 'search/layout.html' %} {% extends 'search/layout.html' %}
{% load bookwyrm_tags %}
{% block panel %} {% block panel %}

View file

@ -1,7 +1,8 @@
{% extends 'settings/admin_layout.html' %} {% extends 'settings/admin_layout.html' %}
{% block title %}{{ server.server_name }}{% endblock %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load markdown %}
{% block title %}{{ server.server_name }}{% endblock %}
{% block header %} {% block header %}
{{ server.server_name }} {{ server.server_name }}

View file

@ -1,3 +1,2 @@
{% load bookwyrm_tags %}
<img class="avatar image {% if large %}is-96x96{% elif medium %}is-48x48{% else %}is-32x32{% endif %}" src="{% if user.avatar %}/images/{{ user.avatar }}{% else %}/static/images/default_avi.jpg{% endif %}" {% if ariaHide %}aria-hidden="true"{% endif %} alt="{{ user.alt_text }}"> <img class="avatar image {% if large %}is-96x96{% elif medium %}is-48x48{% else %}is-32x32{% endif %}" src="{% if user.avatar %}/images/{{ user.avatar }}{% else %}/static/images/default_avi.jpg{% endif %}" {% if ariaHide %}aria-hidden="true"{% endif %} alt="{{ user.alt_text }}">

View file

@ -1,6 +1,5 @@
{% spaceless %} {% spaceless %}
{% load bookwyrm_tags %}
{% load i18n %} {% load i18n %}
<figure <figure

View file

@ -1,5 +1,5 @@
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load utilities %}
{% if book.authors %} {% if book.authors %}
{% blocktrans with path=book.local_path title=book|title %}<a href="{{ path }}">{{ title }}</a> by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %} {% blocktrans with path=book.local_path title=book|title %}<a href="{{ path }}">{{ title }}</a> by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %}
{% else %} {% else %}

View file

@ -1,5 +1,6 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% load utilities %} {% load utilities %}
{% load status_display %}
{% load i18n %} {% load i18n %}
<form class="is-flex-grow-1" name="{{ type }}" action="/post/{% if type == 'direct' %}status{% else %}{{ type }}{% endif %}" method="post" id="tab-{{ type }}-{{ book.id }}{{ reply_parent.id }}"> <form class="is-flex-grow-1" name="{{ type }}" action="/post/{% if type == 'direct' %}status{% else %}{{ type }}{% endif %}" method="post" id="tab-{{ type }}-{{ book.id }}{{ reply_parent.id }}">

View file

@ -1,6 +1,5 @@
{% spaceless %} {% spaceless %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %}
<div class=" <div class="
field is-grouped field is-grouped

View file

@ -1,5 +1,6 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% load utilities %} {% load utilities %}
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
{% with book.id|uuid as uuid %} {% with book.id|uuid as uuid %}

View file

@ -1,4 +1,5 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% load markdown %}
{% load i18n %} {% load i18n %}
{% with status_type=status.status_type %} {% with status_type=status.status_type %}

View file

@ -1,6 +1,7 @@
{% spaceless %} {% spaceless %}
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% load markdown %}
{% load i18n %} {% load i18n %}
{% if not hide_book %} {% if not hide_book %}

View file

@ -1,5 +1,6 @@
{% load bookwyrm_tags %} {% load status_display %}
{% load i18n %} {% load i18n %}
{% if not status.deleted %} {% if not status.deleted %}
{% if status.status_type == 'Announce' %} {% if status.status_type == 'Announce' %}
<a href="{{ status.user.local_path }}"> <a href="{{ status.user.local_path }}">

View file

@ -1,4 +1,5 @@
{% load bookwyrm_tags %} {% load utilities %}
{% load status_display %}
{% load i18n %} {% load i18n %}
{% load humanize %} {% load humanize %}
@ -29,7 +30,7 @@
</span> </span>
{% if status.status_type == 'GeneratedNote' %} {% if status.status_type == 'GeneratedNote' %}
{{ status.content | safe }} {{ status.content|safe }}
{% elif status.status_type == 'Rating' %} {% elif status.status_type == 'Rating' %}
{% trans "rated" %} {% trans "rated" %}
{% elif status.status_type == 'Review' %} {% elif status.status_type == 'Review' %}

View file

@ -1,4 +1,4 @@
{% load bookwyrm_tags %} {% load markdown %}
{% load utilities %} {% load utilities %}
{% load i18n %} {% load i18n %}

View file

@ -1,6 +1,6 @@
{% extends 'components/dropdown.html' %} {% extends 'components/dropdown.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load utilities %}
{% block dropdown-trigger %} {% block dropdown-trigger %}
<span class="icon icon-dots-three"> <span class="icon icon-dots-three">

View file

@ -1,7 +1,8 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% load i18n %} {% load i18n %}
{% load humanize %} {% load humanize %}
{% load bookwyrm_tags %} {% load utilities %}
{% load markdown %}
{% block title %}{{ user.display_name }}{% endblock %} {% block title %}{{ user.display_name }}{% endblock %}
@ -23,7 +24,7 @@
{% if user.summary %} {% if user.summary %}
<div class="column box has-background-white-bis content"> <div class="column box has-background-white-bis content">
{{ user.summary | to_markdown | safe }} {{ user.summary|to_markdown|safe }}
</div> </div>
{% endif %} {% endif %}
</div> </div>

View file

@ -1,6 +1,6 @@
{% extends 'user/layout.html' %} {% extends 'user/layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load utilities %}
{% block tabs %} {% block tabs %}
{% with user|username as username %} {% with user|username as username %}

View file

@ -1,5 +1,5 @@
{% extends 'user/layout.html' %} {% extends 'user/layout.html' %}
{% load bookwyrm_tags %} {% load utilities %}
{% load humanize %} {% load humanize %}
{% load i18n %} {% load i18n %}
@ -101,14 +101,14 @@
{% include 'snippets/authors.html' %} {% include 'snippets/authors.html' %}
</td> </td>
<td data-title="{% trans "Shelved" %}"> <td data-title="{% trans "Shelved" %}">
{{ book.created_date | naturalday }} {{ book.created_date|naturalday }}
</td> </td>
{% latest_read_through book user as read_through %} {% latest_read_through book user as read_through %}
<td data-title="{% trans "Started" %}"> <td data-title="{% trans "Started" %}">
{{ read_through.start_date | naturalday |default_if_none:""}} {{ read_through.start_date|naturalday|default_if_none:""}}
</td> </td>
<td data-title="{% trans "Finished" %}"> <td data-title="{% trans "Finished" %}">
{{ read_through.finish_date | naturalday |default_if_none:""}} {{ read_through.finish_date|naturalday|default_if_none:""}}
</td> </td>
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<td data-title="{% trans "Rating" %}"> <td data-title="{% trans "Rating" %}">

View file

@ -1,6 +1,6 @@
{% extends 'user/layout.html' %} {% extends 'user/layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load utilities %}
{% block title %}{{ user.display_name }}{% endblock %} {% block title %}{{ user.display_name }}{% endblock %}

View file

@ -1,5 +1,6 @@
{% load i18n %} {% load i18n %}
{% load humanize %} {% load humanize %}
{% load utilities %}
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
<div class="media block"> <div class="media block">

View file

@ -1,7 +1,5 @@
{% extends 'settings/admin_layout.html' %} {% extends 'settings/admin_layout.html' %}
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %}
{% load humanize %}
{% block title %}{{ user.username }}{% endblock %} {% block title %}{{ user.username }}{% endblock %}
{% block header %}{{ user.username }}{% endblock %} {% block header %}{{ user.username }}{% endblock %}

View file

@ -1,5 +1,5 @@
{% load i18n %} {% load i18n %}
{% load bookwyrm_tags %} {% load markdown %}
<div class="block columns"> <div class="block columns">
<div class="column is-flex is-flex-direction-column"> <div class="column is-flex is-flex-direction-column">
<h4 class="title is-4">{% trans "User details" %}</h4> <h4 class="title is-4">{% trans "User details" %}</h4>
@ -7,7 +7,7 @@
{% include 'user/user_preview.html' with user=user %} {% include 'user/user_preview.html' with user=user %}
{% if user.summary %} {% if user.summary %}
<div class="box content has-background-white-ter is-shadowless"> <div class="box content has-background-white-ter is-shadowless">
{{ user.summary | to_markdown | safe }} {{ user.summary|to_markdown|safe }}
</div> </div>
{% endif %} {% endif %}

View file

@ -36,57 +36,12 @@ def get_user_rating(book, user):
return 0 return 0
@register.filter(name="replies")
def get_replies(status):
"""get all direct replies to a status"""
# TODO: this limit could cause problems
return models.Status.objects.filter(
reply_parent=status,
deleted=False,
).select_subclasses()[:10]
@register.filter(name="parent")
def get_parent(status):
"""get the reply parent for a status"""
return (
models.Status.objects.filter(id=status.reply_parent_id)
.select_subclasses()
.get()
)
@register.filter(name="boosted_status")
def get_boosted(boost):
"""load a boosted status. have to do this or it won't get foreign keys"""
return (
models.Status.objects.select_subclasses().get(id=boost.boosted_status.id)
)
@register.filter(name="book_description") @register.filter(name="book_description")
def get_book_description(book): def get_book_description(book):
"""use the work's text if the book doesn't have it""" """use the work's text if the book doesn't have it"""
return book.description or book.parent_work.description return book.description or book.parent_work.description
@register.filter(name="to_markdown")
def get_markdown(content):
"""convert markdown to html"""
if content:
return to_markdown(content)
return None
@register.filter(name="mentions")
def get_mentions(status, user):
"""people to @ in a reply: the parent and all mentions"""
mentions = set([status.user] + list(status.mention_users.all()))
return (
" ".join("@" + get_user_identifier(m) for m in mentions if not m == user) + " "
)
@register.filter(name="next_shelf") @register.filter(name="next_shelf")
def get_next_shelf(current_shelf): def get_next_shelf(current_shelf):
"""shelf you'd use to update reading progress""" """shelf you'd use to update reading progress"""

View file

@ -0,0 +1,14 @@
""" template filters """
from django import template
from bookwyrm.views.status import to_markdown
register = template.Library()
@register.filter(name="to_markdown")
def get_markdown(content):
"""convert markdown to html"""
if content:
return to_markdown(content)
return None

View file

@ -0,0 +1,46 @@
""" template filters """
from django import template
from bookwyrm import models
from bookwyrm.templatetags.utilities import get_user_identifier
register = template.Library()
@register.filter(name="mentions")
def get_mentions(status, user):
"""people to @ in a reply: the parent and all mentions"""
mentions = set([status.user] + list(status.mention_users.all()))
return (
" ".join("@" + get_user_identifier(m) for m in mentions if not m == user) + " "
)
@register.filter(name="replies")
def get_replies(status):
"""get all direct replies to a status"""
# TODO: this limit could cause problems
return models.Status.objects.filter(
reply_parent=status,
deleted=False,
).select_subclasses()[:10]
@register.filter(name="parent")
def get_parent(status):
"""get the reply parent for a status"""
return (
models.Status.objects.filter(id=status.reply_parent_id)
.select_subclasses()
.get()
)
@register.filter(name="boosted_status")
def get_boosted(boost):
"""load a boosted status. have to do this or it won't get foreign keys"""
return (
models.Status.objects.select_subclasses().get(id=boost.boosted_status.id)
)