forked from crunk/distribusi-verse
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.3 KiB
86 lines
2.3 KiB
3 years ago
|
from flask_wtf import FlaskForm
|
||
7 months ago
|
from flask_wtf.file import FileAllowed, FileField, FileRequired, FileSize
|
||
7 months ago
|
from wtforms import (
|
||
6 months ago
|
SelectField,
|
||
|
StringField,
|
||
|
SubmitField,
|
||
|
validators,
|
||
7 months ago
|
)
|
||
|
from wtforms.validators import (
|
||
6 months ago
|
DataRequired,
|
||
|
Length,
|
||
|
ValidationError,
|
||
7 months ago
|
)
|
||
3 years ago
|
|
||
7 months ago
|
from app import settings
|
||
|
|
||
3 years ago
|
|
||
|
class UploadForm(FlaskForm):
|
||
6 months ago
|
"""File upload class for a new site in distribusi-verse"""
|
||
3 years ago
|
|
||
6 months ago
|
def distribusiname(form, field):
|
||
|
if field.data.lower() == "new":
|
||
|
raise ValidationError("Name has to be unique and not just new.")
|
||
3 years ago
|
|
||
6 months ago
|
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
|
||
7 months ago
|
|
||
6 months ago
|
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
|
||
7 months ago
|
|
||
6 months ago
|
sitename = StringField(
|
||
|
"Name of your archive section:",
|
||
|
validators=[
|
||
|
validators.InputRequired(),
|
||
|
Length(2, 100),
|
||
|
distribusiname,
|
||
|
],
|
||
|
)
|
||
|
year = SelectField(
|
||
|
"Year:",
|
||
|
validate_choice=True,
|
||
|
coerce=str,
|
||
|
choices=year_choices,
|
||
|
option_widget=None,
|
||
|
validators=[DataRequired()],
|
||
|
)
|
||
|
category = SelectField(
|
||
|
"Category:",
|
||
|
validate_choice=True,
|
||
|
coerce=str,
|
||
|
choices=category_choices,
|
||
|
option_widget=None,
|
||
|
validators=[DataRequired()],
|
||
|
)
|
||
7 months ago
|
|
||
6 months ago
|
tags = StringField(
|
||
|
"Add search tags, seperated by commas. No need for the '#' sign:",
|
||
|
validators=[validators.InputRequired(), Length(3, 500)],
|
||
|
)
|
||
3 years ago
|
|
||
6 months ago
|
zipfile = FileField(
|
||
|
"Upload your zip file with content here:",
|
||
|
validators=[
|
||
|
FileAllowed(["zip"], "Zip archives only!"),
|
||
|
FileRequired(),
|
||
|
FileSize(
|
||
|
max_size=1073741824,
|
||
|
message="Zipfile size must be smaller than 100MB",
|
||
|
),
|
||
|
],
|
||
|
)
|
||
3 years ago
|
|
||
6 months ago
|
submit = SubmitField("Upload")
|