From f085315d70d7cbb7f772b51ef6cb8cce8d6f42a2 Mon Sep 17 00:00:00 2001 From: Giebisch Date: Mon, 30 Jan 2023 16:12:14 +0100 Subject: [PATCH 1/4] Added Backend Part --- bookwyrm/forms/status.py | 1 + .../migrations/0174_auto_20230130_1240.py | 26 +++++++++++++++++++ bookwyrm/models/status.py | 3 +++ .../snippets/create_status/quotation.html | 13 ++++++++++ .../snippets/status/content_status.html | 4 +-- 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 bookwyrm/migrations/0174_auto_20230130_1240.py diff --git a/bookwyrm/forms/status.py b/bookwyrm/forms/status.py index 0800166bf7..b562595eeb 100644 --- a/bookwyrm/forms/status.py +++ b/bookwyrm/forms/status.py @@ -53,6 +53,7 @@ class Meta: "sensitive", "privacy", "position", + "endposition", "position_mode", ] diff --git a/bookwyrm/migrations/0174_auto_20230130_1240.py b/bookwyrm/migrations/0174_auto_20230130_1240.py new file mode 100644 index 0000000000..1b81c20878 --- /dev/null +++ b/bookwyrm/migrations/0174_auto_20230130_1240.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.16 on 2023-01-30 12:40 + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ('bookwyrm', '0173_default_user_auth_group_setting'), + ] + + operations = [ + migrations.AddField( + model_name='quotation', + name='endposition', + field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)]), + ), + migrations.AlterField( + model_name='sitesettings', + name='default_user_auth_group', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='auth.group'), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 19eab584d6..d5dc8e9c15 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -329,6 +329,9 @@ class Quotation(BookStatus): position = models.IntegerField( validators=[MinValueValidator(0)], null=True, blank=True ) + endposition = models.IntegerField( + validators=[MinValueValidator(0)], null=True, blank=True + ) position_mode = models.CharField( max_length=3, choices=ProgressMode.choices, diff --git a/bookwyrm/templates/snippets/create_status/quotation.html b/bookwyrm/templates/snippets/create_status/quotation.html index a9ddb17f46..9cc76d5a92 100644 --- a/bookwyrm/templates/snippets/create_status/quotation.html +++ b/bookwyrm/templates/snippets/create_status/quotation.html @@ -65,6 +65,19 @@ {% if not draft %}data-cache-draft="id_position_{{ book.id }}_{{ type }}"{% endif %} > +
+ +
{% endblock %} diff --git a/bookwyrm/templates/snippets/status/content_status.html b/bookwyrm/templates/snippets/status/content_status.html index e39284fcf1..4c4d893415 100644 --- a/bookwyrm/templates/snippets/status/content_status.html +++ b/bookwyrm/templates/snippets/status/content_status.html @@ -99,9 +99,9 @@

— {% 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 %} + {% blocktrans with page=status.position|intcomma %}(Page {{ page }}{% endblocktrans%}{% if status.endposition%} - {% blocktrans with endpage=status.endposition|intcomma %}{{ endpage }}{% endblocktrans %}{% endif%}) {% else %} - {% blocktrans with percent=status.position %}({{ percent }}%){% endblocktrans %} + {% blocktrans with percent=status.position %}({{ percent }}%{% endblocktrans %}{% if status.endposition%}{% blocktrans with endpercent=status.endposition|intcomma %} - {{ endpercent }}%{% endblocktrans %}{% endif %}) {% endif %} {% endif %}

From f65e0b7632b4c5f17cdd6335e4e0a1aa466532bd Mon Sep 17 00:00:00 2001 From: Giebisch Date: Mon, 6 Feb 2023 14:00:04 +0100 Subject: [PATCH 2/4] Add Quotation endposition test --- .../migrations/0174_auto_20230130_1240.py | 25 +++++++++++------ bookwyrm/tests/views/books/test_book.py | 27 +++++++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/bookwyrm/migrations/0174_auto_20230130_1240.py b/bookwyrm/migrations/0174_auto_20230130_1240.py index 1b81c20878..7337b6b461 100644 --- a/bookwyrm/migrations/0174_auto_20230130_1240.py +++ b/bookwyrm/migrations/0174_auto_20230130_1240.py @@ -8,19 +8,28 @@ class Migration(migrations.Migration): dependencies = [ - ('auth', '0012_alter_user_first_name_max_length'), - ('bookwyrm', '0173_default_user_auth_group_setting'), + ("auth", "0012_alter_user_first_name_max_length"), + ("bookwyrm", "0173_default_user_auth_group_setting"), ] operations = [ migrations.AddField( - model_name='quotation', - name='endposition', - field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)]), + model_name="quotation", + name="endposition", + field=models.IntegerField( + blank=True, + null=True, + validators=[django.core.validators.MinValueValidator(0)], + ), ), migrations.AlterField( - model_name='sitesettings', - name='default_user_auth_group', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='auth.group'), + model_name="sitesettings", + name="default_user_auth_group", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="auth.group", + ), ), ] diff --git a/bookwyrm/tests/views/books/test_book.py b/bookwyrm/tests/views/books/test_book.py index e536ef7360..dfa68a7e4b 100644 --- a/bookwyrm/tests/views/books/test_book.py +++ b/bookwyrm/tests/views/books/test_book.py @@ -257,6 +257,33 @@ def test_resolve_book(self): self.assertEqual(mock.call_args[0][0], "https://openlibrary.org/book/123") self.assertEqual(result.status_code, 302) + @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async") + @patch("bookwyrm.activitystreams.add_status_task.delay") + def test_quotation_endposition(self, *_): + """make sure the endposition is served as well""" + view = views.Book.as_view() + + quote = models.Quotation.objects.create( + user=self.local_user, + book=self.book, + content="hi", + quote="wow", + position=12, + endposition=13, + ) + + request = self.factory.get("") + request.user = self.local_user + + with patch("bookwyrm.views.books.books.is_api_request") as is_api: + is_api.return_value = False + result = view(request, self.book.id, user_statuses="quotation") + self.assertIsInstance(result, TemplateResponse) + validate_html(result.render()) + print(result.render()) + self.assertEqual(result.status_code, 200) + self.assertEqual(result.context_data["statuses"].object_list[0].endposition, 13) + def _setup_cover_url(): """creates cover url mock""" From 21575fbf3f8e2c08c0ef9c7551978764606890a3 Mon Sep 17 00:00:00 2001 From: Giebisch Date: Mon, 6 Feb 2023 14:09:53 +0100 Subject: [PATCH 3/4] Unused variable fix --- bookwyrm/tests/views/books/test_book.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/books/test_book.py b/bookwyrm/tests/views/books/test_book.py index dfa68a7e4b..a829c4a4b5 100644 --- a/bookwyrm/tests/views/books/test_book.py +++ b/bookwyrm/tests/views/books/test_book.py @@ -263,7 +263,7 @@ def test_quotation_endposition(self, *_): """make sure the endposition is served as well""" view = views.Book.as_view() - quote = models.Quotation.objects.create( + _ = models.Quotation.objects.create( user=self.local_user, book=self.book, content="hi", From 43fe4331338eee4468566cec16d76af086d84f4c Mon Sep 17 00:00:00 2001 From: Giebisch Date: Thu, 23 Feb 2023 18:40:20 +0100 Subject: [PATCH 4/4] Quotation same start and endposition --- bookwyrm/templates/snippets/create_status/quotation.html | 3 +++ bookwyrm/templates/snippets/status/content_status.html | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/snippets/create_status/quotation.html b/bookwyrm/templates/snippets/create_status/quotation.html index 9cc76d5a92..bd1d817ad7 100644 --- a/bookwyrm/templates/snippets/create_status/quotation.html +++ b/bookwyrm/templates/snippets/create_status/quotation.html @@ -65,6 +65,9 @@ {% if not draft %}data-cache-draft="id_position_{{ book.id }}_{{ type }}"{% endif %} > +
+ {% trans "to" %} +
— {% 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%}{% if status.endposition%} - {% blocktrans with endpage=status.endposition|intcomma %}{{ endpage }}{% endblocktrans %}{% endif%}) + {% blocktrans with page=status.position|intcomma %}(Page {{ page }}{% endblocktrans%}{% if status.endposition and status.endposition != status.position %} - {% blocktrans with endpage=status.endposition|intcomma %}{{ endpage }}{% endblocktrans %}{% endif%}) {% else %} - {% blocktrans with percent=status.position %}({{ percent }}%{% endblocktrans %}{% if status.endposition%}{% blocktrans with endpercent=status.endposition|intcomma %} - {{ endpercent }}%{% endblocktrans %}{% endif %}) + {% blocktrans with percent=status.position %}({{ percent }}%{% endblocktrans %}{% if status.endposition and status.endposition != status.position %}{% blocktrans with endpercent=status.endposition|intcomma %} - {{ endpercent }}%{% endblocktrans %}{% endif %}) {% endif %} {% endif %}