Files
classifieds/app/blueprints/listings/forms.py
T
2026-06-15 11:23:05 -04:00

34 lines
1.6 KiB
Python

"""Listing forms. Core fields only; category-specific fields are rendered and
parsed dynamically from the category field_schema (prefix `attr_`)."""
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms import (StringField, TextAreaField, SelectField, DecimalField,
SubmitField, MultipleFileField)
from wtforms.validators import DataRequired, Length, Optional, NumberRange
from flask_babel import lazy_gettext as _l
class ListingForm(FlaskForm):
category_id = SelectField(_l("Category"), coerce=int,
validators=[DataRequired()])
title = StringField(_l("Title"), validators=[DataRequired(), Length(3, 140)])
body = TextAreaField(_l("Description"),
validators=[DataRequired(), Length(10, 8000)])
lang = SelectField(_l("Language"),
choices=[("en", "English"), ("vi", "Tiếng Việt"),
("es", "Español")], default="en")
price = DecimalField(_l("Price (USD)"), places=2,
validators=[Optional(), NumberRange(min=0)])
zip = StringField(_l("ZIP code"), validators=[Optional(), Length(3, 12)])
images = MultipleFileField(_l("Photos"),
validators=[FileAllowed(["jpg", "jpeg", "png", "webp"],
_l("Images only"))])
submit = SubmitField(_l("Publish"))
class ImageUploadForm(FlaskForm):
image = FileField(_l("Photo"),
validators=[DataRequired(),
FileAllowed(["jpg", "jpeg", "png", "webp"])])
submit = SubmitField(_l("Add photo"))