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 CommentForm(CustomForm):
class Meta: class Meta:
model = models.Comment model = models.Comment
fields = ["user", "book", "content", "content_warning", "sensitive", "privacy"] fields = ["user", "book", "content", "content_warning", "sensitive", "privacy", "progress", "mode"]
class QuotationForm(CustomForm): 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 .activitypub_mixin import OrderedCollectionPageMixin
from .base_model import BookWyrmModel from .base_model import BookWyrmModel
from .fields import image_serializer from .fields import image_serializer
from .readthrough import ProgressMode
from . import fields from . import fields
@ -229,6 +230,13 @@ class Comment(Status):
"Edition", on_delete=models.PROTECT, activitypub_field="inReplyToBook" "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 @property
def pure_content(self): def pure_content(self):
""" indicate the book in question for mastodon (or w/e) users """ """ indicate the book in question for mastodon (or w/e) users """

View File

@ -60,13 +60,14 @@
{% with readthrough=book.latest_readthrough %} {% with readthrough=book.latest_readthrough %}
<div class="field"> <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="field has-addons mb-0">
<div class="control"> <div class="control">
<input <input
aria-label="{% if readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}" aria-label="{% if readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}"
class="input" type="number" min="0" 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>
<div class="control select"> <div class="control select">
<select name="progress_mode" aria-label="Progress mode"> <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.status import delete_status
from bookwyrm.utils import regex from bookwyrm.utils import regex
from .helpers import handle_remote_webfinger from .helpers import handle_remote_webfinger
from .reading import edit_readthrough
# pylint: disable= no-self-use # pylint: disable= no-self-use
@ -64,6 +65,10 @@ class CreateStatus(View):
status.quote = to_markdown(status.quote) status.quote = to_markdown(status.quote)
status.save(created=True) status.save(created=True)
# update a readthorugh, if needed
edit_readthrough(request)
return redirect(request.headers.get("Referer", "/")) return redirect(request.headers.get("Referer", "/"))