From 6efe4d54f008ae2051fba642a0aac431c2f2e7e1 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 19 Jan 2021 07:30:35 -0800 Subject: [PATCH 1/4] Sets minimum goal --- bookwyrm/models/user.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 1e9db401..79d11206 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -4,6 +4,7 @@ from urllib.parse import urlparse from django.apps import apps from django.contrib.auth.models import AbstractUser +from django.core.validators import MinValueValidator from django.db import models from django.dispatch import receiver from django.utils import timezone @@ -226,7 +227,9 @@ class KeyPair(ActivitypubMixin, BookWyrmModel): class AnnualGoal(BookWyrmModel): ''' set a goal for how many books you read in a year ''' user = models.ForeignKey('User', on_delete=models.PROTECT) - goal = models.IntegerField() + goal = models.IntegerField( + validators=[MinValueValidator(1)] + ) year = models.IntegerField(default=timezone.now().year) privacy = models.CharField( max_length=255, From 328ebc39c1407abf7a0924c8e242a806cd81d7e5 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 19 Jan 2021 07:38:12 -0800 Subject: [PATCH 2/4] Adds migration --- .../migrations/0038_auto_20210119_1534.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bookwyrm/migrations/0038_auto_20210119_1534.py diff --git a/bookwyrm/migrations/0038_auto_20210119_1534.py b/bookwyrm/migrations/0038_auto_20210119_1534.py new file mode 100644 index 00000000..ac7a0d68 --- /dev/null +++ b/bookwyrm/migrations/0038_auto_20210119_1534.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2021-01-19 15:34 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0037_auto_20210118_1954'), + ] + + operations = [ + migrations.AlterField( + model_name='annualgoal', + name='goal', + field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1)]), + ), + ] From 589c128793547836d92e31f76750d01caf461228 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 19 Jan 2021 07:38:18 -0800 Subject: [PATCH 3/4] Sets min in html --- bookwyrm/templates/snippets/goal_form.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/snippets/goal_form.html b/bookwyrm/templates/snippets/goal_form.html index bd36f609..475c5da5 100644 --- a/bookwyrm/templates/snippets/goal_form.html +++ b/bookwyrm/templates/snippets/goal_form.html @@ -8,7 +8,7 @@
- +
From c1c7b68fc1ac9f1c15fbe106526c81741a528513 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 19 Jan 2021 07:40:37 -0800 Subject: [PATCH 4/4] Fixes error state for goal --- bookwyrm/views/goal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/goal.py b/bookwyrm/views/goal.py index 45fe614b..f1954672 100644 --- a/bookwyrm/views/goal.py +++ b/bookwyrm/views/goal.py @@ -52,7 +52,7 @@ class Goal(View): form = forms.GoalForm(request.POST, instance=goal) if not form.is_valid(): data = { - 'title': '%s\'s %d Reading' % (goal.user.display_name, year), + 'title': '%s\'s %d Reading' % (request.user.display_name, year), 'goal_form': form, 'goal': goal, 'year': year,