mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Merge pull request #250 from mouse-reeve/readthrough
UI for editable readthroughs
This commit is contained in:
commit
905c99b075
5 changed files with 104 additions and 6 deletions
|
@ -29,6 +29,7 @@ class CustomForm(ModelForm):
|
|||
visible.field.widget.attrs['rows'] = None
|
||||
visible.field.widget.attrs['class'] = css_classes[input_type]
|
||||
|
||||
|
||||
class LoginForm(CustomForm):
|
||||
class Meta:
|
||||
model = models.User
|
||||
|
|
|
@ -56,10 +56,58 @@
|
|||
</div>
|
||||
|
||||
{% for readthrough in readthroughs %}
|
||||
<div class="block">
|
||||
{{ readthrough.start_date }}
|
||||
{{ readthrough.finish_date }}
|
||||
{{ readthrough.pages_read }}
|
||||
<div class="content block">
|
||||
<input class="toggle-control" type="radio" name="show-edit-readthrough" id="show-readthrough-{{ readthrough.id }}" checked>
|
||||
<div class="toggle-content hidden">
|
||||
<dl>
|
||||
<dt>Started reading:</dt>
|
||||
<dd>{{ readthrough.start_date | naturalday }}</dd>
|
||||
<dt>Finished reading:</dt>
|
||||
<dd>{{ readthrough.finish_date | naturalday }}</dd>
|
||||
</dl>
|
||||
<div class="field is-grouped">
|
||||
<label class="button is-small" for="edit-readthrough-{{ readthrough.id }}">
|
||||
<span class="icon icon-pencil">
|
||||
<span class="is-sr-only">Edit readthrough dates</span>
|
||||
</span>
|
||||
</label>
|
||||
<form name="delete-readthrough-{{ readthrough.id }}" action="/delete-readthrough" method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
||||
<button class="button is-small" type="submit">
|
||||
<span class="icon icon-x">
|
||||
<span class="is-sr-only">Delete this readthrough</span>
|
||||
</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content block">
|
||||
<input class="toggle-control" type="radio" name="show-edit-readthrough" id="edit-readthrough-{{ readthrough.id }}">
|
||||
<div class="toggle-content hidden">
|
||||
<form name="edit-readthrough" action="/edit-readthrough" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
||||
<div class="field">
|
||||
<label class="label" for="start_date">
|
||||
Started reading
|
||||
<input type="date" name="start_date" class="input" id="id_start_date-{{ readthrough.id }}" value="{{ readthrough.start_date | date:"Y-m-d" }}">
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="finish_date">
|
||||
Finished reading
|
||||
<input type="date" name="finish_date" class="input" id="id_finish_date-{{ readthrough.id }}" value="{{ readthrough.finish_date | date:"Y-m-d" }}">
|
||||
</label>
|
||||
</div>
|
||||
<div class="field is-grouped">
|
||||
<button class="button is-small" type="submit">Save</button>
|
||||
<label class="button is-small" for="show-readthrough-{{ readthrough.id }}">Cancel</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -102,6 +102,9 @@ urlpatterns = [
|
|||
re_path(r'^edit_book/(?P<book_id>\d+)/?', actions.edit_book),
|
||||
re_path(r'^upload_cover/(?P<book_id>\d+)/?', actions.upload_cover),
|
||||
|
||||
re_path(r'^edit-readthrough/?', actions.edit_readthrough),
|
||||
re_path(r'^delete-readthrough/?', actions.delete_readthrough),
|
||||
|
||||
re_path(r'^rate/?$', actions.rate),
|
||||
re_path(r'^review/?$', actions.review),
|
||||
re_path(r'^quotate/?$', actions.quotate),
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
from io import BytesIO, TextIOWrapper
|
||||
from PIL import Image
|
||||
|
||||
import dateutil.parser
|
||||
from dateutil.parser import ParserError
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.core.files.base import ContentFile
|
||||
|
@ -261,6 +263,51 @@ def upload_cover(request, book_id):
|
|||
return redirect('/book/%s' % book.id)
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_readthrough(request):
|
||||
''' can't use the form because the dates are too finnicky '''
|
||||
try:
|
||||
readthrough = models.ReadThrough.objects.get(id=request.POST.get('id'))
|
||||
except models.ReadThrough.DoesNotExist:
|
||||
return HttpResponseNotFound()
|
||||
|
||||
# don't let people edit other people's data
|
||||
if request.user != readthrough.user:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
# convert dates into a legible format
|
||||
start_date = request.POST.get('start_date')
|
||||
try:
|
||||
start_date = dateutil.parser.parse(start_date)
|
||||
except ParserError:
|
||||
start_date = None
|
||||
readthrough.start_date = start_date
|
||||
finish_date = request.POST.get('finish_date')
|
||||
try:
|
||||
finish_date = dateutil.parser.parse(finish_date)
|
||||
except ParserError:
|
||||
finish_date = None
|
||||
readthrough.finish_date = finish_date
|
||||
readthrough.save()
|
||||
return redirect(request.headers.get('Referer', '/'))
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_readthrough(request):
|
||||
''' remove a readthrough '''
|
||||
try:
|
||||
readthrough = models.ReadThrough.objects.get(id=request.POST.get('id'))
|
||||
except models.ReadThrough.DoesNotExist:
|
||||
return HttpResponseNotFound()
|
||||
|
||||
# don't let people edit other people's data
|
||||
if request.user != readthrough.user:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
readthrough.delete()
|
||||
return redirect(request.headers.get('Referer', '/'))
|
||||
|
||||
|
||||
@login_required
|
||||
def shelve(request):
|
||||
''' put a on a user's shelf '''
|
||||
|
|
|
@ -493,7 +493,6 @@ def book_page(request, book_id):
|
|||
book=book,
|
||||
).order_by('start_date')
|
||||
|
||||
|
||||
rating = reviews.aggregate(Avg('rating'))
|
||||
tags = models.Tag.objects.filter(
|
||||
book=book
|
||||
|
@ -508,10 +507,10 @@ def book_page(request, book_id):
|
|||
'rating': rating['rating__avg'],
|
||||
'tags': tags,
|
||||
'user_tags': user_tags,
|
||||
'readthroughs': readthroughs,
|
||||
'review_form': forms.ReviewForm(),
|
||||
'quotation_form': forms.QuotationForm(),
|
||||
'comment_form': forms.CommentForm(),
|
||||
'readthroughs': readthroughs,
|
||||
'tag_form': forms.TagForm(),
|
||||
'path': '/book/%s' % book_id,
|
||||
'cover_form': forms.CoverForm(instance=book),
|
||||
|
|
Loading…
Reference in a new issue