mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-10 17:25:35 +00:00
Merge pull request #103 from cthulahoops/not_logged_in
Book & books while not logged in
This commit is contained in:
commit
448e874851
4 changed files with 52 additions and 33 deletions
|
@ -25,6 +25,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
<div class="content-container">
|
<div class="content-container">
|
||||||
<h2>Leave a review</h2>
|
<h2>Leave a review</h2>
|
||||||
<form class="review-form" name="review" action="/review/" method="post">
|
<form class="review-form" name="review" action="/review/" method="post">
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
<div class="content-container tabs">
|
<div class="content-container tabs">
|
||||||
{% include 'snippets/tabs.html' with tabs=feed_tabs active_tab=active_tab path=path %}
|
{% include 'snippets/tabs.html' with tabs=feed_tabs active_tab=active_tab path=path %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if not reviews %}
|
{% if not reviews %}
|
||||||
<div class="content-container">
|
<div class="content-container">
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
<div id="branding"><a href="/"><img id="logo" src="/static/images/logo-small.png" alt="BookWyrm"></img></a></div>
|
<div id="branding"><a href="/"><img id="logo" src="/static/images/logo-small.png" alt="BookWyrm"></img></a></div>
|
||||||
|
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
<li><a href="/user/{{request.user.localname}}/shelves">Your shelves</a></li>
|
<li><a href="/user/{{request.user.localname}}/shelves">Your shelves</a></li>
|
||||||
|
{% endif %}
|
||||||
<li><a href="/#feed">Updates</a></li>
|
<li><a href="/#feed">Updates</a></li>
|
||||||
<li><a href="/books">Discover Books</a></li>
|
<li><a href="/books">Discover Books</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{% load fr_display %}
|
{% load fr_display %}
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
{% if not pulldown %}
|
{% if not pulldown %}
|
||||||
|
|
||||||
<form name="shelve" action="/shelve/" method="post">
|
<form name="shelve" action="/shelve/" method="post">
|
||||||
|
@ -25,3 +26,4 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
|
@ -98,11 +98,11 @@ def home_tab(request, tab):
|
||||||
|
|
||||||
def books_page(request):
|
def books_page(request):
|
||||||
''' discover books '''
|
''' discover books '''
|
||||||
recent_books = models.Book.objects.filter(
|
recent_books = models.Book.objects
|
||||||
~Q(shelfbook__shelf__user=request.user)
|
if request.user.is_authenticated:
|
||||||
).order_by(
|
recent_books = recent_books.filter(~Q(shelfbook__shelf__user=request.user))
|
||||||
'-created_date'
|
recent_books = recent_books.order_by('-created_date')[:50]
|
||||||
)[:50]
|
|
||||||
data = {
|
data = {
|
||||||
'books': recent_books,
|
'books': recent_books,
|
||||||
}
|
}
|
||||||
|
@ -306,6 +306,7 @@ def book_page(request, book_identifier, tab='friends'):
|
||||||
else:
|
else:
|
||||||
book_reviews = models.Review.objects.filter(book=book)
|
book_reviews = models.Review.objects.filter(book=book)
|
||||||
|
|
||||||
|
if request.user.is_authenticated:
|
||||||
user_reviews = book_reviews.filter(
|
user_reviews = book_reviews.filter(
|
||||||
user=request.user,
|
user=request.user,
|
||||||
).all()
|
).all()
|
||||||
|
@ -333,15 +334,27 @@ def book_page(request, book_identifier, tab='friends'):
|
||||||
except models.Shelf.DoesNotExist:
|
except models.Shelf.DoesNotExist:
|
||||||
shelf = None
|
shelf = None
|
||||||
|
|
||||||
|
user_tags = models.Tag.objects.filter(
|
||||||
|
book=book, user=request.user
|
||||||
|
).all()
|
||||||
|
user_tag_names = user_tags.values_list('identifier', flat=True)
|
||||||
|
|
||||||
|
user_rating = user_reviews.aggregate(Avg('rating')),
|
||||||
|
else:
|
||||||
|
tab = 'public'
|
||||||
|
reviews = book_reviews.filter(privacy='public')
|
||||||
|
shelf = None
|
||||||
|
user_reviews = []
|
||||||
|
user_rating = None
|
||||||
|
user_tags = []
|
||||||
|
user_tag_names = []
|
||||||
|
|
||||||
rating = reviews.aggregate(Avg('rating'))
|
rating = reviews.aggregate(Avg('rating'))
|
||||||
tags = models.Tag.objects.filter(
|
tags = models.Tag.objects.filter(
|
||||||
book=book
|
book=book
|
||||||
).values(
|
).values(
|
||||||
'book', 'name', 'identifier'
|
'book', 'name', 'identifier'
|
||||||
).distinct().all()
|
).distinct().all()
|
||||||
user_tags = models.Tag.objects.filter(
|
|
||||||
book=book, user=request.user
|
|
||||||
).all()
|
|
||||||
|
|
||||||
review_form = forms.ReviewForm()
|
review_form = forms.ReviewForm()
|
||||||
tag_form = forms.TagForm()
|
tag_form = forms.TagForm()
|
||||||
|
@ -349,12 +362,12 @@ def book_page(request, book_identifier, tab='friends'):
|
||||||
'book': book,
|
'book': book,
|
||||||
'shelf': shelf,
|
'shelf': shelf,
|
||||||
'user_reviews': user_reviews,
|
'user_reviews': user_reviews,
|
||||||
'user_rating': user_reviews.aggregate(Avg('rating')),
|
'user_rating': user_rating,
|
||||||
'reviews': reviews.distinct(),
|
'reviews': reviews.distinct(),
|
||||||
'rating': rating['rating__avg'],
|
'rating': rating['rating__avg'],
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
'user_tags': user_tags,
|
'user_tags': user_tags,
|
||||||
'user_tag_names': user_tags.values_list('identifier', flat=True),
|
'user_tag_names': user_tag_names,
|
||||||
'review_form': review_form,
|
'review_form': review_form,
|
||||||
'tag_form': tag_form,
|
'tag_form': tag_form,
|
||||||
'feed_tabs': [
|
'feed_tabs': [
|
||||||
|
|
Loading…
Reference in a new issue