+ {{ year }} reading goal +
+Set a goal for how many books you'll finish reading in {{ year }}, and track your progress throughout the year.
+ + {% include 'snippets/goal_form.html' %} +diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py
index d57d90f3..0e3ac9c1 100644
--- a/bookwyrm/forms.py
+++ b/bookwyrm/forms.py
@@ -192,4 +192,4 @@ class ShelfForm(CustomForm):
class GoalForm(CustomForm):
class Meta:
model = models.AnnualGoal
- fields = ['user', 'year', 'goal']
+ fields = ['user', 'year', 'goal', 'privacy']
diff --git a/bookwyrm/migrations/0036_annualgoal.py b/bookwyrm/migrations/0036_annualgoal.py
index 9e86f624..fb12833e 100644
--- a/bookwyrm/migrations/0036_annualgoal.py
+++ b/bookwyrm/migrations/0036_annualgoal.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.0.7 on 2021-01-15 23:01
+# Generated by Django 3.0.7 on 2021-01-16 18:43
import bookwyrm.models.fields
from django.conf import settings
@@ -20,9 +20,10 @@ class Migration(migrations.Migration):
('created_date', models.DateTimeField(auto_now_add=True)),
('updated_date', models.DateTimeField(auto_now=True)),
('remote_id', bookwyrm.models.fields.RemoteIdField(max_length=255, null=True, validators=[bookwyrm.models.fields.validate_remote_id])),
- ('goal', bookwyrm.models.fields.IntegerField()),
+ ('goal', models.IntegerField()),
('year', models.IntegerField(default=2021)),
- ('user', bookwyrm.models.fields.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
+ ('privacy', models.CharField(choices=[('public', 'Public'), ('unlisted', 'Unlisted'), ('followers', 'Followers'), ('direct', 'Direct')], default='public', max_length=255)),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
options={
'unique_together': {('user', 'year')},
diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py
index 5c59496e..6697b1b8 100644
--- a/bookwyrm/models/user.py
+++ b/bookwyrm/models/user.py
@@ -19,7 +19,7 @@ from bookwyrm.utils import regex
from .base_model import OrderedCollectionPageMixin
from .base_model import ActivitypubMixin, BookWyrmModel
from .federated_server import FederatedServer
-from . import fields
+from . import fields, Review
class User(OrderedCollectionPageMixin, AbstractUser):
@@ -224,9 +224,14 @@ class KeyPair(ActivitypubMixin, BookWyrmModel):
class AnnualGoal(BookWyrmModel):
''' set a goal for how many books you read in a year '''
- user = fields.ForeignKey('User', on_delete=models.PROTECT)
- goal = fields.IntegerField()
+ user = models.ForeignKey('User', on_delete=models.PROTECT)
+ goal = models.IntegerField()
year = models.IntegerField(default=timezone.now().year)
+ privacy = models.CharField(
+ max_length=255,
+ default='public',
+ choices=fields.PrivacyLevels.choices
+ )
class Meta:
''' unqiueness constraint '''
@@ -243,6 +248,23 @@ class AnnualGoal(BookWyrmModel):
finish_date__year__gte=self.year
).order_by('finish_date').all()
+
+ @property
+ def ratings(self):
+ ''' ratings for books read this year '''
+ book_ids = [r.book.id for r in self.books]
+ reviews = Review.objects.filter(
+ user=self.user,
+ book__in=book_ids,
+ )
+ return {r.book.id: r.rating for r in reviews}
+
+
+ @property
+ def progress_percent(self):
+ return int(float(self.book_count / self.goal) * 100)
+
+
@property
def book_count(self):
''' how many books you've read this year '''
diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html
index b37c6b74..79dd4b85 100644
--- a/bookwyrm/templates/feed.html
+++ b/bookwyrm/templates/feed.html
@@ -71,7 +71,8 @@
{% if goal %}
Set a goal for how many books you'll finish reading in {{ year }}, and track your progress throughout the year. {{ user.display_name }} hasn't set a reading goal for {{ year }}.{{ goal.year }} Reading Goal
+ {% include 'snippets/goal_progress.html' with goal=goal %}
{{ year }} Reading Progress
+ {% if not goal and user == request.user %}
+ {% now 'Y' as year %}
+
+ {{ year }} reading goal
+
+ {% if goal.user == request.user %}Your{% else %}{{ goal.user.display_name }}'s{% endif %} {{ year }} Books
+