From 7bf39d3bf749f89c14fb0ab6930915629e1dc572 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 5 Nov 2020 16:48:15 -0800 Subject: [PATCH 1/6] html for updated reading progress flow --- bookwyrm/static/css/format.css | 4 + .../templates/snippets/create_status.html | 9 +- bookwyrm/templates/snippets/reply_form.html | 9 +- .../templates/snippets/shelve_button.html | 153 +++++++++++++++--- bookwyrm/templatetags/fr_display.py | 27 ++-- bookwyrm/views.py | 8 +- 6 files changed, 155 insertions(+), 55 deletions(-) diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index 51c931e6..db3c20ef 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -15,6 +15,10 @@ input.toggle-control:checked ~ .toggle-content { display: block; } +input.toggle-control:checked ~ .modal.toggle-content { + display: flex; +} + /* --- STARS --- */ .rate-stars button.icon { background: none; diff --git a/bookwyrm/templates/snippets/create_status.html b/bookwyrm/templates/snippets/create_status.html index 28379f0e..9055e2d4 100644 --- a/bookwyrm/templates/snippets/create_status.html +++ b/bookwyrm/templates/snippets/create_status.html @@ -44,14 +44,7 @@
-
- -
+ {% include 'snippets/privacy_select.html' %}
diff --git a/bookwyrm/templates/snippets/reply_form.html b/bookwyrm/templates/snippets/reply_form.html index 48371f63..2d8abd23 100644 --- a/bookwyrm/templates/snippets/reply_form.html +++ b/bookwyrm/templates/snippets/reply_form.html @@ -13,14 +13,7 @@
-
- -
+ {% include 'snippets/privacy_select.html' %}
- - +
+ +
+ +
+ + +
+{% endwith %} {% endif %} diff --git a/bookwyrm/templatetags/fr_display.py b/bookwyrm/templatetags/fr_display.py index 73df1db8..5e719695 100644 --- a/bookwyrm/templatetags/fr_display.py +++ b/bookwyrm/templatetags/fr_display.py @@ -158,22 +158,14 @@ def time_since(date): @register.simple_tag(takes_context=True) -def shelve_button_identifier(context, book): +def active_shelf(context, book): ''' check what shelf a user has a book on, if any ''' #TODO: books can be on multiple shelves, handle that better shelf = models.ShelfBook.objects.filter( shelf__user=context['request'].user, book=book ).first() - if not shelf: - return 'to-read' - - identifier = shelf.shelf.identifier - if identifier == 'to-read': - return 'reading' - if identifier == 'reading': - return 'read' - return 'to-read' + return shelf.shelf if shelf else None @register.simple_tag(takes_context=True) @@ -192,7 +184,7 @@ def shelve_button_text(context, book): return 'Start reading' if identifier == 'reading': return 'I\'m done!' - return 'Want to read' + return 'Read' @register.simple_tag(takes_context=False) @@ -200,4 +192,15 @@ def latest_read_through(book, user): ''' the most recent read activity ''' return models.ReadThrough.objects.filter( user=user, - book=book).order_by('-created_date').first() + book=book + ).order_by('-start_date').first() + + +@register.simple_tag(takes_context=False) +def active_read_through(book, user): + ''' the most recent read activity ''' + return models.ReadThrough.objects.filter( + user=user, + book=book, + finish_date__isnull=True + ).order_by('-start_date').first() diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 6e98225c..9794d585 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -71,7 +71,7 @@ def home_tab(request, tab): models.Edition.objects.filter( shelves__user=request.user, shelves__identifier='read' - )[:2], + ).order_by('-updated_date')[:2], # to-read models.Edition.objects.filter( shelves__user=request.user, @@ -242,7 +242,11 @@ def about_page(request): def password_reset_request(request): ''' invite management page ''' - return TemplateResponse(request, 'password_reset_request.html', {'title': 'Reset Password'}) + return TemplateResponse( + request, + 'password_reset_request.html', + {'title': 'Reset Password'} + ) def password_reset(request, code): From c64acf559b7f9f57fa6f8161eb072758c8fc40ac Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 6 Nov 2020 08:51:50 -0800 Subject: [PATCH 2/6] create readthroughs --- bookwyrm/outgoing.py | 50 ++--- bookwyrm/status.py | 3 +- .../templates/snippets/shelve_button.html | 76 ++++---- bookwyrm/urls.py | 2 + bookwyrm/view_actions.py | 180 +++++++++++++----- 5 files changed, 200 insertions(+), 111 deletions(-) diff --git a/bookwyrm/outgoing.py b/bookwyrm/outgoing.py index 444b2e71..0ea10ab9 100644 --- a/bookwyrm/outgoing.py +++ b/bookwyrm/outgoing.py @@ -1,5 +1,4 @@ ''' handles all the activity coming out of the server ''' -from datetime import datetime import re from django.db import IntegrityError, transaction @@ -121,6 +120,19 @@ def handle_shelve(user, book, shelf): broadcast(user, shelve.to_add_activity(user)) + +def handle_unshelve(user, book, shelf): + ''' a local user is getting a book put on their shelf ''' + # update the database + row = models.ShelfBook.objects.get(book=book, shelf=shelf) + activity = row.to_remove_activity(user) + row.delete() + + broadcast(user, activity) + + +def handle_reading_status(user, shelf, book, privacy): + ''' post about a user reading a book ''' # tell the world about this cool thing that happened try: message = { @@ -132,41 +144,17 @@ def handle_shelve(user, book, shelf): # it's a non-standard shelf, don't worry about it return - status = create_generated_note(user, message, mention_books=[book]) + status = create_generated_note( + user, + message, + mention_books=[book], + privacy=privacy + ) status.save() - if shelf.identifier == 'reading': - read = models.ReadThrough( - user=user, - book=book, - start_date=datetime.now()) - read.save() - elif shelf.identifier == 'read': - read = models.ReadThrough.objects.filter( - user=user, - book=book, - finish_date=None).order_by('-created_date').first() - if not read: - read = models.ReadThrough( - user=user, - book=book, - start_date=datetime.now()) - read.finish_date = datetime.now() - read.save() - broadcast(user, status.to_create_activity(user)) -def handle_unshelve(user, book, shelf): - ''' a local user is getting a book put on their shelf ''' - # update the database - row = models.ShelfBook.objects.get(book=book, shelf=shelf) - activity = row.to_remove_activity(user) - row.delete() - - broadcast(user, activity) - - def handle_imported_book(user, item, include_reviews, privacy): ''' process a goodreads csv and then post about it ''' if isinstance(item.book, models.Work): diff --git a/bookwyrm/status.py b/bookwyrm/status.py index b373bec5..c8c01c99 100644 --- a/bookwyrm/status.py +++ b/bookwyrm/status.py @@ -14,7 +14,7 @@ def delete_status(status): status.save() -def create_generated_note(user, content, mention_books=None): +def create_generated_note(user, content, mention_books=None, privacy='public'): ''' a note created by the app about user activity ''' # sanitize input html parser = InputHtmlParser() @@ -24,6 +24,7 @@ def create_generated_note(user, content, mention_books=None): status = models.GeneratedNote.objects.create( user=user, content=content, + privacy=privacy ) if mention_books: diff --git a/bookwyrm/templates/snippets/shelve_button.html b/bookwyrm/templates/snippets/shelve_button.html index 5cb7d0d3..ab83ae73 100644 --- a/bookwyrm/templates/snippets/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button.html @@ -30,15 +30,23 @@
@@ -55,14 +63,14 @@
@@ -74,7 +82,7 @@
- +
@@ -97,21 +105,21 @@ {% active_read_through book user as readthrough %}
@@ -132,7 +132,7 @@
- +
From 8f5d6c11ef6dd6e483a22ea36aacc9fb3864750a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 6 Nov 2020 09:00:33 -0800 Subject: [PATCH 4/6] button spacing in shelve button pulldown --- bookwyrm/templates/snippets/shelve_button.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/snippets/shelve_button.html b/bookwyrm/templates/snippets/shelve_button.html index 0091bb4f..2688d06b 100644 --- a/bookwyrm/templates/snippets/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button.html @@ -33,13 +33,13 @@ {% for shelf in request.user.shelf_set.all %}
  • {% if shelf.identifier == 'reading' and active_shelf.identifier != 'reading' %} -