forked from mirrors/bookwyrm
Shelve books from anywhere you see a book
This commit is contained in:
parent
6c629be667
commit
78336531c9
7 changed files with 32 additions and 21 deletions
|
@ -4,7 +4,7 @@
|
|||
<div id="content">
|
||||
<div>
|
||||
<div class="book-preview">
|
||||
{% include 'snippets/book.html' with book=book size=large rating=rating description=True %}
|
||||
{% include 'snippets/book.html' with book=book size=large rating=rating description=True shelf_pulldown=True %}
|
||||
</div>
|
||||
<div id="tag-cloud">
|
||||
{% for tag in tags %}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
{% for book in shelf.books %}
|
||||
<div class="book-preview">
|
||||
{% include 'snippets/book.html' with book=book size="small" %}
|
||||
{% include 'snippets/shelve-button.html' with book=book %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% if shelf.size > shelf.books.count %}
|
||||
|
@ -29,9 +28,6 @@
|
|||
{% for book in recent_books %}
|
||||
<div class="book-preview">
|
||||
{% include 'snippets/book.html' with book=book size="small" %}
|
||||
{% if not book in user_books.all %}
|
||||
{% include 'snippets/shelve-button.html' with book=book %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -12,3 +12,5 @@
|
|||
{% if description %}
|
||||
<blockquote>{{ book.data.description | description }}</blockquote>
|
||||
{% endif %}
|
||||
|
||||
{% include 'snippets/shelve-button.html' with book=book pulldown=shelf_pulldown%}
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
{% load fr_display %}
|
||||
<form name="shelve" action="/shelve/{{ user.localname }}/{% shelve_button_identifier book %}/{{ book.id }}" method="post">
|
||||
{% if not pulldown %}
|
||||
|
||||
<form name="shelve" action="/shelve/" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="book.id"></input>
|
||||
<input type="hidden" name="book" value="{{ book.id }}"></input>
|
||||
<input type="hidden" name="shelf" value="{% shelve_button_identifier book %}"></input>
|
||||
<button type="submit">{% shelve_button_text book %}</button>
|
||||
</form>
|
||||
|
||||
{% else %}
|
||||
|
||||
<form name="shelve" action="/shelve/" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="{{ book.id }}"></input>
|
||||
|
||||
<select name="shelf">
|
||||
{% for shelf in request.user.shelf_set.all %}
|
||||
<option value="{{ shelf.identifier }}" {% if book in shelf.books.all %} selected {% endif %}>
|
||||
{{ shelf.name }}{% if book in shelf.books.all %} ✓ {% endif %}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="submit">Shelve</button>
|
||||
</form>
|
||||
|
||||
{% endif %}
|
||||
|
|
|
@ -74,8 +74,8 @@ def shelve_button_text(context, book):
|
|||
except models.ShelfBook.DoesNotExist:
|
||||
return 'Want to read'
|
||||
identifier = shelf.shelf.identifier
|
||||
if identifier == 'Start reading':
|
||||
return 'reading'
|
||||
if identifier == 'to-read':
|
||||
return 'Start reading'
|
||||
elif identifier == 'reading':
|
||||
return 'I\'m done!'
|
||||
return 'Want to read'
|
||||
|
|
|
@ -56,10 +56,7 @@ urlpatterns = [
|
|||
re_path(r'^untag/?$', views.untag),
|
||||
re_path(r'^comment/?$', views.comment),
|
||||
re_path(r'^favorite/(?P<status_id>\d+)/?$', views.favorite),
|
||||
re_path(
|
||||
r'^shelve/(?P<username>\w+)/(?P<shelf_id>[\w-]+)/(?P<book_id>\d+)/?$',
|
||||
views.shelve
|
||||
),
|
||||
re_path(r'^shelve/?$', views.shelve),
|
||||
re_path(r'^follow/(?P<username>[\w@\.-]+)/?$', views.follow),
|
||||
re_path(r'^unfollow/(?P<username>[\w@\.-]+)/?$', views.unfollow),
|
||||
re_path(r'^search/?$', views.search),
|
||||
|
|
|
@ -274,19 +274,15 @@ def shelf_page(request, username, shelf_identifier):
|
|||
|
||||
|
||||
@login_required
|
||||
def shelve(request, username, shelf_id, book_id, reshelve=True):
|
||||
def shelve(request):
|
||||
''' put a book on a user's shelf '''
|
||||
if request.user.localname != username:
|
||||
# don't let people put books on other people's shelves
|
||||
return HttpResponseNotFound()
|
||||
|
||||
book = models.Book.objects.get(id=book_id)
|
||||
book = models.Book.objects.get(id=request.POST['book'])
|
||||
desired_shelf = models.Shelf.objects.filter(
|
||||
identifier=shelf_id,
|
||||
identifier=request.POST['shelf'],
|
||||
user=request.user
|
||||
).first()
|
||||
|
||||
if reshelve:
|
||||
if request.POST.get('reshelve', True):
|
||||
try:
|
||||
current_shelf = models.Shelf.objects.get(
|
||||
user=request.user,
|
||||
|
|
Loading…
Reference in a new issue