mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 05:21:08 +00:00
Moves status interaction filters into their own module
This commit is contained in:
parent
acd26012be
commit
eba6159f68
2 changed files with 22 additions and 16 deletions
|
@ -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")
|
@register.filter(name="boosted_status")
|
||||||
def get_boosted(boost):
|
def get_boosted(boost):
|
||||||
"""load a boosted status. have to do this or it won't get foreign keys"""
|
"""load a boosted status. have to do this or it won't get foreign keys"""
|
||||||
|
|
22
bookwyrm/templatetags/interaction.py
Normal file
22
bookwyrm/templatetags/interaction.py
Normal 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)
|
Loading…
Reference in a new issue