2021-05-11 21:14:22 +00:00
|
|
|
""" template filters for status interaction buttons """
|
|
|
|
from django import template
|
2022-01-06 19:07:22 +00:00
|
|
|
from django.core.cache import cache
|
|
|
|
|
2021-05-11 21:14:22 +00:00
|
|
|
from bookwyrm import models
|
|
|
|
|
|
|
|
|
|
|
|
register = template.Library()
|
|
|
|
|
|
|
|
|
|
|
|
@register.filter(name="liked")
|
|
|
|
def get_user_liked(user, status):
|
|
|
|
"""did the given user fav a status?"""
|
2022-01-06 19:07:22 +00:00
|
|
|
return cache.get_or_set(
|
|
|
|
f"fav-{user.id}-{status.id}",
|
|
|
|
models.Favorite.objects.filter(user=user, status=status).exists(),
|
|
|
|
259200,
|
|
|
|
)
|
2021-05-11 21:14:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@register.filter(name="boosted")
|
|
|
|
def get_user_boosted(user, status):
|
|
|
|
"""did the given user fav a status?"""
|
2022-01-06 19:07:22 +00:00
|
|
|
return cache.get_or_set(
|
|
|
|
f"boost-{user.id}-{status.id}",
|
|
|
|
status.boosters.filter(user=user).exists(),
|
|
|
|
259200,
|
|
|
|
)
|
2021-08-23 20:02:27 +00:00
|
|
|
|
2021-08-23 20:15:35 +00:00
|
|
|
|
2021-08-23 22:07:38 +00:00
|
|
|
@register.filter(name="saved")
|
|
|
|
def get_user_saved_lists(user, book_list):
|
|
|
|
"""did the user save a list"""
|
2021-08-23 20:02:27 +00:00
|
|
|
return user.saved_lists.filter(id=book_list.id).exists()
|