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.
37 lines
1.0 KiB
37 lines
1.0 KiB
from flask_wtf import FlaskForm
|
|
from flask_wtf.file import FileField, FileAllowed
|
|
from wtforms import validators
|
|
from wtforms.validators import Length, ValidationError
|
|
from wtforms import (
|
|
SubmitField,
|
|
StringField,
|
|
)
|
|
|
|
|
|
class UploadForm(FlaskForm):
|
|
"""File upload class for a new site in distribusi-verse"""
|
|
|
|
def FileSizeLimit(max_size_in_mb):
|
|
max_bytes = max_size_in_mb * 1024 * 1024
|
|
|
|
def file_length_check(form, field):
|
|
if len(field.data.read()) > max_bytes:
|
|
raise ValidationError(
|
|
"File size must be less than {}MB".format(max_size_in_mb)
|
|
)
|
|
|
|
return file_length_check
|
|
|
|
sitename = StringField(
|
|
"Name of your website:",
|
|
validators=[validators.InputRequired(), Length(2, 100)],
|
|
)
|
|
zipfile = FileField(
|
|
"Upload your zip file with content here:",
|
|
validators=[
|
|
FileAllowed(["zip"], "Zip archives only!"),
|
|
FileSizeLimit(max_size_in_mb=100),
|
|
],
|
|
)
|
|
|
|
submit = SubmitField("Upload")
|
|
|