Cleans up queryset declarations
This commit is contained in:
parent
888930f891
commit
126594ec49
|
@ -251,7 +251,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% url 'book' book.id as tab_url %}
|
{% url 'book' book.id as tab_url %}
|
||||||
<li {% if tab_url == request.path %}class="is-active"{% endif %}>
|
<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>
|
</li>
|
||||||
{% if user_statuses.review_count %}
|
{% if user_statuses.review_count %}
|
||||||
{% url 'book-user-statuses' book.id 'review' as tab_url %}
|
{% 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()),
|
re_path(r"^unboost/(?P<status_id>\d+)/?$", views.Unboost.as_view()),
|
||||||
# books
|
# books
|
||||||
re_path(r"%s(.json)?/?$" % book_path, views.Book.as_view(), name="book"),
|
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/edit/?$" % book_path, views.EditBook.as_view()),
|
||||||
re_path(r"%s/confirm/?$" % book_path, views.ConfirmEditBook.as_view()),
|
re_path(r"%s/confirm/?$" % book_path, views.ConfirmEditBook.as_view()),
|
||||||
re_path(r"^create-book/?$", views.EditBook.as_view()),
|
re_path(r"^create-book/?$", views.EditBook.as_view()),
|
||||||
|
|
|
@ -47,25 +47,22 @@ class Book(View):
|
||||||
|
|
||||||
# all reviews for the book
|
# all reviews for the book
|
||||||
reviews = privacy_filter(
|
reviews = privacy_filter(
|
||||||
request.user,
|
request.user, models.Review.objects.filter(book__in=work.editions.all())
|
||||||
models.Review.objects.filter(book__in=work.editions.all())
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# the reviews to show
|
# the reviews to show
|
||||||
if user_statuses and request.user.is_authenticated:
|
if user_statuses and request.user.is_authenticated:
|
||||||
if user_statuses == 'review':
|
if user_statuses == "review":
|
||||||
queryset = book.review_set
|
queryset = book.review_set
|
||||||
elif user_statuses == 'comment':
|
elif user_statuses == "comment":
|
||||||
queryset = book.comment_set
|
queryset = book.comment_set
|
||||||
else:
|
else:
|
||||||
queryset = book.quotation_set
|
queryset = book.quotation_set
|
||||||
paginated = Paginator(
|
queryset = queryset.filter(user=request.user)
|
||||||
queryset.filter(user=request.user), PAGE_LENGTH
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
paginated = Paginator(
|
queryset = reviews.exclude(Q(content__isnull=True) | Q(content=""))
|
||||||
reviews.exclude(Q(content__isnull=True) | Q(content="")), PAGE_LENGTH
|
paginated = Paginator(queryset, PAGE_LENGTH)
|
||||||
)
|
|
||||||
data = {
|
data = {
|
||||||
"book": book,
|
"book": book,
|
||||||
"statuses": paginated.get_page(request.GET.get("page")),
|
"statuses": paginated.get_page(request.GET.get("page")),
|
||||||
|
|
Loading…
Reference in New Issue