forked from mirrors/bookwyrm
Merge pull request #1934 from tversteeg/partially-read-shelf
Add 'Stopped Reading' shelf
This commit is contained in:
commit
f2b0b306e9
19 changed files with 206 additions and 7 deletions
77
bookwyrm/migrations/0134_alter_stopped_reading.py
Normal file
77
bookwyrm/migrations/0134_alter_stopped_reading.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
# Generated by Django 3.2.11 on 2022-02-11 13:19
|
||||
|
||||
import bookwyrm.models.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def add_shelves(apps, schema_editor):
|
||||
"""add any superusers to the "admin" group"""
|
||||
|
||||
db_alias = schema_editor.connection.alias
|
||||
shelf_model = apps.get_model("bookwyrm", "Shelf")
|
||||
|
||||
users = apps.get_model("bookwyrm", "User")
|
||||
local_users = users.objects.using(db_alias).filter(local=True)
|
||||
for user in local_users:
|
||||
shelf_model.using(db_alias)(
|
||||
name="Stopped reading",
|
||||
identifier=Shelf.STOPPED_READING,
|
||||
user=user,
|
||||
editable=False,
|
||||
).save(broadcast=False)
|
||||
|
||||
|
||||
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"),
|
||||
("stopped-reading", "Stopped-Reading"),
|
||||
],
|
||||
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"),
|
||||
("stopped-reading", "Stopped-Reading"),
|
||||
],
|
||||
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"),
|
||||
("stopped-reading", "Stopped-Reading"),
|
||||
],
|
||||
max_length=255,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
migrations.RunPython(add_shelves, reverse_code=migrations.RunPython.noop),
|
||||
]
|
13
bookwyrm/migrations/0142_merge_20220225_2103.py
Normal file
13
bookwyrm/migrations/0142_merge_20220225_2103.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Generated by Django 3.2.12 on 2022-02-25 21:03
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0134_alter_stopped_reading"),
|
||||
("bookwyrm", "0141_alter_report_status"),
|
||||
]
|
||||
|
||||
operations = []
|
13
bookwyrm/migrations/0145_merge_20220312_1040.py
Normal file
13
bookwyrm/migrations/0145_merge_20220312_1040.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Generated by Django 3.2.12 on 2022-03-12 10:40
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0142_merge_20220225_2103"),
|
||||
("bookwyrm", "0144_alter_announcement_display_type"),
|
||||
]
|
||||
|
||||
operations = []
|
|
@ -17,8 +17,9 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel):
|
|||
TO_READ = "to-read"
|
||||
READING = "reading"
|
||||
READ_FINISHED = "read"
|
||||
STOPPED_READING = "stopped-reading"
|
||||
|
||||
READ_STATUS_IDENTIFIERS = (TO_READ, READING, READ_FINISHED)
|
||||
READ_STATUS_IDENTIFIERS = (TO_READ, READING, READ_FINISHED, STOPPED_READING)
|
||||
|
||||
name = fields.CharField(max_length=100)
|
||||
identifier = models.CharField(max_length=100)
|
||||
|
|
|
@ -265,7 +265,7 @@ class GeneratedNote(Status):
|
|||
|
||||
|
||||
ReadingStatusChoices = models.TextChoices(
|
||||
"ReadingStatusChoices", ["to-read", "reading", "read"]
|
||||
"ReadingStatusChoices", ["to-read", "reading", "read", "stopped-reading"]
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -374,6 +374,10 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
"name": "Read",
|
||||
"identifier": "read",
|
||||
},
|
||||
{
|
||||
"name": "Stopped Reading",
|
||||
"identifier": "stopped-reading",
|
||||
},
|
||||
]
|
||||
|
||||
for shelf in shelves:
|
||||
|
|
|
@ -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 == 'stopped-reading' %}{% trans "Stopped Reading" %}
|
||||
{% else %}{{ shelf.name }}{% endif %}
|
||||
</option>
|
||||
{% endfor %}
|
||||
|
|
14
bookwyrm/templates/reading_progress/stop.html
Normal file
14
bookwyrm/templates/reading_progress/stop.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}
|
||||
{% blocktrans trimmed with book_title=book.title %}
|
||||
Stop Reading "{{ book_title }}"
|
||||
{% endblocktrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% include "snippets/reading_modals/stop_reading_modal.html" with book=book active=True static=True %}
|
||||
|
||||
{% endblock %}
|
|
@ -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 == 'stopped-reading' %}{% trans "Stopped Reading" %}
|
||||
{% else %}{{ shelf.name }}{% endif %}
|
||||
<span class="subtitle">
|
||||
{% include 'snippets/privacy-icons.html' with item=shelf %}
|
||||
|
@ -150,7 +151,7 @@
|
|||
{% if is_self %}
|
||||
<th>{% trans "Shelved" as text %}{% include 'snippets/table-sort-header.html' with field="shelved_date" sort=sort text=text %}</th>
|
||||
<th>{% trans "Started" as text %}{% include 'snippets/table-sort-header.html' with field="start_date" sort=sort text=text %}</th>
|
||||
<th>{% trans "Finished" as text %}{% include 'snippets/table-sort-header.html' with field="finish_date" sort=sort text=text %}</th>
|
||||
<th>{% if shelf.identifier == 'read' %}{% trans "Finished" as text %}{% else %}{% trans "Until" as text %}{% endif %}{% include 'snippets/table-sort-header.html' with field="finish_date" sort=sort text=text %}</th>
|
||||
{% endif %}
|
||||
<th>{% trans "Rating" as text %}{% include 'snippets/table-sort-header.html' with field="rating" sort=sort text=text %}</th>
|
||||
{% endif %}
|
||||
|
@ -180,7 +181,7 @@
|
|||
<td data-title="{% trans "Started" %}">
|
||||
{{ book.start_date|naturalday|default_if_none:""}}
|
||||
</td>
|
||||
<td data-title="{% trans "Finished" %}">
|
||||
<td data-title="{% if shelf.identifier == 'read' %}{% trans "Finished" as text %}{% else %}{% trans "Until" as text %}{% endif %}">
|
||||
{{ book.finish_date|naturalday|default_if_none:""}}
|
||||
</td>
|
||||
{% endif %}
|
||||
|
|
|
@ -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 %}
|
||||
Stop Reading "<em>{{ book_title }}</em>"
|
||||
{% endblocktrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-form-open %}
|
||||
<form name="stop-reading-{{ 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="stop_id_start_date_{{ uuid }}">
|
||||
{% trans "Started reading" %}
|
||||
</label>
|
||||
<input type="date" name="start_date" class="input" id="stop_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_read_until_date_{{ uuid }}">
|
||||
{% trans "Read until" %}
|
||||
</label>
|
||||
<input type="date" name="finish_date" class="input" id="id_read_until_date_{{ uuid }}" value="{% now "Y-m-d" %}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block form %}
|
||||
{% include "snippets/reading_modals/form.html" with optional=True type="stop_modal" %}
|
||||
{% endblock %}
|
|
@ -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 == 'stopped-reading' %}
|
||||
|
||||
{% trans "Stopped reading" as button_text %}
|
||||
{% url 'reading-status' 'stop' book.id as fallback_url %}
|
||||
{% join "stop_reading" 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 %}
|
||||
|
@ -99,5 +106,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 "stop_reading" uuid as modal_id %}
|
||||
{% include 'snippets/reading_modals/stop_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id readthrough=readthrough refresh=True class="" %}
|
||||
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -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 "stop_reading" uuid as modal_id %}
|
||||
{% include 'snippets/reading_modals/stop_reading_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="" %}
|
||||
|
||||
|
|
|
@ -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 == 'stopped-reading' %}
|
||||
|
||||
{% trans "Stop reading" as button_text %}
|
||||
{% url 'reading-status' 'stop' book.id as fallback_url %}
|
||||
{% join "stop_reading" 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 %}
|
||||
|
|
|
@ -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 == 'stopped-reading' %}
|
||||
|
||||
{% trans "Stop reading" as button_text %}
|
||||
{% url 'reading-status' 'stop' book.id as fallback_url %}
|
||||
{% join "stop_reading" 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 %}
|
||||
|
|
|
@ -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 == 'Stopped Reading' %}{% trans "Stopped Reading" %}
|
||||
{% 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 %}
|
||||
|
|
|
@ -53,15 +53,17 @@ class User(TestCase):
|
|||
|
||||
def test_user_shelves(self):
|
||||
shelves = models.Shelf.objects.filter(user=self.user).all()
|
||||
self.assertEqual(len(shelves), 3)
|
||||
self.assertEqual(len(shelves), 4)
|
||||
names = [s.name for s in shelves]
|
||||
self.assertTrue("To Read" in names)
|
||||
self.assertTrue("Currently Reading" in names)
|
||||
self.assertTrue("Read" in names)
|
||||
self.assertTrue("Stopped Reading" 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("stopped-reading" in ids)
|
||||
|
||||
def test_activitypub_serialize(self):
|
||||
activity = self.user.to_activity()
|
||||
|
|
|
@ -592,7 +592,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",
|
||||
),
|
||||
|
|
|
@ -137,6 +137,7 @@ def handle_reading_status(user, shelf, book, privacy):
|
|||
"to-read": "wants to read",
|
||||
"reading": "started reading",
|
||||
"read": "finished reading",
|
||||
"stopped-reading": "stopped reading",
|
||||
}[shelf.identifier]
|
||||
except KeyError:
|
||||
# it's a non-standard shelf, don't worry about it
|
||||
|
|
|
@ -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.STOPPED_READING,
|
||||
}.get(status)
|
||||
if not identifier:
|
||||
return HttpResponseBadRequest()
|
||||
|
|
Loading…
Reference in a new issue