Add 'Partially Read' shelf

This commit is contained in:
Thomas Versteeg 2022-02-11 14:33:46 +01:00
parent 542957364c
commit 2b27889457
16 changed files with 116 additions and 4 deletions

View file

@ -0,0 +1,29 @@
# Generated by Django 3.2.11 on 2022-02-11 13:19
import bookwyrm.models.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0133_alter_listitem_notes'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='reading_status',
field=bookwyrm.models.fields.CharField(blank=True, choices=[('to-read', 'To-Read'), ('reading', 'Reading'), ('read', 'Read'), ('partially-read', 'Partially-Read')], max_length=255, null=True),
),
migrations.AlterField(
model_name='quotation',
name='reading_status',
field=bookwyrm.models.fields.CharField(blank=True, choices=[('to-read', 'To-Read'), ('reading', 'Reading'), ('read', 'Read'), ('partially-read', 'Partially-Read')], max_length=255, null=True),
),
migrations.AlterField(
model_name='review',
name='reading_status',
field=bookwyrm.models.fields.CharField(blank=True, choices=[('to-read', 'To-Read'), ('reading', 'Reading'), ('read', 'Read'), ('partially-read', 'Partially-Read')], max_length=255, null=True),
),
]

View file

@ -17,8 +17,9 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel):
TO_READ = "to-read"
READING = "reading"
READ_FINISHED = "read"
PARTIALLY_READ = "partially-read"
READ_STATUS_IDENTIFIERS = (TO_READ, READING, READ_FINISHED)
READ_STATUS_IDENTIFIERS = (TO_READ, READING, READ_FINISHED, PARTIALLY_READ)
name = fields.CharField(max_length=100)
identifier = models.CharField(max_length=100)

View file

@ -265,7 +265,7 @@ class GeneratedNote(Status):
ReadingStatusChoices = models.TextChoices(
"ReadingStatusChoices", ["to-read", "reading", "read"]
"ReadingStatusChoices", ["to-read", "reading", "read", "partially-read"]
)

View file

@ -372,6 +372,10 @@ class User(OrderedCollectionPageMixin, AbstractUser):
"name": "Read",
"identifier": "read",
},
{
"name": "Partially Read",
"identifier": "partially-read",
},
]
for shelf in shelves:

View file

@ -10,6 +10,7 @@
{% if shelf.identifier == 'to-read' %}{% trans "To Read" %}
{% elif shelf.identifier == 'reading' %}{% trans "Currently Reading" %}
{% elif shelf.identifier == 'read' %}{% trans "Read" %}
{% elif shelf.identifier == 'partially-read' %}{% trans "Partially Read" %}
{% else %}{{ shelf.name }}{% endif %}
</option>
{% endfor %}

View file

@ -86,6 +86,7 @@
{% if shelf.identifier == 'to-read' %}{% trans "To Read" %}
{% elif shelf.identifier == 'reading' %}{% trans "Currently Reading" %}
{% elif shelf.identifier == 'read' %}{% trans "Read" %}
{% elif shelf.identifier == 'partially-read' %}{% trans "Partially Read" %}
{% else %}{{ shelf.name }}{% endif %}
<span class="subtitle">
{% include 'snippets/privacy-icons.html' with item=shelf %}

View file

@ -0,0 +1,42 @@
{% extends 'snippets/reading_modals/layout.html' %}
{% load i18n %}
{% load utilities %}
{% block modal-title %}
{% blocktrans trimmed with book_title=book|book_title %}
Partially Read "<em>{{ book_title }}</em>"
{% endblocktrans %}
{% endblock %}
{% block modal-form-open %}
<form name="partially-read-{{ uuid }}" action="{% url 'reading-status' 'stop' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}>
{% csrf_token %}
<input type="hidden" name="id" value="{{ readthrough.id }}">
<input type="hidden" name="reading_status" value="stop">
<input type="hidden" name="shelf" value="{{ move_from }}">
{% endblock %}
{% block reading-dates %}
<div class="columns">
<div class="column is-half">
<div class="field">
<label class="label" for="finish_id_start_date_{{ uuid }}">
{% trans "Started reading" %}
</label>
<input type="date" name="start_date" class="input" id="finish_id_start_date_{{ uuid }}" value="{{ readthrough.start_date | date:"Y-m-d" }}">
</div>
</div>
<div class="column is-half">
<div class="field">
<label class="label" for="id_finish_date_{{ uuid }}">
{% trans "Stopped reading" %}
</label>
<input type="date" name="finish_date" class="input" id="id_finish_date_{{ uuid }}" value="{% now "Y-m-d" %}">
</div>
</div>
</div>
{% endblock %}
{% block form %}
{% include "snippets/reading_modals/form.html" with optional=True type="partially_read_model" %}
{% endblock %}

View file

@ -49,6 +49,13 @@
{% join "finish_reading" uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=button_class fallback_url=fallback_url %}
{% elif shelf.identifier == 'partially-read' %}
{% trans "Partially read" as button_text %}
{% url 'reading-status' 'stop' book.id as fallback_url %}
{% join "partially_read" uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=button_class fallback_url=fallback_url %}
{% elif shelf.identifier == 'to-read' %}
{% trans "Want to read" as button_text %}
@ -97,5 +104,8 @@
{% join "finish_reading" uuid as modal_id %}
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id readthrough=readthrough refresh=True class="" %}
{% join "partially_read" uuid as modal_id %}
{% include 'snippets/reading_modals/partially_read_modal.html' with book=active_shelf.book id=modal_id move_from=current.id readthrough=readthrough refresh=True class="" %}
{% endwith %}
{% endblock %}

View file

@ -29,6 +29,9 @@
{% join "finish_reading" uuid as modal_id %}
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf_book id=modal_id readthrough=readthrough class="" %}
{% join "partially_read" uuid as modal_id %}
{% include 'snippets/reading_modals/partially_read_modal.html' with book=active_shelf_book id=modal_id readthrough=readthrough class="" %}
{% join "progress_update" uuid as modal_id %}
{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf_book id=modal_id readthrough=readthrough class="" %}

View file

@ -26,6 +26,13 @@
{% join "finish_reading" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.identifier == 'partially-read' %}
{% trans "Partially read" as button_text %}
{% url 'reading-status' 'stop' book.id as fallback_url %}
{% join "partially_read" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.identifier == 'to-read' %}
{% trans "Want to read" as button_text %}

View file

@ -33,6 +33,13 @@
{% join "finish_reading" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.identifier == 'partially-read' %}
{% trans "Stop reading" as button_text %}
{% url 'reading-status' 'stop' book.id as fallback_url %}
{% join "partially_read" button_uuid as modal_id %}
{% include 'snippets/shelve_button/modal_button.html' with class=class fallback_url=fallback_url %}
{% elif shelf.identifier == 'to-read' %}
{% trans "Want to read" as button_text %}

View file

@ -7,6 +7,8 @@
{% trans "Currently Reading" %}
{% elif shelf.identifier == 'read' %}
{% trans "Read" %}
{% elif shelf.identifier == 'partially-read' %}
{% trans "Partially Read" %}
{% else %}
{{ shelf.name }}
{% endif %}

View file

@ -33,8 +33,9 @@
{% if shelf.name == 'To Read' %}{% trans "To Read" %}
{% elif shelf.name == 'Currently Reading' %}{% trans "Currently Reading" %}
{% elif shelf.name == 'Read' %}{% trans "Read" %}
{% elif shelf.name == 'Partially Read' %}{% trans "Partially Read" %}
{% else %}{{ shelf.name }}{% endif %}
{% if shelf.size > 3 %}<small>(<a href="{{ shelf.local_path }}">{% blocktrans with size=shelf.size %}View all {{ size }}{% endblocktrans %}</a>)</small>{% endif %}
{% if shelf.size > 4 %}<small>(<a href="{{ shelf.local_path }}">{% blocktrans with size=shelf.size %}View all {{ size }}{% endblocktrans %}</a>)</small>{% endif %}
</h3>
<div class="is-mobile field is-grouped">
{% for book in shelf.books %}

View file

@ -58,10 +58,12 @@ class User(TestCase):
self.assertTrue("To Read" in names)
self.assertTrue("Currently Reading" in names)
self.assertTrue("Read" in names)
self.assertTrue("Partially Read" in names)
ids = [s.identifier for s in shelves]
self.assertTrue("to-read" in ids)
self.assertTrue("reading" in ids)
self.assertTrue("read" in ids)
self.assertTrue("partially-read" in ids)
def test_activitypub_serialize(self):
activity = self.user.to_activity()

View file

@ -543,7 +543,7 @@ urlpatterns = [
name="reading-status-update",
),
re_path(
r"^reading-status/(?P<status>want|start|finish)/(?P<book_id>\d+)/?$",
r"^reading-status/(?P<status>want|start|finish|stop)/(?P<book_id>\d+)/?$",
views.ReadingStatus.as_view(),
name="reading-status",
),

View file

@ -29,6 +29,7 @@ class ReadingStatus(View):
"want": "want.html",
"start": "start.html",
"finish": "finish.html",
"stop": "stop.html",
}.get(status)
if not template:
return HttpResponseNotFound()
@ -41,6 +42,7 @@ class ReadingStatus(View):
"want": models.Shelf.TO_READ,
"start": models.Shelf.READING,
"finish": models.Shelf.READ_FINISHED,
"stop": models.Shelf.PARTIALLY_READ,
}.get(status)
if not identifier:
return HttpResponseBadRequest()