2022-03-14 18:46:08 +00:00
|
|
|
""" using django model forms """
|
|
|
|
from django import forms
|
|
|
|
|
2023-11-05 05:34:24 +00:00
|
|
|
from file_resubmit.widgets import ResubmitImageWidget
|
2023-10-30 10:47:19 +00:00
|
|
|
|
|
|
|
from bookwyrm import models
|
2022-03-14 18:46:08 +00:00
|
|
|
from .custom_form import CustomForm
|
2022-03-19 15:44:30 +00:00
|
|
|
from .widgets import ArrayWidget, SelectDateWidget, Select
|
2022-03-14 18:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=missing-class-docstring
|
|
|
|
class CoverForm(CustomForm):
|
|
|
|
class Meta:
|
|
|
|
model = models.Book
|
|
|
|
fields = ["cover"]
|
|
|
|
help_texts = {f: None for f in fields}
|
|
|
|
|
|
|
|
|
|
|
|
class EditionForm(CustomForm):
|
|
|
|
class Meta:
|
|
|
|
model = models.Edition
|
2022-12-11 18:58:19 +00:00
|
|
|
fields = [
|
|
|
|
"title",
|
2023-04-27 04:05:03 +00:00
|
|
|
"sort_title",
|
2022-12-11 18:58:19 +00:00
|
|
|
"subtitle",
|
|
|
|
"description",
|
|
|
|
"series",
|
|
|
|
"series_number",
|
|
|
|
"languages",
|
|
|
|
"subjects",
|
|
|
|
"publishers",
|
|
|
|
"first_published_date",
|
|
|
|
"published_date",
|
|
|
|
"cover",
|
|
|
|
"physical_format",
|
|
|
|
"physical_format_detail",
|
|
|
|
"pages",
|
|
|
|
"isbn_13",
|
|
|
|
"isbn_10",
|
|
|
|
"openlibrary_key",
|
|
|
|
"inventaire_id",
|
|
|
|
"goodreads_key",
|
|
|
|
"oclc_number",
|
|
|
|
"asin",
|
2022-12-11 20:37:40 +00:00
|
|
|
"aasin",
|
|
|
|
"isfdb",
|
2022-03-14 18:46:08 +00:00
|
|
|
]
|
|
|
|
widgets = {
|
|
|
|
"title": forms.TextInput(attrs={"aria-describedby": "desc_title"}),
|
2023-04-27 04:05:03 +00:00
|
|
|
"sort_title": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_sort_title"}
|
|
|
|
),
|
2022-03-14 18:46:08 +00:00
|
|
|
"subtitle": forms.TextInput(attrs={"aria-describedby": "desc_subtitle"}),
|
|
|
|
"description": forms.Textarea(
|
|
|
|
attrs={"aria-describedby": "desc_description"}
|
|
|
|
),
|
|
|
|
"series": forms.TextInput(attrs={"aria-describedby": "desc_series"}),
|
|
|
|
"series_number": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_series_number"}
|
|
|
|
),
|
2022-03-14 21:55:41 +00:00
|
|
|
"subjects": ArrayWidget(),
|
2022-03-14 18:46:08 +00:00
|
|
|
"languages": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_languages_help desc_languages"}
|
|
|
|
),
|
|
|
|
"publishers": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_publishers_help desc_publishers"}
|
|
|
|
),
|
2022-03-19 15:44:30 +00:00
|
|
|
"first_published_date": SelectDateWidget(
|
2022-03-14 18:46:08 +00:00
|
|
|
attrs={"aria-describedby": "desc_first_published_date"}
|
|
|
|
),
|
2022-03-19 15:44:30 +00:00
|
|
|
"published_date": SelectDateWidget(
|
2022-03-14 18:46:08 +00:00
|
|
|
attrs={"aria-describedby": "desc_published_date"}
|
|
|
|
),
|
2023-11-05 05:34:24 +00:00
|
|
|
"cover": ResubmitImageWidget(attrs={"aria-describedby": "desc_cover"}),
|
2022-03-19 15:44:30 +00:00
|
|
|
"physical_format": Select(
|
2022-03-14 18:46:08 +00:00
|
|
|
attrs={"aria-describedby": "desc_physical_format"}
|
|
|
|
),
|
|
|
|
"physical_format_detail": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_physical_format_detail"}
|
|
|
|
),
|
|
|
|
"pages": forms.NumberInput(attrs={"aria-describedby": "desc_pages"}),
|
|
|
|
"isbn_13": forms.TextInput(attrs={"aria-describedby": "desc_isbn_13"}),
|
|
|
|
"isbn_10": forms.TextInput(attrs={"aria-describedby": "desc_isbn_10"}),
|
|
|
|
"openlibrary_key": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_openlibrary_key"}
|
|
|
|
),
|
|
|
|
"inventaire_id": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_inventaire_id"}
|
|
|
|
),
|
2022-12-10 09:50:25 +00:00
|
|
|
"goodreads_key": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_goodreads_key"}
|
|
|
|
),
|
2022-03-14 18:46:08 +00:00
|
|
|
"oclc_number": forms.TextInput(
|
|
|
|
attrs={"aria-describedby": "desc_oclc_number"}
|
|
|
|
),
|
|
|
|
"ASIN": forms.TextInput(attrs={"aria-describedby": "desc_ASIN"}),
|
2022-12-11 19:33:33 +00:00
|
|
|
"AASIN": forms.TextInput(attrs={"aria-describedby": "desc_AASIN"}),
|
|
|
|
"isfdb": forms.TextInput(attrs={"aria-describedby": "desc_isfdb"}),
|
2022-03-14 18:46:08 +00:00
|
|
|
}
|
2022-03-16 23:16:55 +00:00
|
|
|
|
2022-03-17 15:18:44 +00:00
|
|
|
|
2022-03-16 23:16:55 +00:00
|
|
|
class EditionFromWorkForm(CustomForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# make all fields hidden
|
|
|
|
for visible in self.visible_fields():
|
|
|
|
visible.field.widget = forms.HiddenInput()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = models.Work
|
|
|
|
fields = [
|
|
|
|
"title",
|
2023-08-01 13:12:50 +00:00
|
|
|
"sort_title",
|
2022-03-16 23:16:55 +00:00
|
|
|
"subtitle",
|
|
|
|
"authors",
|
|
|
|
"description",
|
|
|
|
"languages",
|
|
|
|
"series",
|
|
|
|
"series_number",
|
|
|
|
"subjects",
|
|
|
|
"subject_places",
|
|
|
|
"cover",
|
|
|
|
"first_published_date",
|
|
|
|
]
|