2021-03-08 11:49:10 -05:00
|
|
|
""" using django model forms """
|
2020-03-23 12:40:09 -04:00
|
|
|
from django import forms
|
2022-03-14 14:46:08 -04:00
|
|
|
from django.forms import widgets
|
2021-04-04 16:22:36 -04:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-01-29 04:05:27 -05:00
|
|
|
|
2020-09-21 11:10:37 -04:00
|
|
|
from bookwyrm import models
|
2021-11-24 05:59:45 -05:00
|
|
|
from bookwyrm.models.user import FeedFilterChoices
|
2022-03-14 14:46:08 -04:00
|
|
|
from .custom_form import CustomForm
|
2020-09-29 13:21:10 -04:00
|
|
|
|
2020-12-22 12:26:40 -05:00
|
|
|
|
2020-12-12 21:13:00 -05:00
|
|
|
# pylint: disable=missing-class-docstring
|
2021-11-22 12:52:57 -05:00
|
|
|
class FeedStatusTypesForm(CustomForm):
|
2021-11-21 18:25:47 -05:00
|
|
|
class Meta:
|
|
|
|
model = models.User
|
|
|
|
fields = ["feed_status_types"]
|
|
|
|
help_texts = {f: None for f in fields}
|
|
|
|
widgets = {
|
2021-11-22 12:52:57 -05:00
|
|
|
"feed_status_types": widgets.CheckboxSelectMultiple(
|
2021-11-24 05:59:45 -05:00
|
|
|
choices=FeedFilterChoices,
|
2021-11-21 18:25:47 -05:00
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-23 12:40:09 -04:00
|
|
|
class ImportForm(forms.Form):
|
|
|
|
csv_file = forms.FileField()
|
2020-06-03 12:38:30 -04:00
|
|
|
|
2021-03-08 11:49:10 -05:00
|
|
|
|
2020-11-10 17:52:04 -05:00
|
|
|
class ShelfForm(CustomForm):
|
|
|
|
class Meta:
|
|
|
|
model = models.Shelf
|
2021-09-28 19:36:47 -04:00
|
|
|
fields = ["user", "name", "privacy", "description"]
|
2021-01-16 11:18:54 -05:00
|
|
|
|
2021-01-29 18:38:42 -05:00
|
|
|
|
2021-01-16 11:18:54 -05:00
|
|
|
class GoalForm(CustomForm):
|
|
|
|
class Meta:
|
|
|
|
model = models.AnnualGoal
|
2021-03-08 11:49:10 -05:00
|
|
|
fields = ["user", "year", "goal", "privacy"]
|
2021-01-29 18:38:42 -05:00
|
|
|
|
|
|
|
|
2021-03-08 21:36:34 -05:00
|
|
|
class ReportForm(CustomForm):
|
|
|
|
class Meta:
|
|
|
|
model = models.Report
|
2022-02-24 15:48:52 -05:00
|
|
|
fields = ["user", "reporter", "status", "links", "note"]
|
2021-04-07 14:52:13 -04:00
|
|
|
|
|
|
|
|
2022-01-11 12:50:04 -05:00
|
|
|
class ReadThroughForm(CustomForm):
|
2022-01-11 13:22:01 -05:00
|
|
|
def clean(self):
|
|
|
|
"""make sure the email isn't in use by a registered user"""
|
|
|
|
cleaned_data = super().clean()
|
|
|
|
start_date = cleaned_data.get("start_date")
|
|
|
|
finish_date = cleaned_data.get("finish_date")
|
2022-01-17 22:46:48 -05:00
|
|
|
if start_date and finish_date and start_date > finish_date:
|
2022-01-11 13:22:01 -05:00
|
|
|
self.add_error(
|
|
|
|
"finish_date", _("Reading finish date cannot be before start date.")
|
|
|
|
)
|
|
|
|
|
2022-01-11 12:50:04 -05:00
|
|
|
class Meta:
|
|
|
|
model = models.ReadThrough
|
|
|
|
fields = ["user", "book", "start_date", "finish_date"]
|