Skip to content

Commit

Permalink
Merge pull request #2638 from Giebisch/page-range
Browse files Browse the repository at this point in the history
Page Range
  • Loading branch information
hughrun authored Feb 27, 2023
2 parents 233cf80 + 43fe433 commit 3a67727
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions bookwyrm/forms/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Meta:
"sensitive",
"privacy",
"position",
"endposition",
"position_mode",
]

Expand Down
35 changes: 35 additions & 0 deletions bookwyrm/migrations/0174_auto_20230130_1240.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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",
),
),
]
3 changes: 3 additions & 0 deletions bookwyrm/models/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions bookwyrm/templates/snippets/create_status/quotation.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@
{% if not draft %}data-cache-draft="id_position_{{ book.id }}_{{ type }}"{% endif %}
>
</div>
<div class="button is-static">
{% trans "to" %}
</div>
<div class="control">
<input
aria-label="{% if draft.position_mode == 'PG' %}Page{% else %}Percent{% endif %}"
class="input"
type="number"
min="0"
name="endposition"
size="3"
value="{% firstof draft.endposition '' %}"
id="endposition_{{ uuid }}"
{% if not draft %}data-cache-draft="id_endposition_{{ book.id }}_{{ type }}"{% endif %}
>
</div>
</div>
</div>
{% endblock %}
4 changes: 2 additions & 2 deletions bookwyrm/templates/snippets/status/content_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ <h4 class="subtitle is-6">
&mdash; {% 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 and status.endposition != status.position %} - {% 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 and status.endposition != status.position %}{% blocktrans with endpercent=status.endposition|intcomma %} - {{ endpercent }}%{% endblocktrans %}{% endif %})
{% endif %}
{% endif %}
</p>
Expand Down
27 changes: 27 additions & 0 deletions bookwyrm/tests/views/books/test_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

_ = 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"""
Expand Down

0 comments on commit 3a67727

Please sign in to comment.