2022-01-09 17:22:38 +01:00
|
|
|
from flask_wtf import FlaskForm
|
2022-02-13 21:49:07 +01:00
|
|
|
from flask_wtf.file import FileField, FileAllowed, FileRequired, FileSize
|
2022-01-09 17:22:38 +01:00
|
|
|
from wtforms import validators
|
2022-03-04 22:15:08 +01:00
|
|
|
from wtforms.validators import (
|
|
|
|
Length,
|
|
|
|
NumberRange,
|
|
|
|
DataRequired,
|
|
|
|
ValidationError,
|
|
|
|
)
|
2022-01-09 17:22:38 +01:00
|
|
|
from wtforms import (
|
|
|
|
SubmitField,
|
|
|
|
StringField,
|
2022-02-13 21:49:07 +01:00
|
|
|
IntegerField,
|
2022-02-18 12:41:20 +01:00
|
|
|
SelectField,
|
2022-01-09 17:22:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class UploadForm(FlaskForm):
|
|
|
|
"""File upload class for a new site in distribusi-verse"""
|
|
|
|
|
2022-03-04 22:15:08 +01:00
|
|
|
def distribusiname(form, field):
|
|
|
|
if field.data.lower() == "new":
|
|
|
|
raise ValidationError("Name has to be unique and not just new.")
|
|
|
|
|
2022-01-09 17:22:38 +01:00
|
|
|
sitename = StringField(
|
|
|
|
"Name of your website:",
|
2022-03-04 22:15:08 +01:00
|
|
|
validators=[validators.InputRequired(), Length(2, 100), distribusiname],
|
2022-01-09 17:22:38 +01:00
|
|
|
)
|
2022-03-06 23:15:38 +01:00
|
|
|
academicyear = SelectField(
|
2022-02-13 21:49:07 +01:00
|
|
|
"Academic year:",
|
2022-03-06 23:15:38 +01:00
|
|
|
validate_choice=True,
|
|
|
|
coerce=str,
|
|
|
|
choices=[
|
|
|
|
(u'2021-2022', u'2021-2022'),
|
|
|
|
(u'2022-2023', u'2022-2023'),
|
|
|
|
(u'2023-2024', u'2023-2024'),
|
|
|
|
(u'2024-2025', u'2024-2025'),
|
|
|
|
(u'2020-2021', u'past: 2020-2021'),
|
|
|
|
],
|
|
|
|
option_widget=None,
|
|
|
|
validators=[DataRequired()]
|
2022-02-13 21:49:07 +01:00
|
|
|
)
|
2022-02-18 14:47:37 +01:00
|
|
|
term = SelectField(
|
|
|
|
"Term:",
|
|
|
|
validate_choice=True,
|
|
|
|
coerce=str,
|
|
|
|
choices=[
|
|
|
|
(u'1.2', u'1.2'),
|
|
|
|
(u'2.3', u'2.3'),
|
|
|
|
(u'3.1', u'3.1'),
|
|
|
|
(u'4.1', u'4.1'),
|
|
|
|
(u'4.2', u'4.2'),
|
|
|
|
],
|
|
|
|
option_widget=None,
|
|
|
|
validators=[DataRequired()]
|
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
|
|
|
|
|
|
|
course = SelectField(
|
|
|
|
u'Course:',
|
|
|
|
validate_choice=True,
|
|
|
|
coerce=str,
|
|
|
|
choices=[
|
|
|
|
('hacking', u'Autonomous - Hacking'),
|
|
|
|
('digitalcraft', u'Autonomous - Digital Craft'),
|
|
|
|
('criticalstudies', u'Autonomous - Critical Studies'),
|
|
|
|
('publicprivate', u'Autonomous - Public&Private'),
|
|
|
|
],
|
|
|
|
option_widget=None,
|
|
|
|
validators=[DataRequired()]
|
|
|
|
)
|
|
|
|
|
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(
|
|
|
|
max_size=104857600,
|
|
|
|
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")
|