From b80de929fd1118cd213b2aef7f0f9f1183cad7d6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Sep 2021 16:00:40 -0700 Subject: [PATCH] Create and view quotation page numbers --- bookwyrm/activitypub/note.py | 2 + bookwyrm/forms.py | 2 + .../migrations/0088_auto_20210905_2233.py | 34 ++++++++++++++++ bookwyrm/models/status.py | 10 +++++ .../snippets/create_status/comment.html | 25 ++++++++++-- .../snippets/create_status/quotation.html | 39 +++++++++++++++++-- .../snippets/status/content_status.html | 12 +++++- 7 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 bookwyrm/migrations/0088_auto_20210905_2233.py diff --git a/bookwyrm/activitypub/note.py b/bookwyrm/activitypub/note.py index aca62d7c..d61471fe 100644 --- a/bookwyrm/activitypub/note.py +++ b/bookwyrm/activitypub/note.py @@ -70,6 +70,8 @@ class Quotation(Comment): """a quote and commentary on a book""" quote: str + position: int = None + positionMode: str = None type: str = "Quotation" diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index e8812470..69052605 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -101,6 +101,8 @@ class QuotationForm(CustomForm): "content_warning", "sensitive", "privacy", + "position", + "position_mode", ] diff --git a/bookwyrm/migrations/0088_auto_20210905_2233.py b/bookwyrm/migrations/0088_auto_20210905_2233.py new file mode 100644 index 00000000..028cf7bf --- /dev/null +++ b/bookwyrm/migrations/0088_auto_20210905_2233.py @@ -0,0 +1,34 @@ +# Generated by Django 3.2.4 on 2021-09-05 22:33 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0087_merge_0086_auto_20210827_1727_0086_auto_20210828_1724"), + ] + + operations = [ + migrations.AddField( + model_name="quotation", + name="position", + field=models.IntegerField( + blank=True, + null=True, + validators=[django.core.validators.MinValueValidator(0)], + ), + ), + migrations.AddField( + model_name="quotation", + name="position_mode", + field=models.CharField( + blank=True, + choices=[("PG", "page"), ("PCT", "percent")], + default="PG", + max_length=3, + null=True, + ), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 9274a581..d0f094d2 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -290,6 +290,16 @@ class Quotation(BookStatus): """like a review but without a rating and transient""" quote = fields.HtmlField() + position = models.IntegerField( + validators=[MinValueValidator(0)], null=True, blank=True + ) + position_mode = models.CharField( + max_length=3, + choices=ProgressMode.choices, + default=ProgressMode.PAGE, + null=True, + blank=True, + ) @property def pure_content(self): diff --git a/bookwyrm/templates/snippets/create_status/comment.html b/bookwyrm/templates/snippets/create_status/comment.html index d830ddcb..8f3f5c2b 100644 --- a/bookwyrm/templates/snippets/create_status/comment.html +++ b/bookwyrm/templates/snippets/create_status/comment.html @@ -26,13 +26,32 @@ uuid: a unique identifier used to make html "id" attributes unique and clarify j
- +
diff --git a/bookwyrm/templates/snippets/create_status/quotation.html b/bookwyrm/templates/snippets/create_status/quotation.html index 03e9c25b..c6f1f85f 100644 --- a/bookwyrm/templates/snippets/create_status/quotation.html +++ b/bookwyrm/templates/snippets/create_status/quotation.html @@ -11,8 +11,6 @@ draft: the content of an existing Status object to be edited (used in delete and uuid: a unique identifier used to make html "id" attributes unique and clarify javascript controls {% endcomment %} -{% with type="quotation" %} - {% block pre_content_additions %}
+
+ +
+
+
+ +
+
+
+ +
+
+
{% endblock %} - -{% endwith %} diff --git a/bookwyrm/templates/snippets/status/content_status.html b/bookwyrm/templates/snippets/status/content_status.html index 781af279..788ea395 100644 --- a/bookwyrm/templates/snippets/status/content_status.html +++ b/bookwyrm/templates/snippets/status/content_status.html @@ -2,6 +2,7 @@ {% load markdown %} {% load i18n %} {% load static %} +{% load humanize %} {% with status_type=status.status_type %}
{{ status.quote|safe }}
-

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

+

+ — {% include 'snippets/book_titleby.html' with book=status.book %} + {% if status.position %} + {% if status.position_mode == 'PG' %} + {% blocktrans with page=status.position|intcomma %}(Page {{ page }}){% endblocktrans %} + {% else %} + {% blocktrans with percent=status.position %}({{ percent }}%){% endblocktrans %} + {% endif %} + {% endif %} +

{% endif %}