2024-08-13 16:47:55 +02:00
|
|
|
"""WTF Forms for ScoDoc
|
|
|
|
"""
|
|
|
|
|
|
|
|
from flask_wtf import FlaskForm
|
|
|
|
|
|
|
|
|
|
|
|
class ScoDocForm(FlaskForm):
|
|
|
|
"""Super class for ScoDoc forms
|
|
|
|
(inspired by @iziram)
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
"Init form, adding a filed for our error messages"
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.ok = True
|
|
|
|
self.error_messages: list[str] = [] # used to report our errors
|
|
|
|
|
|
|
|
def set_error(self, err_msg, field=None):
|
|
|
|
"Set error message both in form and field"
|
|
|
|
self.ok = False
|
|
|
|
self.error_messages.append(err_msg)
|
|
|
|
if field:
|
|
|
|
field.errors.append(err_msg)
|