mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 05:21:08 +00:00
Cleans up queryset declarations
This commit is contained in:
parent
888930f891
commit
126594ec49
3 changed files with 13 additions and 12 deletions
|
@ -251,7 +251,7 @@
|
|||
<ul>
|
||||
{% url 'book' book.id as tab_url %}
|
||||
<li {% if tab_url == request.path %}class="is-active"{% endif %}>
|
||||
<a href="{{ tab_url }}">{% trans "Reviews" %}</a>
|
||||
<a href="{{ tab_url }}">{% trans "Reviews" %} ({{ review_count }})</a>
|
||||
</li>
|
||||
{% if user_statuses.review_count %}
|
||||
{% url 'book-user-statuses' book.id 'review' as tab_url %}
|
||||
|
|
|
@ -261,7 +261,11 @@ urlpatterns = [
|
|||
re_path(r"^unboost/(?P<status_id>\d+)/?$", views.Unboost.as_view()),
|
||||
# books
|
||||
re_path(r"%s(.json)?/?$" % book_path, views.Book.as_view(), name="book"),
|
||||
re_path(r"%s/(?P<user_statuses>review|comment|quote)/?$" % book_path, views.Book.as_view(), name="book-user-statuses"),
|
||||
re_path(
|
||||
r"%s/(?P<user_statuses>review|comment|quote)/?$" % book_path,
|
||||
views.Book.as_view(),
|
||||
name="book-user-statuses",
|
||||
),
|
||||
re_path(r"%s/edit/?$" % book_path, views.EditBook.as_view()),
|
||||
re_path(r"%s/confirm/?$" % book_path, views.ConfirmEditBook.as_view()),
|
||||
re_path(r"^create-book/?$", views.EditBook.as_view()),
|
||||
|
|
|
@ -47,25 +47,22 @@ class Book(View):
|
|||
|
||||
# all reviews for the book
|
||||
reviews = privacy_filter(
|
||||
request.user,
|
||||
models.Review.objects.filter(book__in=work.editions.all())
|
||||
request.user, models.Review.objects.filter(book__in=work.editions.all())
|
||||
)
|
||||
|
||||
# the reviews to show
|
||||
if user_statuses and request.user.is_authenticated:
|
||||
if user_statuses == 'review':
|
||||
if user_statuses == "review":
|
||||
queryset = book.review_set
|
||||
elif user_statuses == 'comment':
|
||||
elif user_statuses == "comment":
|
||||
queryset = book.comment_set
|
||||
else:
|
||||
queryset = book.quotation_set
|
||||
paginated = Paginator(
|
||||
queryset.filter(user=request.user), PAGE_LENGTH
|
||||
)
|
||||
queryset = queryset.filter(user=request.user)
|
||||
else:
|
||||
paginated = Paginator(
|
||||
reviews.exclude(Q(content__isnull=True) | Q(content="")), PAGE_LENGTH
|
||||
)
|
||||
queryset = reviews.exclude(Q(content__isnull=True) | Q(content=""))
|
||||
paginated = Paginator(queryset, PAGE_LENGTH)
|
||||
|
||||
data = {
|
||||
"book": book,
|
||||
"statuses": paginated.get_page(request.GET.get("page")),
|
||||
|
|
Loading…
Reference in a new issue