open-law/app/forms/interpretation.py

30 lines
956 B
Python
Raw Normal View History

2023-05-04 12:14:17 +00:00
from flask_wtf import FlaskForm
2023-05-25 14:22:56 +00:00
from wtforms import StringField, SubmitField, ValidationError
2023-05-18 12:37:55 +00:00
from wtforms.validators import DataRequired
2023-05-04 12:14:17 +00:00
2023-05-25 14:22:56 +00:00
from app.controllers import clean_html
from app.logger import log
2023-05-04 12:14:17 +00:00
class BaseInterpretationForm(FlaskForm):
about = StringField("About")
2023-05-18 08:48:25 +00:00
text = StringField("Text")
2023-05-04 12:14:17 +00:00
class CreateInterpretationForm(BaseInterpretationForm):
section_id = StringField("Interpretation ID", [DataRequired()])
submit = SubmitField("Create")
2023-05-25 14:22:56 +00:00
def validate_text(self, field):
text = clean_html(field.data)
text = text.replace(" ", "")
text = text.strip()
if len(text) < 1:
log(log.WARNING, "Can't submit empty interpretation")
raise ValidationError("You can't create interpretation with no text")
2023-05-04 12:14:17 +00:00
2023-05-04 13:32:56 +00:00
class EditInterpretationForm(BaseInterpretationForm):
interpretation_id = StringField("Interpretation ID", [DataRequired()])
submit = SubmitField("Edit")