open-law/app/forms/interpretation.py

35 lines
1.1 KiB
Python
Raw Normal View History

2023-05-04 15:14:17 +03:00
from flask_wtf import FlaskForm
2023-05-25 17:22:56 +03:00
from wtforms import StringField, SubmitField, ValidationError
2023-05-18 15:37:55 +03:00
from wtforms.validators import DataRequired
2023-05-04 15:14:17 +03:00
2023-05-25 17:22:56 +03:00
from app.controllers import clean_html
from app.logger import log
2023-05-04 15:14:17 +03:00
class BaseInterpretationForm(FlaskForm):
about = StringField("About")
2023-05-18 11:48:25 +03:00
text = StringField("Text")
2023-05-04 15:14:17 +03:00
class CreateInterpretationForm(BaseInterpretationForm):
section_id = StringField("Interpretation ID", [DataRequired()])
submit = SubmitField("Create")
2023-05-25 17:22:56 +03: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 15:14:17 +03:00
2023-05-04 16:32:56 +03:00
class EditInterpretationForm(BaseInterpretationForm):
interpretation_id = StringField("Interpretation ID", [DataRequired()])
submit = SubmitField("Edit")
2023-05-29 11:07:04 +03:00
class DeleteInterpretationForm(FlaskForm):
interpretation_id = StringField("Interpretation ID", [DataRequired()])
submit = SubmitField("Delete")