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' %}
{% load i18n %}
{% load bookwyrm_tags %}
{% load markdown %}
{% load humanize %}
{% block title %}{{ author.name }}{% endblock %}

View file

@ -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 %}

View file

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

View file

@ -1,5 +1,6 @@
{% load i18n %}
{% load bookwyrm_tags %}
{% load utilities %}
{% load markdown %}
{% load humanize %}
<div class="card is-stretchable">

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,7 @@
{% extends 'lists/list_layout.html' %}
{% load i18n %}
{% load bookwyrm_tags %}
{% load markdown %}
{% block panel %}
{% if request.user == list.user and pending_count %}

View file

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

View file

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

View file

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

View file

@ -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 %}

View file

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

View file

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

View file

@ -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 }}

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 }}">

View file

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

View file

@ -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 %}

View file

@ -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 }}">

View file

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

View file

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

View file

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

View file

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

View file

@ -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 }}">

View file

@ -1,4 +1,5 @@
{% load bookwyrm_tags %}
{% load utilities %}
{% load status_display %}
{% load i18n %}
{% load humanize %}

View file

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

View file

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

View file

@ -1,7 +1,8 @@
{% extends 'layout.html' %}
{% load i18n %}
{% load humanize %}
{% load bookwyrm_tags %}
{% load utilities %}
{% load markdown %}
{% block title %}{{ user.display_name }}{% endblock %}

View file

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

View file

@ -1,5 +1,5 @@
{% extends 'user/layout.html' %}
{% load bookwyrm_tags %}
{% load utilities %}
{% load humanize %}
{% load i18n %}

View file

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

View file

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

View file

@ -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 %}

View file

@ -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>

View file

@ -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"""

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)
)