diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index edf1d9e45..d723ebdbf 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -76,7 +76,16 @@ class ReviewForm(CustomForm): class CommentForm(CustomForm): class Meta: model = models.Comment - fields = ["user", "book", "content", "content_warning", "sensitive", "privacy"] + fields = [ + "user", + "book", + "content", + "content_warning", + "sensitive", + "privacy", + "progress", + "progress_mode", + ] class QuotationForm(CustomForm): diff --git a/bookwyrm/migrations/0055_auto_20210321_0101.py b/bookwyrm/migrations/0055_auto_20210321_0101.py new file mode 100644 index 000000000..dea219c4d --- /dev/null +++ b/bookwyrm/migrations/0055_auto_20210321_0101.py @@ -0,0 +1,34 @@ +# Generated by Django 3.1.6 on 2021-03-21 01:01 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0054_auto_20210319_1942"), + ] + + operations = [ + migrations.AddField( + model_name="comment", + name="progress", + field=models.IntegerField( + blank=True, + null=True, + validators=[django.core.validators.MinValueValidator(0)], + ), + ), + migrations.AddField( + model_name="comment", + name="progress_mode", + field=models.CharField( + blank=True, + choices=[("PG", "page"), ("PCT", "percent")], + default="PG", + max_length=3, + null=True, + ), + ), + ] diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index 3445573c4..1a5fcb0d5 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -7,6 +7,8 @@ from .base_model import BookWyrmModel class ProgressMode(models.TextChoices): + """ types of prgress available """ + PAGE = "PG", "page" PERCENT = "PCT", "percent" @@ -32,10 +34,12 @@ class ReadThrough(BookWyrmModel): super().save(*args, **kwargs) def create_update(self): + """ add update to the readthrough """ if self.progress: return self.progressupdate_set.create( user=self.user, progress=self.progress, mode=self.progress_mode ) + return None class ProgressUpdate(BookWyrmModel): diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 09a7c4ec1..904ce461d 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -14,6 +14,7 @@ from .activitypub_mixin import ActivitypubMixin, ActivityMixin from .activitypub_mixin import OrderedCollectionPageMixin from .base_model import BookWyrmModel from .fields import image_serializer +from .readthrough import ProgressMode from . import fields @@ -229,6 +230,19 @@ class Comment(Status): "Edition", on_delete=models.PROTECT, activitypub_field="inReplyToBook" ) + # this is it's own field instead of a foreign key to the progress update + # so that the update can be deleted without impacting the status + progress = models.IntegerField( + validators=[MinValueValidator(0)], null=True, blank=True + ) + progress_mode = models.CharField( + max_length=3, + choices=ProgressMode.choices, + default=ProgressMode.PAGE, + null=True, + blank=True, + ) + @property def pure_content(self): """ indicate the book in question for mastodon (or w/e) users """ diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index 9715f1608..c68eb40d2 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -14,9 +14,6 @@ html { .card { overflow: visible; } -.card-header-title { - overflow: hidden; -} /* --- SHELVING --- */ .shelf-option:disabled > *::after { diff --git a/bookwyrm/templates/feed/feed_layout.html b/bookwyrm/templates/feed/feed_layout.html index 24294e5d0..6ed696a12 100644 --- a/bookwyrm/templates/feed/feed_layout.html +++ b/bookwyrm/templates/feed/feed_layout.html @@ -47,20 +47,18 @@ {% for book in shelf.books %}
-

- {% include 'snippets/book_titleby.html' with book=book %} -

+
+
+

{% include 'snippets/book_titleby.html' with book=book %}

+ {% include 'snippets/shelve_button/shelve_button.html' with book=book %} +
+
{% trans "Close" as button_text %} {% include 'snippets/toggle/toggle_button.html' with label=button_text controls_text="book" controls_uid=book.id class="delete" nonbutton=True pressed=True %}
- {% include 'snippets/shelve_button/shelve_button.html' with book=book %} - {% active_shelf book as active_shelf %} - {% if active_shelf.shelf.identifier == 'reading' and book.latest_readthrough %} - {% include 'snippets/progress_update.html' with readthrough=book.latest_readthrough %} - {% endif %} {% include 'snippets/create_status.html' with book=book %}
diff --git a/bookwyrm/templates/snippets/create_status_form.html b/bookwyrm/templates/snippets/create_status_form.html index 187eae605..c70a0e58b 100644 --- a/bookwyrm/templates/snippets/create_status_form.html +++ b/bookwyrm/templates/snippets/create_status_form.html @@ -13,7 +13,15 @@ {% endif %}
{% if type != 'reply' and type != 'direct' %} - + {% endif %} {% if type == 'review' %} @@ -45,6 +53,33 @@ {% include 'snippets/content_warning_field.html' with parent_status=status %}
+ {% elif type == 'comment' %} +
+ {% active_shelf book as active_shelf %} + {% if active_shelf.shelf.identifier == 'reading' and book.latest_readthrough %} + + {% with readthrough=book.latest_readthrough %} +
+ + +
+
+ +
+
+ +
+
+ {% if readthrough.progress_mode == 'PG' and book.pages %} +

{% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}

+ {% endif %} +
+ {% endwith %} + {% endif %} +
{% endif %} {# bottom bar #} diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html deleted file mode 100644 index 7bfde8dd4..000000000 --- a/bookwyrm/templates/snippets/progress_update.html +++ /dev/null @@ -1,33 +0,0 @@ -{% load i18n %} -
- {% csrf_token %} - -
- -
-
- -
-
- -
-
- -
-
- {% if readthrough.progress_mode == 'PG' and book.pages %} -

{% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}

- {% endif %} -
-
diff --git a/bookwyrm/templates/snippets/shelve_button/progress_update_modal.html b/bookwyrm/templates/snippets/shelve_button/progress_update_modal.html new file mode 100644 index 000000000..c766153af --- /dev/null +++ b/bookwyrm/templates/snippets/shelve_button/progress_update_modal.html @@ -0,0 +1,46 @@ +{% extends 'components/modal.html' %} +{% load i18n %} + +{% block modal-title %} +{% trans "Update progress" %} +{% endblock %} + +{% block modal-form-open %} +
+{% endblock %} + +{% block modal-body %} +{% csrf_token %} + +
+ +
+
+ +
+
+ +
+
+ {% if readthrough.progress_mode == 'PG' and book.pages %} +

{% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}

+ {% endif %} +
+{% endblock %} + +{% block modal-footer %} + +{% trans "Cancel" as button_text %} +{% include 'snippets/toggle/toggle_button.html' with text=button_text %} +{% endblock %} +{% block modal-form-close %}
{% endblock %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button.html b/bookwyrm/templates/snippets/shelve_button/shelve_button.html index 5f6ed8d20..586d7d9d1 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button.html @@ -3,7 +3,7 @@ {% with book.id|uuid as uuid %} {% active_shelf book as active_shelf %} -
+
{% if switch_mode and active_shelf.book != book %}
{% include 'snippets/switch_edition_button.html' with edition=book size='is-small' %} @@ -23,5 +23,7 @@ {% latest_read_through book request.user as readthrough %} {% include 'snippets/shelve_button/finish_reading_modal.html' with book=active_shelf.book controls_text="finish-reading" controls_uid=uuid readthrough=readthrough %} +{% include 'snippets/shelve_button/progress_update_modal.html' with book=shelf_book.book controls_text="progress-update" controls_uid=uuid readthrough=readthrough %} + {% endwith %} {% endif %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html index d6fdb13bc..56783b2cc 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html @@ -27,3 +27,11 @@
{% if dropdown %}{% endif %} {% endfor %} +{% if dropdown %} +
  • + +
  • +{% endif %} diff --git a/bookwyrm/templates/snippets/status/status_header.html b/bookwyrm/templates/snippets/status/status_header.html index a04177d9a..dc112f4d2 100644 --- a/bookwyrm/templates/snippets/status/status_header.html +++ b/bookwyrm/templates/snippets/status/status_header.html @@ -35,3 +35,9 @@ {% elif status.mention_books %} {{ status.mention_books.first.title }} {% endif %} + +{% if status.progress %} +

    + ({% if status.progress_mode == 'PG' %}page {{ status.progress }}{%else %}{{ status.progress }}%{% endif %}) +

    +{% endif %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 44492668b..c24b83f70 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -183,7 +183,7 @@ urlpatterns = [ re_path(r"^shelve/?$", views.shelve), re_path(r"^unshelve/?$", views.unshelve), # reading progress - re_path(r"^edit-readthrough/?$", views.edit_readthrough), + re_path(r"^edit-readthrough/?$", views.edit_readthrough, name="edit-readthrough"), re_path(r"^delete-readthrough/?$", views.delete_readthrough), re_path(r"^create-readthrough/?$", views.create_readthrough), re_path(r"^delete-progressupdate/?$", views.delete_progressupdate), diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index 0cb5974bd..fb548690d 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -13,6 +13,7 @@ from bookwyrm.settings import DOMAIN from bookwyrm.status import delete_status from bookwyrm.utils import regex from .helpers import handle_remote_webfinger +from .reading import edit_readthrough # pylint: disable= no-self-use @@ -64,6 +65,10 @@ class CreateStatus(View): status.quote = to_markdown(status.quote) status.save(created=True) + + # update a readthorugh, if needed + edit_readthrough(request) + return redirect(request.headers.get("Referer", "/"))