2022-01-09 17:22:38 +01:00
|
|
|
from flask_wtf import FlaskForm
|
2024-04-21 20:44:08 +02:00
|
|
|
from flask_wtf.file import FileAllowed, FileField, FileRequired, FileSize
|
2024-04-28 13:15:23 +02:00
|
|
|
from wtforms import (
|
|
|
|
IntegerField,
|
|
|
|
SelectField,
|
|
|
|
StringField,
|
|
|
|
SubmitField,
|
|
|
|
validators,
|
|
|
|
)
|
|
|
|
from wtforms.validators import (
|
|
|
|
DataRequired,
|
|
|
|
Length,
|
|
|
|
NumberRange,
|
|
|
|
ValidationError,
|
|
|
|
)
|
2022-01-09 17:22:38 +01:00
|
|
|
|
2024-04-28 13:04:07 +02:00
|
|
|
from app import settings
|
|
|
|
|
2022-01-09 17:22:38 +01:00
|
|
|
|
|
|
|
class UploadForm(FlaskForm):
|
|
|
|
"""File upload class for a new site in distribusi-verse"""
|
|
|
|
|
2024-04-22 20:34:33 +02:00
|
|
|
def distribusiname(form, field):
|
2022-03-04 22:15:08 +01:00
|
|
|
if field.data.lower() == "new":
|
|
|
|
raise ValidationError("Name has to be unique and not just new.")
|
|
|
|
|
2024-04-22 20:34:33 +02:00
|
|
|
def category_choices():
|
|
|
|
APP = settings()
|
|
|
|
config_categories = APP.config["categories"]
|
|
|
|
categories = []
|
|
|
|
for config_category in config_categories:
|
|
|
|
categories.append((config_category, config_category))
|
|
|
|
return categories
|
|
|
|
|
2024-04-22 20:59:26 +02:00
|
|
|
def year_choices():
|
|
|
|
APP = settings()
|
|
|
|
start_time = APP.config["start_time"]
|
|
|
|
end_time = APP.config["end_time"]
|
|
|
|
year_range = range(start_time.year, end_time.year, 1)
|
|
|
|
year_choices = []
|
|
|
|
for year in year_range:
|
|
|
|
year_choices.append((str(year), str(year)))
|
|
|
|
return year_choices
|
|
|
|
|
2022-01-09 17:22:38 +01:00
|
|
|
sitename = StringField(
|
2024-04-19 22:33:52 +02:00
|
|
|
"Name of your archive section:",
|
2024-04-21 20:44:08 +02:00
|
|
|
validators=[
|
|
|
|
validators.InputRequired(),
|
|
|
|
Length(2, 100),
|
2024-04-22 20:34:33 +02:00
|
|
|
distribusiname,
|
2024-04-21 20:44:08 +02:00
|
|
|
],
|
2022-01-09 17:22:38 +01:00
|
|
|
)
|
2024-04-19 22:55:07 +02:00
|
|
|
year = SelectField(
|
|
|
|
"Year:",
|
2022-03-06 23:15:38 +01:00
|
|
|
validate_choice=True,
|
|
|
|
coerce=str,
|
2024-04-22 20:59:26 +02:00
|
|
|
choices=year_choices,
|
2022-03-06 23:15:38 +01:00
|
|
|
option_widget=None,
|
2024-04-21 20:44:08 +02:00
|
|
|
validators=[DataRequired()],
|
2022-02-13 21:49:07 +01:00
|
|
|
)
|
2024-04-19 22:55:07 +02:00
|
|
|
category = SelectField(
|
2024-04-19 22:33:52 +02:00
|
|
|
"Category:",
|
2022-02-18 14:47:37 +01:00
|
|
|
validate_choice=True,
|
|
|
|
coerce=str,
|
2024-04-22 20:34:33 +02:00
|
|
|
choices=category_choices,
|
2022-02-18 14:47:37 +01:00
|
|
|
option_widget=None,
|
2024-04-21 20:44:08 +02:00
|
|
|
validators=[DataRequired()],
|
2022-02-13 21:49:07 +01:00
|
|
|
)
|
2024-04-27 11:26:19 +02:00
|
|
|
|
2022-02-13 21:49:07 +01:00
|
|
|
tags = StringField(
|
2022-03-25 12:29:02 +01:00
|
|
|
"Add tags, seperated by commas. No need for the '#' sign:",
|
2022-02-13 21:49:07 +01:00
|
|
|
validators=[validators.InputRequired(), Length(2, 500)],
|
|
|
|
)
|
2022-02-18 12:41:20 +01:00
|
|
|
|
2022-01-09 17:22:38 +01:00
|
|
|
zipfile = FileField(
|
|
|
|
"Upload your zip file with content here:",
|
2022-02-12 19:44:44 +01:00
|
|
|
validators=[
|
|
|
|
FileAllowed(["zip"], "Zip archives only!"),
|
2022-02-13 21:49:07 +01:00
|
|
|
FileRequired(),
|
|
|
|
FileSize(
|
2024-04-27 11:26:19 +02:00
|
|
|
max_size=1073741824,
|
2022-02-13 21:49:07 +01:00
|
|
|
message="Zipfile size must be smaller than 100MB",
|
|
|
|
),
|
2022-02-12 19:44:44 +01:00
|
|
|
],
|
2022-01-09 17:22:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
submit = SubmitField("Upload")
|