Use smaller templatetag modules

This commit is contained in:
Mouse Reeve 2021-05-11 14:41:28 -07:00
parent eba6159f68
commit 58da17d694
17 changed files with 69 additions and 50 deletions

View file

@ -1,5 +1,5 @@
{% spaceless %}
{% load bookwyrm_tags %}
{% load utilities %}
{% with 0|uuid as uuid %}
<div

View file

@ -1,5 +1,5 @@
{% load i18n %}
{% load bookwyrm_tags %}
{% load utilities %}
{% load humanize %}
<div class="columns is-mobile scroll-x mb-0">
{% for user in suggested_users %}

View file

@ -1,4 +1,4 @@
{% load bookwyrm_tags %}
{% load layout %}
{% load i18n %}
<!DOCTYPE html>
<html lang="{% get_lang %}">

View file

@ -1,4 +1,5 @@
{% load bookwyrm_tags %}
{% load interaction %}
{% load utilities %}
{% load i18n %}
{% with status.id|uuid as uuid %}

View file

@ -1,6 +1,6 @@
{% load humanize %}
{% load i18n %}
{% load bookwyrm_tags %}
{% load utilities %}
{% with status_type=request.GET.status_type %}
<div class="tab-group">

View file

@ -1,4 +1,6 @@
{% load bookwyrm_tags %}
{% load utilities %}
{% 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 }}">
{% csrf_token %}

View file

@ -1,5 +1,7 @@
{% load bookwyrm_tags %}
{% load interaction %}
{% load utilities %}
{% load i18n %}
{% with status.id|uuid as uuid %}
<form name="favorite" action="/favorite/{{ status.id }}" method="POST" class="interaction fav-{{ status.id }}-{{ uuid }} {% if request.user|liked:status %}is-hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}">
{% csrf_token %}

View file

@ -1,5 +1,5 @@
{% load i18n %}
{% load bookwyrm_tags %}
{% load utilities %}
<div class="select {{ class }}">
{% with 0|uuid as uuid %}
{% if not no_label %}

View file

@ -1,5 +1,6 @@
{% load i18n %}
{% load bookwyrm_tags %}
{% load utilities %}
{% with 0|uuid as report_uuid %}
{% trans "Report" as button_text %}

View file

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

View file

@ -1,5 +1,7 @@
{% load bookwyrm_tags %}
{% load utilities %}
{% load i18n %}
{% for shelf in shelves %}
{% comparison_bool shelf.identifier active_shelf.shelf.identifier as is_current %}
{% if dropdown %}<li role="menuitem" class="dropdown-item p-0">{% endif %}

View file

@ -1,7 +1,6 @@
{% extends 'components/card.html' %}
{% load i18n %}
{% load bookwyrm_tags %}
{% load humanize %}
{% load utilities %}
{% block card-header %}
<div class="card-header-title has-background-white-ter is-block">

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 m-0-mobile"></span>

View file

@ -1,4 +1,5 @@
{% load bookwyrm_tags %}
{% load utilities %}
{% load i18n %}
{% with 0|uuid as uuid %}

View file

@ -1,11 +1,10 @@
""" template filters """
from uuid import uuid4
from django import template, utils
from django import template
from django.db.models import Avg
from bookwyrm import models, views
from bookwyrm.views.status import to_markdown
from bookwyrm.templatetags.utilities import get_user_identifier
register = template.Library()
@ -37,12 +36,6 @@ def get_user_rating(book, user):
return 0
@register.filter(name="username")
def get_user_identifier(user):
"""use localname for local users, username for remote"""
return user.localname if user.localname else user.username
@register.filter(name="replies")
def get_replies(status):
"""get all direct replies to a status"""
@ -77,12 +70,6 @@ def get_book_description(book):
return book.description or book.parent_work.description
@register.filter(name="uuid")
def get_uuid(identifier):
"""for avoiding clashing ids when there are many forms"""
return "%s%s" % (identifier, uuid4())
@register.filter(name="to_markdown")
def get_markdown(content):
"""convert markdown to html"""
@ -112,17 +99,6 @@ def get_next_shelf(current_shelf):
return "to-read"
@register.filter(name="title")
def get_title(book):
"""display the subtitle if the title is short"""
if not book:
return ""
title = book.title
if len(title) < 6 and book.subtitle:
title = "{:s}: {:s}".format(title, book.subtitle)
return title
@register.simple_tag(takes_context=False)
def related_status(notification):
"""for notifications"""
@ -156,19 +132,6 @@ def latest_read_through(book, user):
)
@register.simple_tag(takes_context=False)
def comparison_bool(str1, str2):
"""idk why I need to write a tag for this, it reutrns a bool"""
return str1 == str2
@register.simple_tag(takes_context=False)
def get_lang():
"""get current language, strip to the first two letters"""
language = utils.translation.get_language()
return language[0 : language.find("-")]
@register.simple_tag(takes_context=True)
def mutuals_count(context, user):
"""how many users that you follow, follow them"""

View file

@ -0,0 +1,12 @@
""" template filters used for creating the layout"""
from django import template, utils
register = template.Library()
@register.simple_tag(takes_context=False)
def get_lang():
"""get current language, strip to the first two letters"""
language = utils.translation.get_language()
return language[0 : language.find("-")]

View file

@ -0,0 +1,35 @@
""" template filters for really common utilities """
from uuid import uuid4
from django import template
register = template.Library()
@register.filter(name="uuid")
def get_uuid(identifier):
"""for avoiding clashing ids when there are many forms"""
return "%s%s" % (identifier, uuid4())
@register.filter(name="username")
def get_user_identifier(user):
"""use localname for local users, username for remote"""
return user.localname if user.localname else user.username
@register.filter(name="title")
def get_title(book):
"""display the subtitle if the title is short"""
if not book:
return ""
title = book.title
if len(title) < 6 and book.subtitle:
title = "{:s}: {:s}".format(title, book.subtitle)
return title
@register.simple_tag(takes_context=False)
def comparison_bool(str1, str2):
"""idk why I need to write a tag for this, it reutrns a bool"""
return str1 == str2