Merge pull request #545 from mouse-reeve/goal-min-2

Goal min
This commit is contained in:
Mouse Reeve 2021-01-19 07:49:28 -08:00 committed by GitHub
commit 243e998fbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View file

@ -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)]),
),
]

View file

@ -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,

View file

@ -8,7 +8,7 @@
<label class="label" for="id_goal">Reading goal:</label>
<div class="field has-addons">
<div class="control">
<input type="number" class="input" name="goal" id="id_goal" value="{% if goal %}{{ goal.goal }}{% else %}12{% endif %}">
<input type="number" class="input" name="goal" min="1" id="id_goal" value="{% if goal %}{{ goal.goal }}{% else %}12{% endif %}">
</div>
<p class="button is-static" aria-hidden="true">books</p>
</div>

View file

@ -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,