proxadmin/app/settings/forms.py
2017-05-24 17:37:52 +03:00

72 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from iso3166 import countries
import string
import random
from ..models import User, Role
from flask_wtf import FlaskForm, RecaptchaField
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
from wtforms import validators, ValidationError
from wtforms.fields.html5 import EmailField
class EditProfileForm(FlaskForm):
name = StringField('Лице за контакт:', [validators.DataRequired(), validators.Length(3, 60)])
address = StringField('Адрес:', [validators.DataRequired(), validators.Length(2, 50)])
city = StringField('Град:', [validators.DataRequired(), validators.Length(2,40)])
postcode = StringField('Пощенски Код:')
clist = []
for c in countries:
clist.append((c.alpha2, c.name))
country = SelectField('Държава:', choices=clist, default='BG')
phone = StringField('Телефон:')
org_account = BooleanField('Юридическо лице')
org_companyname = StringField('Име на фирма:')
org_regaddress = StringField('Адресна регистрация:')
org_responsible = StringField('Отговорно Лице:')
org_bulstat = StringField('БУЛСТАТ:')
org_vat = BooleanField('Регистрация по ДДС')
org_vatnum = StringField('ДДС Номер:')
twofactor = BooleanField('2-factor authentication')
submit = SubmitField('Обнови')
class EditProfileAdminForm(FlaskForm):
email = StringField('Електроннa поща (логин):', [validators.DataRequired(), validators.Length(1, 64), validators.Email()])
confirmed = BooleanField('Активиран')
role = SelectField('Роля', coerce=int)
name = StringField('Лице за контакт:', [validators.DataRequired(), validators.Length(3, 60)])
address = StringField('Адрес:', [validators.DataRequired(), validators.Length(2, 50)])
city = StringField('Град:', [validators.DataRequired(), validators.Length(2,40)])
postcode = DecimalField('Пощенски Код:')
clist = []
for c in countries:
clist.append((c.alpha2, c.name))
country = SelectField('Държава:', choices=clist)
phone = DecimalField('Телефон:', [validators.DataRequired()])
org_account = BooleanField('Юридическо лице')
org_companyname = StringField('Име на фирма:')
org_regaddress = StringField('Адресна регистрация:')
org_responsible = StringField('Отговорно Лице:')
org_bulstat = StringField('БУЛСТАТ:')
org_vat = BooleanField('Регистрация по ДДС')
org_vatnum = StringField('ДДС Номер:')
twofactor = BooleanField('2-factor authentication')
submit = SubmitField('Обнови')
def __init__(self, user, *args, **kwargs):
super(EditProfileAdminForm, self).__init__(*args, **kwargs)
self.role.choices = [(role.pid, role.name)
for role in Role.query.order_by(Role.name).all()]
self.user = user
def validate_email(self, field):
if field.data != self.user.email and User.query.filter_by(email=field.data).first():
raise ValidationError('Email-а е вече регистриран.')