mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-18 14:16:45 +00:00
Want to read view
This commit is contained in:
parent
45146b4999
commit
1231d40e80
9 changed files with 72 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
|||
{% load i18n %}
|
||||
<div
|
||||
role="dialog"
|
||||
class="modal is-hidden"
|
||||
class="modal {% if active %}is-active{% else %}is-hidden{% endif %}"
|
||||
id="{{ controls_text }}-{{ controls_uid }}"
|
||||
aria-labelledby="modal-card-title-{{ controls_text }}-{{ controls_uid }}"
|
||||
aria-modal="true"
|
||||
|
|
14
bookwyrm/templates/reading_progress/start.html
Normal file
14
bookwyrm/templates/reading_progress/start.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}
|
||||
{% blocktrans trimmed with book_title=book.title %}
|
||||
Start "{{ book_title }}"
|
||||
{% endblocktrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% include "snippets/shelve_button/start_reading_modal.html" active=True %}
|
||||
|
||||
{% endblock %}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
{% block modal-form-open %}
|
||||
<form name="finish-reading" action="/finish-reading/{{ book.id }}" method="post">
|
||||
<form name="finish-reading" action="{% url 'finish-reading' book.id %}" method="post">
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block modal-title %}
|
||||
{% blocktrans with book_title=book.title %}Start "<em>{{ book_title }}</em>"{% endblocktrans %}
|
||||
{% blocktrans trimmed with book_title=book.title %}
|
||||
Start "<em>{{ book_title }}</em>"
|
||||
{% endblocktrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-form-open %}
|
||||
<form name="start-reading" action="/start-reading/{{ book.id }}" method="post">
|
||||
<form name="start-reading" action="{% url 'start-reading' book.id %}" method="post">
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block modal-form-open %}
|
||||
<form name="shelve" action="/shelve/" method="post">
|
||||
<form name="shelve" action="{% url 'to-read' book.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="{{ active_shelf.book.id }}">
|
||||
<input type="hidden" name="shelf" value="to-read">
|
||||
|
|
|
@ -223,7 +223,7 @@ urlpatterns = [
|
|||
re_path(
|
||||
r"^list/(?P<list_id>\d+)/curate/?$", views.Curate.as_view(), name="list-curate"
|
||||
),
|
||||
# Uyser books
|
||||
# User books
|
||||
re_path(r"%s/books/?$" % user_path, views.Shelf.as_view(), name="user-shelves"),
|
||||
re_path(
|
||||
r"^%s/(helf|books)/(?P<shelf_identifier>[\w-]+)(.json)?/?$" % user_path,
|
||||
|
@ -315,8 +315,10 @@ urlpatterns = [
|
|||
re_path(r"^delete-readthrough/?$", views.delete_readthrough),
|
||||
re_path(r"^create-readthrough/?$", views.create_readthrough),
|
||||
re_path(r"^delete-progressupdate/?$", views.delete_progressupdate),
|
||||
re_path(r"^start-reading/(?P<book_id>\d+)/?$", views.start_reading),
|
||||
re_path(r"^finish-reading/(?P<book_id>\d+)/?$", views.finish_reading),
|
||||
# shelve actions
|
||||
re_path(r"^to-read/(?P<book_id>\d+)/?$", views.WantToRead.as_view(), name="to-read"),
|
||||
re_path(r"^start-reading/(?P<book_id>\d+)/?$", views.StartReading.as_view(), name="start-reading"),
|
||||
re_path(r"^finish-reading/(?P<book_id>\d+)/?$", views.FinishReading.as_view(), name="finish-reading"),
|
||||
# following
|
||||
re_path(r"^follow/?$", views.follow, name="follow"),
|
||||
re_path(r"^unfollow/?$", views.unfollow, name="unfollow"),
|
||||
|
|
|
@ -25,7 +25,7 @@ from .list import Lists, List, Curate, UserLists
|
|||
from .notifications import Notifications
|
||||
from .outbox import Outbox
|
||||
from .reading import edit_readthrough, create_readthrough, delete_readthrough
|
||||
from .reading import StartReading, FinishReading, delete_progressupdate
|
||||
from .reading import WantToRead, StartReading, FinishReading, delete_progressupdate
|
||||
from .reports import Report, Reports, make_report, resolve_report, suspend_user
|
||||
from .rss_feed import RssFeed
|
||||
from .password import PasswordResetRequest, PasswordReset, ChangePassword
|
||||
|
|
|
@ -16,6 +16,45 @@ from .helpers import get_edition, handle_reading_status
|
|||
from .shelf import handle_unshelve
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
# pylint: disable=no-self-use
|
||||
class WantToRead(View):
|
||||
"""consider reading a book"""
|
||||
|
||||
def post(self, request, book_id):
|
||||
"""desire a book"""
|
||||
book = get_edition(book_id)
|
||||
desired_shelf = models.Shelf.objects.filter(
|
||||
identifier=models.Shelf.TO_READ, user=request.user
|
||||
).first()
|
||||
|
||||
current_status_shelfbook = (
|
||||
models.ShelfBook.objects.select_related("shelf")
|
||||
.filter(
|
||||
shelf__identifier__in=models.Shelf.READ_STATUS_IDENTIFIERS,
|
||||
user=request.user,
|
||||
book=book,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if current_status_shelfbook is not None:
|
||||
if current_status_shelfbook.shelf.identifier != models.Shelf.READING:
|
||||
handle_unshelve(book, current_status_shelfbook.shelf)
|
||||
else: # It already was on the shelf
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
||||
models.ShelfBook.objects.create(
|
||||
book=book, shelf=desired_shelf, user=request.user
|
||||
)
|
||||
|
||||
# post about it (if you want)
|
||||
if request.POST.get("post-status"):
|
||||
privacy = request.POST.get("privacy")
|
||||
handle_reading_status(request.user, desired_shelf, book, privacy)
|
||||
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
# pylint: disable=no-self-use
|
||||
class StartReading(View):
|
||||
|
@ -24,7 +63,7 @@ class StartReading(View):
|
|||
def post(self, request, book_id):
|
||||
"""begin reading a book"""
|
||||
book = get_edition(book_id)
|
||||
reading_shelf = models.Shelf.objects.filter(
|
||||
desired_shelf = models.Shelf.objects.filter(
|
||||
identifier=models.Shelf.READING, user=request.user
|
||||
).first()
|
||||
|
||||
|
@ -52,13 +91,13 @@ class StartReading(View):
|
|||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
||||
models.ShelfBook.objects.create(
|
||||
book=book, shelf=reading_shelf, user=request.user
|
||||
book=book, shelf=desired_shelf, user=request.user
|
||||
)
|
||||
|
||||
# post about it (if you want)
|
||||
if request.POST.get("post-status"):
|
||||
privacy = request.POST.get("privacy")
|
||||
handle_reading_status(request.user, reading_shelf, book, privacy)
|
||||
handle_reading_status(request.user, desired_shelf, book, privacy)
|
||||
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
||||
|
@ -71,7 +110,7 @@ class FinishReading(View):
|
|||
def post(self, request, book_id):
|
||||
"""a user completed a book, yay"""
|
||||
book = get_edition(book_id)
|
||||
finished_read_shelf = models.Shelf.objects.filter(
|
||||
desired_shelf = models.Shelf.objects.filter(
|
||||
identifier=models.Shelf.READ_FINISHED, user=request.user
|
||||
).first()
|
||||
|
||||
|
@ -96,13 +135,13 @@ class FinishReading(View):
|
|||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
||||
models.ShelfBook.objects.create(
|
||||
book=book, shelf=finished_read_shelf, user=request.user
|
||||
book=book, shelf=desired_shelf, user=request.user
|
||||
)
|
||||
|
||||
# post about it (if you want)
|
||||
if request.POST.get("post-status"):
|
||||
privacy = request.POST.get("privacy")
|
||||
handle_reading_status(request.user, finished_read_shelf, book, privacy)
|
||||
handle_reading_status(request.user, desired_shelf, book, privacy)
|
||||
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
||||
|
|
|
@ -178,11 +178,6 @@ def shelve(request):
|
|||
models.ShelfBook.objects.create(
|
||||
book=book, shelf=desired_shelf, user=request.user
|
||||
)
|
||||
if desired_shelf.identifier == models.Shelf.TO_READ and request.POST.get(
|
||||
"post-status"
|
||||
):
|
||||
privacy = request.POST.get("privacy") or desired_shelf.privacy
|
||||
handle_reading_status(request.user, desired_shelf, book, privacy=privacy)
|
||||
else:
|
||||
try:
|
||||
models.ShelfBook.objects.create(
|
||||
|
|
Loading…
Reference in a new issue