Moves status interaction filters into their own module

This commit is contained in:
Mouse Reeve 2021-05-11 14:14:22 -07:00
parent acd26012be
commit eba6159f68
2 changed files with 22 additions and 16 deletions

View file

@ -63,22 +63,6 @@ def get_parent(status):
)
@register.filter(name="liked")
def get_user_liked(user, status):
"""did the given user fav a status?"""
try:
models.Favorite.objects.get(user=user, status=status)
return True
except models.Favorite.DoesNotExist:
return False
@register.filter(name="boosted")
def get_user_boosted(user, status):
"""did the given user fav a status?"""
return user.id in status.boosters.all().values_list("user", flat=True)
@register.filter(name="boosted_status")
def get_boosted(boost):
"""load a boosted status. have to do this or it won't get foreign keys"""

View file

@ -0,0 +1,22 @@
""" template filters for status interaction buttons """
from django import template
from bookwyrm import models
register = template.Library()
@register.filter(name="liked")
def get_user_liked(user, status):
"""did the given user fav a status?"""
try:
models.Favorite.objects.get(user=user, status=status)
return True
except models.Favorite.DoesNotExist:
return False
@register.filter(name="boosted")
def get_user_boosted(user, status):
"""did the given user fav a status?"""
return user.id in status.boosters.all().values_list("user", flat=True)