diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index edf1d9e4..6cc81c04 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -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): diff --git a/bookwyrm/migrations/0055_auto_20210321_0025.py b/bookwyrm/migrations/0055_auto_20210321_0025.py new file mode 100644 index 00000000..446181f9 --- /dev/null +++ b/bookwyrm/migrations/0055_auto_20210321_0025.py @@ -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)]), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 09a7c4ec..60c00f5a 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -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 """ diff --git a/bookwyrm/templates/snippets/create_status_form.html b/bookwyrm/templates/snippets/create_status_form.html index d0b763bf..75f5d28b 100644 --- a/bookwyrm/templates/snippets/create_status_form.html +++ b/bookwyrm/templates/snippets/create_status_form.html @@ -60,13 +60,14 @@ {% with readthrough=book.latest_readthrough %}
- + +
+ name="progress" size="3" value="{{ readthrough.progress|default:'' }}" id="progress-{{ uuid }}">