63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
from flask_wtf import FlaskForm
|
|
from wtforms import SelectField, StringField, SubmitField, TextAreaField
|
|
from wtforms.fields import DateTimeLocalField
|
|
from wtforms.validators import DataRequired, Length, Optional, ValidationError
|
|
|
|
from .models import TASK_PRIORITIES, TASK_STATUSES
|
|
|
|
|
|
STATUS_LABELS = {
|
|
"not_started": "Not started",
|
|
"in_progress": "In progress",
|
|
"done": "Done",
|
|
}
|
|
PRIORITY_LABELS = {
|
|
"urgent": "Urgent",
|
|
"important": "Important",
|
|
"normal": "Normal",
|
|
}
|
|
|
|
|
|
def not_blank(_form: FlaskForm, field: StringField) -> None:
|
|
if not field.data or not field.data.strip():
|
|
raise ValidationError("This field cannot be blank.")
|
|
|
|
|
|
class TaskForm(FlaskForm):
|
|
title = StringField(
|
|
"Task title",
|
|
validators=[DataRequired(), not_blank, Length(max=200)],
|
|
)
|
|
description = TextAreaField(
|
|
"Notes",
|
|
validators=[Optional(), Length(max=5000)],
|
|
)
|
|
status = SelectField(
|
|
"Status",
|
|
choices=[(value, STATUS_LABELS[value]) for value in TASK_STATUSES],
|
|
default="not_started",
|
|
)
|
|
priority = SelectField(
|
|
"Priority",
|
|
choices=[(value, PRIORITY_LABELS[value]) for value in TASK_PRIORITIES],
|
|
default="normal",
|
|
)
|
|
due_date = DateTimeLocalField(
|
|
"Due date and time",
|
|
format="%Y-%m-%dT%H:%M",
|
|
validators=[Optional()],
|
|
)
|
|
submit = SubmitField("Save task")
|
|
|
|
|
|
class SubtaskForm(FlaskForm):
|
|
title = StringField(
|
|
"Next small step",
|
|
validators=[DataRequired(), not_blank, Length(max=100)],
|
|
)
|
|
submit = SubmitField("Add step")
|
|
|
|
|
|
class ActionForm(FlaskForm):
|
|
submit = SubmitField()
|
|
|