forked from mirrors/bookwyrm
Re-add tags to book page
This commit is contained in:
parent
f35cae49b3
commit
630c94a34a
6 changed files with 41 additions and 30 deletions
|
@ -49,9 +49,9 @@ class Connector(AbstractConnector):
|
|||
annotated with work data. '''
|
||||
|
||||
try:
|
||||
book = models.Book.objects.select_subclasses().get(
|
||||
book = models.Book.objects.select_subclasses().filter(
|
||||
openlibrary_key=olkey
|
||||
)
|
||||
).first()
|
||||
return book
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
@ -119,7 +119,7 @@ class Connector(AbstractConnector):
|
|||
author_id = author_blob['key']
|
||||
author_id = author_id.split('/')[-1]
|
||||
book.authors.add(self.get_or_create_author(author_id))
|
||||
if not data.get('authors'):
|
||||
if not data.get('authors') and book.parent_work.authors.count():
|
||||
book.authors.set(book.parent_work.authors.all())
|
||||
|
||||
|
||||
|
@ -166,7 +166,7 @@ class Connector(AbstractConnector):
|
|||
|
||||
try:
|
||||
models.Edition.objects.get(openlibrary_key=olkey)
|
||||
except ObjectDoesNotExist:
|
||||
except models.Edition.DoesNotExist:
|
||||
book = models.Edition.objects.create(openlibrary_key=olkey)
|
||||
self.update_from_data(book, data)
|
||||
|
||||
|
@ -177,7 +177,7 @@ class Connector(AbstractConnector):
|
|||
raise ValueError('Invalid OpenLibrary author ID')
|
||||
try:
|
||||
return models.Author.objects.get(openlibrary_key=olkey)
|
||||
except ObjectDoesNotExist:
|
||||
except models.Author.DoesNotExist:
|
||||
pass
|
||||
|
||||
response = requests.get('%s/authors/%s.json' % (self.url, olkey))
|
||||
|
|
|
@ -546,15 +546,17 @@ dd {
|
|||
}
|
||||
|
||||
.tag {
|
||||
border: 1px solid black;
|
||||
display: inline-block;
|
||||
padding: 0.2em;
|
||||
border-radius: 0.2em;
|
||||
background-color: #F3FFBD;
|
||||
background-color: #EEE;
|
||||
}
|
||||
.tag form {
|
||||
display: inline;
|
||||
}
|
||||
.tag a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
white-space: pre-line;
|
||||
|
|
|
@ -48,14 +48,8 @@
|
|||
<p><a href="/editions/{{ book.parent_work.id }}">{{ book.parent_work.edition_set.count }} editions</a></p>
|
||||
{% endif %}
|
||||
|
||||
<div id="tag-cloud">
|
||||
{% for tag in tags %}
|
||||
{% include 'snippets/tag.html' with tag=tag user=request.user user_tags=user_tag_names %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{% if request.user.is_authenticated %}
|
||||
<div>
|
||||
<h3>Leave a review</h3>
|
||||
<form class="review-form" name="review" action="/review/" method="post">
|
||||
{% csrf_token %}
|
||||
|
@ -64,8 +58,24 @@
|
|||
{{ review_form.as_p }}
|
||||
<button type="submit">Post review</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3>Tags</h3>
|
||||
<form name="tag" action="/tag/" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="{{ book.fedireads_key }}"></input>
|
||||
<input type="text" name="name"></input>
|
||||
<button type="submit">Add tag</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="tag-cloud">
|
||||
{% for tag in tags %}
|
||||
{% include 'snippets/tag.html' with book=book tag=tag user_tags=user_tags %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
{% block content %}
|
||||
<div class="content-container">
|
||||
<h2>Recently Added Books</h2>
|
||||
<div class="book-grid row wrap">
|
||||
<div class="book-grid row wrap shrink">
|
||||
{% for book in books %}
|
||||
<div class="book-preview">
|
||||
<div class="cover-container">
|
||||
<a href="{{ book.absolute_id }}">
|
||||
{% include 'snippets/book_cover.html' with book=book %}
|
||||
</a>
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load fr_display %}
|
||||
{% block content %}
|
||||
<div id="content">
|
||||
<div>
|
||||
<div class="content-container">
|
||||
<h2>Books tagged "{{ tag.name }}"</h2>
|
||||
<div class="book-grid row wrap shrink">
|
||||
{% for book in books.all %}
|
||||
<div class="book-preview grid">
|
||||
{% include 'snippets/book.html' with book=book size=large %}
|
||||
<div class="cover-container">
|
||||
<a href="{{ book.absolute_id }}">
|
||||
{% include 'snippets/book_cover.html' with book=book %}
|
||||
</a>
|
||||
{% include 'snippets/rate_action.html' with user=request.user book=book %}
|
||||
{% include 'snippets/shelve_button.html' with book=book %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -354,6 +354,8 @@ def book_page(request, book_identifier, tab='friends'):
|
|||
book = book.default_edition
|
||||
|
||||
work = book.parent_work
|
||||
if not work:
|
||||
return HttpResponseNotFound()
|
||||
|
||||
book_reviews = models.Review.objects.filter(book__in=work.edition_set.all())
|
||||
|
||||
|
@ -375,18 +377,13 @@ def book_page(request, book_identifier, tab='friends'):
|
|||
|
||||
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')),
|
||||
).values_list('identifier', flat=True)
|
||||
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'))
|
||||
tags = models.Tag.objects.filter(
|
||||
|
@ -399,12 +396,10 @@ def book_page(request, book_identifier, tab='friends'):
|
|||
'book': book,
|
||||
'shelf': shelf,
|
||||
'user_reviews': user_reviews,
|
||||
'user_rating': user_rating,
|
||||
'reviews': reviews.distinct(),
|
||||
'rating': rating['rating__avg'],
|
||||
'tags': tags,
|
||||
'user_tags': user_tags,
|
||||
'user_tag_names': user_tag_names,
|
||||
'review_form': forms.ReviewForm(),
|
||||
'tag_form': forms.TagForm(),
|
||||
'feed_tabs': [
|
||||
|
|
Loading…
Reference in a new issue