47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from flask import flash
|
|
from flask_wtf import FlaskForm
|
|
from wtforms.fields import DateField, EmailField
|
|
from wtforms.fields import StringField, BooleanField
|
|
from wtforms.validators import DataRequired, ValidationError, EqualTo
|
|
from datetime import date
|
|
|
|
|
|
def validate_valid_thru_date(form, field):
|
|
if form.limit_validity.data:
|
|
# only check date format if limited validity of token is set
|
|
try:
|
|
if not field.data >= date.today():
|
|
raise ValueError
|
|
except ValueError as e:
|
|
flash("Ungültiges Datum")
|
|
raise ValidationError
|
|
return True
|
|
|
|
|
|
class TokenForm(FlaskForm):
|
|
name = StringField("Name", validators=[DataRequired()])
|
|
email = EmailField("E-Mail", validators=[DataRequired()])
|
|
organization = StringField("Organization", validators=[DataRequired()])
|
|
limit_validity = BooleanField("Gültigkeit begrenzen?")
|
|
valid_thru = DateField("Gültig bis", validators=[validate_valid_thru_date])
|
|
active = BooleanField("Aktiv?")
|
|
dsgvo = BooleanField(
|
|
"Einwilligung Nutzungsbedingungen erfragt?", validators=[DataRequired()]
|
|
)
|
|
|
|
|
|
class ConfirmDeleteForm(FlaskForm):
|
|
name = StringField(
|
|
"Name",
|
|
validators=[
|
|
DataRequired(),
|
|
EqualTo("name_confirm", "Name stimmt nicht überein"),
|
|
],
|
|
)
|
|
name_confirm = StringField("Name confirm")
|
|
|
|
|
|
class AdminCreationForm(FlaskForm):
|
|
name = StringField("Name", validators=[DataRequired()])
|
|
email = EmailField("E-Mail", validators=[DataRequired()])
|