csv-library-website/library/forms/uploadform.py

77 lines
2.1 KiB
Python
Raw Normal View History

"""Form object declaration."""
from flask_wtf import FlaskForm
2023-11-26 18:38:33 +01:00
from flask_wtf.file import FileAllowed, FileField
2023-12-01 15:58:33 +01:00
from wtforms import (
IntegerField,
RadioField,
StringField,
SubmitField,
validators,
)
2023-11-26 18:38:33 +01:00
from wtforms.validators import Length, NumberRange
class PublicationForm(FlaskForm):
2021-04-05 21:42:43 +02:00
"""Publication upload form."""
2021-03-07 20:08:17 +01:00
uploadpublication = StringField(
2021-04-05 21:42:43 +02:00
"Title of the publication:",
[
validators.InputRequired(),
Length(
min=3, message="A publication in the library needs a title."
),
],
)
author = StringField(
"The author or editor:",
[
validators.InputRequired(),
Length(
min=3,
message=(
"If the author or editor is not known just type unkown."
),
),
],
)
year = IntegerField(
2023-12-01 15:23:37 +01:00
"Year:",
[validators.InputRequired(), NumberRange(min=0, max=2050)],
2023-12-01 15:58:33 +01:00
default=2023,
2021-04-05 21:42:43 +02:00
)
fields = StringField("Fields:")
type = StringField(
"Type of publication:",
[
validators.InputRequired(),
Length(
min=3,
message=(
"Here you can use terms such as zine, paperback,"
" hardcover."
),
),
],
2021-03-07 20:08:17 +01:00
)
2021-04-05 21:42:43 +02:00
publishers = StringField("Publishers:")
license = StringField("License:")
highlights = StringField("Highlights from the publication:")
comments = StringField("Comments on the publication:")
image = FileField(
"Image of the book:",
validators=[FileAllowed(["jpg", "png", "gif"], "Images only!")],
)
2023-12-01 15:23:37 +01:00
pdf = FileField(
"Pdf of the book:",
validators=[FileAllowed(["pdf"], "Only pdf uploads supported")],
)
secret = StringField(
"Librarians secret:",
[
validators.InputRequired(),
Length(min=2, message="Fill in the secret to unlock to library."),
],
)
2021-03-07 20:08:17 +01:00
submit = SubmitField("Submit")