Update progress with comments

This commit is contained in:
Mouse Reeve 2021-03-20 17:34:58 -07:00
parent 942c4a6664
commit daa0268eb3
5 changed files with 41 additions and 3 deletions

View file

@ -76,7 +76,7 @@ class ReviewForm(CustomForm):
class CommentForm(CustomForm):
class Meta:
model = models.Comment
fields = ["user", "book", "content", "content_warning", "sensitive", "privacy"]
fields = ["user", "book", "content", "content_warning", "sensitive", "privacy", "progress", "mode"]
class QuotationForm(CustomForm):

View file

@ -0,0 +1,24 @@
# Generated by Django 3.1.6 on 2021-03-21 00:25
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0054_auto_20210319_1942'),
]
operations = [
migrations.AddField(
model_name='comment',
name='mode',
field=models.CharField(blank=True, choices=[('PG', 'page'), ('PCT', 'percent')], default='PG', max_length=3, null=True),
),
migrations.AddField(
model_name='comment',
name='progress',
field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
]

View file

@ -14,6 +14,7 @@ from .activitypub_mixin import ActivitypubMixin, ActivityMixin
from .activitypub_mixin import OrderedCollectionPageMixin
from .base_model import BookWyrmModel
from .fields import image_serializer
from .readthrough import ProgressMode
from . import fields
@ -229,6 +230,13 @@ class Comment(Status):
"Edition", on_delete=models.PROTECT, activitypub_field="inReplyToBook"
)
# this is it's own field instead of a foreign key to the progress update
# so that the update can be deleted without impacting the status
progress = models.IntegerField(validators=[MinValueValidator(0)], null=True, blank=True)
mode = models.CharField(
max_length=3, choices=ProgressMode.choices, default=ProgressMode.PAGE, null=True, blank=True
)
@property
def pure_content(self):
""" indicate the book in question for mastodon (or w/e) users """

View file

@ -60,13 +60,14 @@
{% with readthrough=book.latest_readthrough %}
<div class="field">
<label class="label" for="progress">{% trans "Progress:" %}</label>
<input type="hidden" name="id" value="{{ readthrough.id }}"/>
<label class="label" for="progress-{{ uuid }}">{% trans "Progress:" %}</label>
<div class="field has-addons mb-0">
<div class="control">
<input
aria-label="{% if readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}"
class="input" type="number" min="0"
name="progress" size="3" value="{{ readthrough.progress|default:'' }}">
name="progress" size="3" value="{{ readthrough.progress|default:'' }}" id="progress-{{ uuid }}">
</div>
<div class="control select">
<select name="progress_mode" aria-label="Progress mode">

View file

@ -13,6 +13,7 @@ from bookwyrm.settings import DOMAIN
from bookwyrm.status import delete_status
from bookwyrm.utils import regex
from .helpers import handle_remote_webfinger
from .reading import edit_readthrough
# pylint: disable= no-self-use
@ -64,6 +65,10 @@ class CreateStatus(View):
status.quote = to_markdown(status.quote)
status.save(created=True)
# update a readthorugh, if needed
edit_readthrough(request)
return redirect(request.headers.get("Referer", "/"))