mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 05:21:08 +00:00
Quick fix for error when books are on 2+ shelves
This commit is contained in:
parent
072e8fe02a
commit
c87f25f072
1 changed files with 17 additions and 6 deletions
|
@ -57,21 +57,30 @@ def get_notification_count(user):
|
||||||
|
|
||||||
@register.filter(name='replies')
|
@register.filter(name='replies')
|
||||||
def get_replies(status):
|
def get_replies(status):
|
||||||
return models.Status.objects.filter(reply_parent=status).select_subclasses().all()[:10]
|
''' get all direct replies to a status '''
|
||||||
|
#TODO: this limit could cause problems
|
||||||
|
return models.Status.objects.filter(
|
||||||
|
reply_parent=status
|
||||||
|
).select_subclasses().all()[:10]
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name='reply_count')
|
@register.filter(name='reply_count')
|
||||||
def get_reply_count(status):
|
def get_reply_count(status):
|
||||||
|
''' how many replies does a status have? '''
|
||||||
return models.Status.objects.filter(reply_parent=status).count()
|
return models.Status.objects.filter(reply_parent=status).count()
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name='parent')
|
@register.filter(name='parent')
|
||||||
def get_parent(status):
|
def get_parent(status):
|
||||||
return models.Status.objects.filter(id=status.reply_parent_id).select_subclasses().get()
|
''' get the reply parent for a status '''
|
||||||
|
return models.Status.objects.filter(
|
||||||
|
id=status.reply_parent_id
|
||||||
|
).select_subclasses().get()
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name='liked')
|
@register.filter(name='liked')
|
||||||
def get_user_liked(user, status):
|
def get_user_liked(user, status):
|
||||||
|
''' did the given user fav a status? '''
|
||||||
try:
|
try:
|
||||||
models.Favorite.objects.get(user=user, status=status)
|
models.Favorite.objects.get(user=user, status=status)
|
||||||
return True
|
return True
|
||||||
|
@ -83,10 +92,11 @@ def get_user_liked(user, status):
|
||||||
def shelve_button_identifier(context, book):
|
def shelve_button_identifier(context, book):
|
||||||
''' check what shelf a user has a book on, if any '''
|
''' check what shelf a user has a book on, if any '''
|
||||||
try:
|
try:
|
||||||
shelf = models.ShelfBook.objects.get(
|
#TODO: books can be on multiple shelves, handle that better
|
||||||
|
shelf = models.ShelfBook.objects.filter(
|
||||||
shelf__user=context['request'].user,
|
shelf__user=context['request'].user,
|
||||||
book=book
|
book=book
|
||||||
)
|
).first()
|
||||||
except models.ShelfBook.DoesNotExist:
|
except models.ShelfBook.DoesNotExist:
|
||||||
return 'to-read'
|
return 'to-read'
|
||||||
identifier = shelf.shelf.identifier
|
identifier = shelf.shelf.identifier
|
||||||
|
@ -101,10 +111,11 @@ def shelve_button_identifier(context, book):
|
||||||
def shelve_button_text(context, book):
|
def shelve_button_text(context, book):
|
||||||
''' check what shelf a user has a book on, if any '''
|
''' check what shelf a user has a book on, if any '''
|
||||||
try:
|
try:
|
||||||
shelf = models.ShelfBook.objects.get(
|
#TODO: books can be on multiple shelves
|
||||||
|
shelf = models.ShelfBook.objects.filter(
|
||||||
shelf__user=context['request'].user,
|
shelf__user=context['request'].user,
|
||||||
book=book
|
book=book
|
||||||
)
|
).first()
|
||||||
except models.ShelfBook.DoesNotExist:
|
except models.ShelfBook.DoesNotExist:
|
||||||
return 'Want to read'
|
return 'Want to read'
|
||||||
identifier = shelf.shelf.identifier
|
identifier = shelf.shelf.identifier
|
||||||
|
|
Loading…
Reference in a new issue