mirror of
https://github.com/lucaspalomodevelop/eventcally.git
synced 2026-03-13 08:09:37 +00:00
40 lines
2.2 KiB
Python
40 lines
2.2 KiB
Python
from flask_babelex import lazy_gettext
|
|
from flask_wtf import FlaskForm
|
|
from flask_wtf.file import FileField, FileAllowed
|
|
from wtforms import StringField, SubmitField, DecimalField, TextAreaField, FormField, SelectField
|
|
from wtforms.fields.html5 import EmailField, TelField
|
|
from wtforms.validators import DataRequired, Optional, Regexp
|
|
import decimal
|
|
from models import Location
|
|
|
|
class OrganizationLocationForm(FlaskForm):
|
|
street = StringField(lazy_gettext('Street'), validators=[Optional()])
|
|
postalCode = StringField(lazy_gettext('Postal code'), validators=[DataRequired()])
|
|
city = StringField(lazy_gettext('City'), validators=[DataRequired()])
|
|
state = StringField(lazy_gettext('State'), validators=[Optional()])
|
|
latitude = DecimalField(lazy_gettext('Latitude'), places=16, validators=[Optional()])
|
|
longitude = DecimalField(lazy_gettext('Longitude'), places=16, validators=[Optional()])
|
|
|
|
class BaseOrganizationForm(FlaskForm):
|
|
name = StringField(lazy_gettext('Name'), validators=[DataRequired()])
|
|
url = StringField(lazy_gettext('Link URL'), validators=[Optional()])
|
|
email = EmailField(lazy_gettext('Email'), validators=[Optional()])
|
|
phone = TelField(lazy_gettext('Phone'), validators=[Optional()])
|
|
fax = TelField(lazy_gettext('Fax'), validators=[Optional()])
|
|
logo_file = FileField(lazy_gettext('Logo'), validators=[FileAllowed(['jpg', 'jpeg', 'png'], lazy_gettext('Images only!'))])
|
|
short_name = StringField(lazy_gettext('Short name'), validators=[Optional(), Regexp('^\w+$', message=lazy_gettext("Short name must contain only letters numbers or underscore"))])
|
|
legal_name = StringField(lazy_gettext('Legal name'), validators=[Optional()])
|
|
location = FormField(OrganizationLocationForm)
|
|
|
|
def populate_obj(self, obj):
|
|
for name, field in self._fields.items():
|
|
if name == 'location' and not obj.location:
|
|
obj.location = Location()
|
|
field.populate_obj(obj, name)
|
|
|
|
class CreateOrganizationForm(BaseOrganizationForm):
|
|
submit = SubmitField(lazy_gettext("Create organization"))
|
|
admin_unit_id = SelectField(lazy_gettext('Admin unit'), validators=[DataRequired()], coerce=int)
|
|
|
|
class UpdateOrganizationForm(BaseOrganizationForm):
|
|
submit = SubmitField(lazy_gettext("Update organization")) |