mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Use smaller templatetag modules
This commit is contained in:
parent
eba6159f68
commit
58da17d694
17 changed files with 69 additions and 50 deletions
|
@ -1,5 +1,5 @@
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
{% load bookwyrm_tags %}
|
{% load utilities %}
|
||||||
|
|
||||||
{% with 0|uuid as uuid %}
|
{% with 0|uuid as uuid %}
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load bookwyrm_tags %}
|
{% load utilities %}
|
||||||
{% load humanize %}
|
{% load humanize %}
|
||||||
<div class="columns is-mobile scroll-x mb-0">
|
<div class="columns is-mobile scroll-x mb-0">
|
||||||
{% for user in suggested_users %}
|
{% for user in suggested_users %}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load layout %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{% get_lang %}">
|
<html lang="{% get_lang %}">
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load interaction %}
|
||||||
|
{% load utilities %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% with status.id|uuid as uuid %}
|
{% with status.id|uuid as uuid %}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% load humanize %}
|
{% load humanize %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load bookwyrm_tags %}
|
{% load utilities %}
|
||||||
|
|
||||||
{% with status_type=request.GET.status_type %}
|
{% with status_type=request.GET.status_type %}
|
||||||
<div class="tab-group">
|
<div class="tab-group">
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load bookwyrm_tags %}
|
||||||
|
{% load utilities %}
|
||||||
|
|
||||||
{% 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 }}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load interaction %}
|
||||||
|
{% load utilities %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% with status.id|uuid as uuid %}
|
{% 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 }}">
|
<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 %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load bookwyrm_tags %}
|
{% load utilities %}
|
||||||
<div class="select {{ class }}">
|
<div class="select {{ class }}">
|
||||||
{% with 0|uuid as uuid %}
|
{% with 0|uuid as uuid %}
|
||||||
{% if not no_label %}
|
{% if not no_label %}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load bookwyrm_tags %}
|
{% load utilities %}
|
||||||
|
|
||||||
{% with 0|uuid as report_uuid %}
|
{% with 0|uuid as report_uuid %}
|
||||||
|
|
||||||
{% trans "Report" as button_text %}
|
{% trans "Report" as button_text %}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load bookwyrm_tags %}
|
||||||
|
{% 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,5 +1,7 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load bookwyrm_tags %}
|
||||||
|
{% load utilities %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% for shelf in shelves %}
|
{% for shelf in shelves %}
|
||||||
{% comparison_bool shelf.identifier active_shelf.shelf.identifier as is_current %}
|
{% comparison_bool shelf.identifier active_shelf.shelf.identifier as is_current %}
|
||||||
{% if dropdown %}<li role="menuitem" class="dropdown-item p-0">{% endif %}
|
{% if dropdown %}<li role="menuitem" class="dropdown-item p-0">{% endif %}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{% extends 'components/card.html' %}
|
{% extends 'components/card.html' %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load bookwyrm_tags %}
|
{% load utilities %}
|
||||||
{% load humanize %}
|
|
||||||
|
|
||||||
{% block card-header %}
|
{% block card-header %}
|
||||||
<div class="card-header-title has-background-white-ter is-block">
|
<div class="card-header-title has-background-white-ter is-block">
|
||||||
|
|
|
@ -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 m-0-mobile"></span>
|
<span class="icon icon-dots-three m-0-mobile"></span>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{% load bookwyrm_tags %}
|
{% load bookwyrm_tags %}
|
||||||
|
{% load utilities %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% with 0|uuid as uuid %}
|
{% with 0|uuid as uuid %}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
""" template filters """
|
""" template filters """
|
||||||
from uuid import uuid4
|
from django import template
|
||||||
|
|
||||||
from django import template, utils
|
|
||||||
from django.db.models import Avg
|
from django.db.models import Avg
|
||||||
|
|
||||||
from bookwyrm import models, views
|
from bookwyrm import models, views
|
||||||
from bookwyrm.views.status import to_markdown
|
from bookwyrm.views.status import to_markdown
|
||||||
|
from bookwyrm.templatetags.utilities import get_user_identifier
|
||||||
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
@ -37,12 +36,6 @@ def get_user_rating(book, user):
|
||||||
return 0
|
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")
|
@register.filter(name="replies")
|
||||||
def get_replies(status):
|
def get_replies(status):
|
||||||
"""get all direct replies to a 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
|
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")
|
@register.filter(name="to_markdown")
|
||||||
def get_markdown(content):
|
def get_markdown(content):
|
||||||
"""convert markdown to html"""
|
"""convert markdown to html"""
|
||||||
|
@ -112,17 +99,6 @@ def get_next_shelf(current_shelf):
|
||||||
return "to-read"
|
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)
|
@register.simple_tag(takes_context=False)
|
||||||
def related_status(notification):
|
def related_status(notification):
|
||||||
"""for notifications"""
|
"""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)
|
@register.simple_tag(takes_context=True)
|
||||||
def mutuals_count(context, user):
|
def mutuals_count(context, user):
|
||||||
"""how many users that you follow, follow them"""
|
"""how many users that you follow, follow them"""
|
||||||
|
|
12
bookwyrm/templatetags/layout.py
Normal file
12
bookwyrm/templatetags/layout.py
Normal 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("-")]
|
35
bookwyrm/templatetags/utilities.py
Normal file
35
bookwyrm/templatetags/utilities.py
Normal 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
|
Loading…
Reference in a new issue