mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-28 19:10:35 +00:00
views handler for creating readthrough dates
This commit is contained in:
parent
b0e4fc2aa9
commit
327020f7b3
4 changed files with 18 additions and 1 deletions
|
@ -164,7 +164,7 @@
|
|||
<form name="add-readthrough" action="/create-readthrough" method="post">
|
||||
{% include 'snippets/readthrough_form.html' with readthrough=None %}
|
||||
<div class="field is-grouped">
|
||||
<button class="button is-primary" type="submit">Save</button>
|
||||
<button class="button is-primary" type="submit">Create</button>
|
||||
<label class="button" for="hide-create-readthrough" role="button" tabindex="0">Cancel</label>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% csrf_token %}
|
||||
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
||||
<input type="hidden" name="book" value="{{ book.id }}">
|
||||
<div class="field">
|
||||
<label class="label">
|
||||
Started reading
|
||||
|
|
|
@ -110,6 +110,7 @@ urlpatterns = [
|
|||
re_path(r'^switch-edition/?$', actions.switch_edition),
|
||||
re_path(r'^edit-readthrough/?$', actions.edit_readthrough),
|
||||
re_path(r'^delete-readthrough/?$', actions.delete_readthrough),
|
||||
re_path(r'^create-readthrough/?$', actions.create_readthrough),
|
||||
|
||||
re_path(r'^rate/?$', actions.rate),
|
||||
re_path(r'^review/?$', actions.review),
|
||||
|
|
|
@ -522,6 +522,18 @@ def delete_readthrough(request):
|
|||
return redirect(request.headers.get('Referer', '/'))
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def create_readthrough(request):
|
||||
''' can't use the form because the dates are too finnicky '''
|
||||
book = get_object_or_404(models.Edition, id=request.POST.get('book'))
|
||||
readthrough = update_readthrough(request, create=True, book=book)
|
||||
if not readthrough:
|
||||
return redirect(book.local_path)
|
||||
readthrough.save()
|
||||
return redirect(request.headers.get('Referer', '/'))
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def rate(request):
|
||||
|
@ -837,4 +849,7 @@ def update_readthrough(request, book=None, create=True):
|
|||
except ParserError:
|
||||
pass
|
||||
|
||||
if not readthrough.start_date and not readthrough.finish_date:
|
||||
return None
|
||||
|
||||
return readthrough
|
||||
|
|
Loading…
Reference in a new issue