mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-15 12:46:38 +00:00
More templatetag files
This commit is contained in:
parent
58da17d694
commit
ac2b63d0cd
40 changed files with 107 additions and 92 deletions
|
@ -1,6 +1,6 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
{% load humanize %}
|
||||
|
||||
{% block title %}{{ author.name }}{% endblock %}
|
||||
|
@ -66,7 +66,7 @@
|
|||
{% endif %}
|
||||
<div class="column">
|
||||
{% if author.bio %}
|
||||
{{ author.bio | to_markdown | safe }}
|
||||
{{ author.bio|to_markdown|safe }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -257,7 +257,7 @@
|
|||
{% include 'snippets/stars.html' with rating=rating.rating %}
|
||||
</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>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
|
||||
{% block title %}{% blocktrans with book_title=work.title %}Editions of {{ book_title }}{% endblocktrans %}{% endblock %}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block title %}{% trans "Compose status" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
{% load markdown %}
|
||||
{% load humanize %}
|
||||
|
||||
<div class="card is-stretchable">
|
||||
|
@ -19,7 +20,7 @@
|
|||
|
||||
<div>
|
||||
{% if user.summary %}
|
||||
{{ user.summary | to_markdown | safe | truncatechars_html:40 }}
|
||||
{{ user.summary|to_markdown|safe|truncatechars_html:40 }}
|
||||
{% else %} {% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
|
||||
{% block title %}{% trans "Welcome" %}{% endblock %}
|
||||
|
||||
|
@ -49,7 +49,7 @@
|
|||
{% else %}
|
||||
|
||||
<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 request_received %}
|
||||
|
@ -64,7 +64,7 @@
|
|||
<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">
|
||||
{% for error in request_form.email.errors %}
|
||||
<p class="help is-danger">{{ error | escape }}</p>
|
||||
<p class="help is-danger">{{ error|escape }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<button type="submit" class="button is-link">{% trans "Submit" %}</button>
|
||||
|
@ -80,7 +80,7 @@
|
|||
{% include 'user/user_preview.html' with user=request.user %}
|
||||
{% if request.user.summary %}
|
||||
<div class="box content">
|
||||
{{ request.user.summary | to_markdown | safe }}
|
||||
{{ request.user.summary|to_markdown|safe }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
{% load i18n %}
|
||||
|
||||
{% if book %}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{% extends 'feed/feed_layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load humanize %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
<h1 class="title">
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
|
||||
{% block title %}{% trans "Updates" %}{% endblock %}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load status_display %}
|
||||
<div class="block">
|
||||
|
||||
{% with depth=depth|add:1 %}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
{% extends 'lists/list_layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
|
||||
{% block panel %}
|
||||
{% if request.user == list.user and pending_count %}
|
||||
<div class="block content">
|
||||
<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>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
<div class="columns is-multiline">
|
||||
{% for list in lists %}
|
||||
<div class="column is-one-quarter">
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
|
||||
{% block title %}{{ list.name }}{% endblock %}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Lists" %}{% endblock %}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% extends 'settings/admin_layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load humanize %}
|
||||
|
||||
{% 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>
|
||||
</div>
|
||||
<div class="card-footer-item">
|
||||
{{ comment.created_date | naturaltime }}
|
||||
{{ comment.created_date|naturaltime }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load humanize %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load humanize %}
|
||||
|
||||
{% block title %}{% trans "Notifications" %}{% endblock %}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
{% extends 'search/layout.html' %}
|
||||
{% load bookwyrm_tags %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
{% extends 'settings/admin_layout.html' %}
|
||||
{% block title %}{{ server.server_name }}{% endblock %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
|
||||
{% block title %}{{ server.server_name }}{% endblock %}
|
||||
|
||||
{% block header %}
|
||||
{{ server.server_name }}
|
||||
|
|
|
@ -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 }}">
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% spaceless %}
|
||||
|
||||
{% load bookwyrm_tags %}
|
||||
{% load i18n %}
|
||||
|
||||
<figure
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
{% 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 %}
|
||||
{% else %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
{% load status_display %}
|
||||
|
||||
{% 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 }}">
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{% spaceless %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
|
||||
<div class="
|
||||
field is-grouped
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
|
||||
{% if request.user.is_authenticated %}
|
||||
|
||||
{% with book.id|uuid as uuid %}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
{% load i18n %}
|
||||
|
||||
{% with status_type=status.status_type %}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{% spaceless %}
|
||||
|
||||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
{% load i18n %}
|
||||
|
||||
{% if not hide_book %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load status_display %}
|
||||
{% load i18n %}
|
||||
|
||||
{% if not status.deleted %}
|
||||
{% if status.status_type == 'Announce' %}
|
||||
<a href="{{ status.user.local_path }}">
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
{% load status_display %}
|
||||
{% load i18n %}
|
||||
{% load humanize %}
|
||||
|
||||
|
@ -29,7 +30,7 @@
|
|||
</span>
|
||||
|
||||
{% if status.status_type == 'GeneratedNote' %}
|
||||
{{ status.content | safe }}
|
||||
{{ status.content|safe }}
|
||||
{% elif status.status_type == 'Rating' %}
|
||||
{% trans "rated" %}
|
||||
{% elif status.status_type == 'Review' %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
{% load utilities %}
|
||||
{% load i18n %}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends 'components/dropdown.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block dropdown-trigger %}
|
||||
<span class="icon icon-dots-three">
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load humanize %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
{% load markdown %}
|
||||
|
||||
{% block title %}{{ user.display_name }}{% endblock %}
|
||||
|
||||
|
@ -23,7 +24,7 @@
|
|||
|
||||
{% if user.summary %}
|
||||
<div class="column box has-background-white-bis content">
|
||||
{{ user.summary | to_markdown | safe }}
|
||||
{{ user.summary|to_markdown|safe }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends 'user/layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block tabs %}
|
||||
{% with user|username as username %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends 'user/layout.html' %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
{% load humanize %}
|
||||
{% load i18n %}
|
||||
|
||||
|
@ -101,14 +101,14 @@
|
|||
{% include 'snippets/authors.html' %}
|
||||
</td>
|
||||
<td data-title="{% trans "Shelved" %}">
|
||||
{{ book.created_date | naturalday }}
|
||||
{{ book.created_date|naturalday }}
|
||||
</td>
|
||||
{% latest_read_through book user as read_through %}
|
||||
<td data-title="{% trans "Started" %}">
|
||||
{{ read_through.start_date | naturalday |default_if_none:""}}
|
||||
{{ read_through.start_date|naturalday|default_if_none:""}}
|
||||
</td>
|
||||
<td data-title="{% trans "Finished" %}">
|
||||
{{ read_through.finish_date | naturalday |default_if_none:""}}
|
||||
{{ read_through.finish_date|naturalday|default_if_none:""}}
|
||||
</td>
|
||||
{% if request.user.is_authenticated %}
|
||||
<td data-title="{% trans "Rating" %}">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends 'user/layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block title %}{{ user.display_name }}{% endblock %}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% load i18n %}
|
||||
{% load humanize %}
|
||||
{% load utilities %}
|
||||
{% load bookwyrm_tags %}
|
||||
|
||||
<div class="media block">
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
{% extends 'settings/admin_layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load humanize %}
|
||||
|
||||
{% block title %}{{ user.username }}{% endblock %}
|
||||
{% block header %}{{ user.username }}{% endblock %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% load i18n %}
|
||||
{% load bookwyrm_tags %}
|
||||
{% load markdown %}
|
||||
<div class="block columns">
|
||||
<div class="column is-flex is-flex-direction-column">
|
||||
<h4 class="title is-4">{% trans "User details" %}</h4>
|
||||
|
@ -7,7 +7,7 @@
|
|||
{% include 'user/user_preview.html' with user=user %}
|
||||
{% if user.summary %}
|
||||
<div class="box content has-background-white-ter is-shadowless">
|
||||
{{ user.summary | to_markdown | safe }}
|
||||
{{ user.summary|to_markdown|safe }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -36,57 +36,12 @@ def get_user_rating(book, user):
|
|||
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")
|
||||
def get_book_description(book):
|
||||
"""use the work's text if the book doesn't have it"""
|
||||
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")
|
||||
def get_next_shelf(current_shelf):
|
||||
"""shelf you'd use to update reading progress"""
|
||||
|
|
14
bookwyrm/templatetags/markdown.py
Normal file
14
bookwyrm/templatetags/markdown.py
Normal 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
|
46
bookwyrm/templatetags/status_display.py
Normal file
46
bookwyrm/templatetags/status_display.py
Normal 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)
|
||||
)
|
Loading…
Reference in a new issue