Create and view quotation page numbers

This commit is contained in:
Mouse Reeve 2021-09-05 16:00:40 -07:00
parent 55b674258d
commit b80de929fd
7 changed files with 116 additions and 8 deletions

View file

@ -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"

View file

@ -101,6 +101,8 @@ class QuotationForm(CustomForm):
"content_warning",
"sensitive",
"privacy",
"position",
"position_mode",
]

View file

@ -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,
),
),
]

View file

@ -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):

View file

@ -26,13 +26,32 @@ uuid: a unique identifier used to make html "id" attributes unique and clarify j
<label class="label" for="progress_{{ uuid }}">{% trans "Progress:" %}</label>
<div class="field has-addons mb-0">
<div class="control">
<input aria-label="{% if draft.progress_mode == 'PG' or readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}" class="input" type="number" min="0" name="progress" size="3" value="{% firstof draft.progress readthrough.progress '' %}" id="progress_{{ uuid }}">
<input
aria-label="{% if draft.progress_mode == 'PG' or readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}"
class="input"
type="number"
min="0"
name="progress"
size="3"
value="{% firstof draft.progress readthrough.progress '' %}"
id="progress_{{ uuid }}"
>
</div>
<div class="control">
<div class="select">
<select name="progress_mode" aria-label="Progress mode">
<option value="PG" {% if draft.progress_mode == 'PG' or readthrough.progress_mode == 'PG' %}selected{% endif %}>{% trans "pages" %}</option>
<option value="PCT" {% if draft.progress_mode == 'PCT' or readthrough.progress_mode == 'PCT' %}selected{% endif %}>{% trans "percent" %}</option>
<option
value="PG"
{% if draft.progress_mode == 'PG' or readthrough.progress_mode == 'PG' %}selected{% endif %}
>
{% trans "pages" %}
</option>
<option
value="PCT"
{% if draft.progress_mode == 'PCT' or readthrough.progress_mode == 'PCT' %}selected{% endif %}
>
{% trans "percent" %}
</option>
</select>
</div>
</div>

View file

@ -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 %}
<div class="field">
<label class="label" for="id_quote_{{ book.id }}_{{ type }}">
@ -29,6 +27,39 @@ uuid: a unique identifier used to make html "id" attributes unique and clarify j
>{{ draft.quote|default:'' }}</textarea>
</div>
</div>
<div class="field">
<label class="label" for="position_{{ uuid }}">{% trans "Position:" %}</label>
<div class="field has-addons mb-0">
<div class="control">
<div class="select">
<select name="position_mode" aria-label="Position mode">
<option
value="PG"
{% if draft.position_mode == 'PG' or not draft %}selected{% endif %}
>
{% trans "On page:" %}
</option>
<option
value="PCT"
{% if draft.position_mode == 'PCT' %}selected{% endif %}
>
{% trans "At percent:" %}
</option>
</select>
</div>
</div>
<div class="control">
<input
aria-label="{% if draft.position_mode == 'PG' %}Page{% else %}Percent{% endif %}"
class="input"
type="number"
min="0"
name="position"
size="3"
value="{% firstof draft.position '' %}"
id="position_{{ uuid }}"
>
</div>
</div>
</div>
{% endblock %}
{% endwith %}

View file

@ -2,6 +2,7 @@
{% load markdown %}
{% load i18n %}
{% load static %}
{% load humanize %}
{% with status_type=status.status_type %}
<div
@ -95,7 +96,16 @@
<div class="quote block">
<blockquote dir="auto" class="content mb-2">{{ status.quote|safe }}</blockquote>
<p> &mdash; {% include 'snippets/book_titleby.html' with book=status.book %}</p>
<p>
&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 %}
{% else %}
{% blocktrans with percent=status.position %}({{ percent }}%){% endblocktrans %}
{% endif %}
{% endif %}
</p>
</div>
{% endif %}