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' %}
|
{% 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 %}
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
{% load bookwyrm_tags %}
|
{% load bookwyrm_tags %}
|
||||||
|
{% load markdown %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% if book %}
|
{% if book %}
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{% 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 %}
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
{% extends 'search/layout.html' %}
|
{% extends 'search/layout.html' %}
|
||||||
{% load bookwyrm_tags %}
|
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
||||||
|
|
|
@ -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 }}
|
||||||
|
|
|
@ -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 }}">
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
|
|
||||||
{% load bookwyrm_tags %}
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
<figure
|
<figure
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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 }}">
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load bookwyrm_tags %}
|
|
||||||
|
|
||||||
<div class="
|
<div class="
|
||||||
field is-grouped
|
field is-grouped
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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 }}">
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load utilities %}
|
||||||
|
{% load status_display %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load humanize %}
|
{% load humanize %}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load markdown %}
|
||||||
{% load utilities %}
|
{% load utilities %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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"""
|
||||||
|
|
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