You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.9 KiB

from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, IntegerField, SelectField
from wtforms.validators import DataRequired, Length, ValidationError, Optional
from minibase.database.models import Company
import minibase.database.utils as dbUtils
# Defines the form class to be used for the user registretion
class companyForm(FlaskForm):
# Decalarion of the fields for the form and it's propereties
company_name = StringField('Name', validators=[DataRequired(), Length(min=3, max=20)])
legal_entity_id = SelectField('Legal Entity', choices=dbUtils.company_legal_entity_choices, validators=[DataRequired()])
relation_id = SelectField('Relation', choices=dbUtils.company_relation_choices, validators=[DataRequired()])
website = StringField('Website', validators=[Optional(), Length(min=3, max=100)])
country = SelectField('Country', choices=dbUtils.getCountryNames,validators=[DataRequired()])
state = StringField('State', validators=[DataRequired()])
city = StringField('City', validators=[DataRequired()])
post = IntegerField('Zip', validators=[DataRequired()])
street = StringField('Street', validators=[DataRequired()])
no = IntegerField('No', validators=[DataRequired()])
industry_id = SelectField('Area', choices=dbUtils.getIndustryNames, validators=[DataRequired()])
submit = SubmitField('Register Company')
# Queries to be made in order to validate the form : If Company name exitst within the same country
# Case Insensistive
def validate_company_name(self, company_name):
company_query = Company.query.filter(Company.name.ilike(self.company_name.data)) # Database Querry ilike means case insessitive
for company in company_query:
if company.name:
if company.country_bill == self.country.data:
raise ValidationError('This company in this contry alredy exist')