File: //home/arjun/projects/buyercall_forms/buyercall/buyercall/blueprints/partnership/forms.py
from flask_babel import lazy_gettext as _
from flask_wtf import FlaskForm
from flask_wtf.file import FileField
from wtforms import HiddenField, StringField, PasswordField, SelectField, BooleanField, FieldList, FormField
from wtforms.fields.html5 import EmailField
from wtforms.validators import DataRequired, Length, Optional, ValidationError
from buyercall.lib.util_wtforms import ModelForm, choices_from_dict
from buyercall.blueprints.partnership.models import BILLING_TYPE, BUSINESS_TYPE, CREDIT_PROVIDER
class PartnershipForm(FlaskForm):
name = StringField(_('Partnership Name'), [Optional(), Length(1, 128)])
logo = FileField(_('Logo'), [Optional()])
default_billing_type = SelectField(
_('Default Billing'),
[DataRequired()],
choices=choices_from_dict(BILLING_TYPE, prepend_blank=False))
business_type = SelectField(
_('Business Type'),
[DataRequired()],
choices=choices_from_dict(BUSINESS_TYPE, prepend_blank=False))
invited_emails = HiddenField()
moved_accounts = HiddenField()
class PartnershipAccountForm(FlaskForm):
name = StringField(_('Name'), [Optional(), Length(1, 128)])
partner_account_code = StringField(_('Partner Account Code'), [Optional(), Length(0, 64)])
billing_type = SelectField(
_('Billing'),
[DataRequired()],
choices=choices_from_dict(BILLING_TYPE, prepend_blank=False))
business_type = SelectField(
_('Business Type'),
[DataRequired()],
choices=choices_from_dict(BUSINESS_TYPE, prepend_blank=False))
credit_sp = SelectField(
_('Credit Provider'),
choices=choices_from_dict(CREDIT_PROVIDER, prepend_blank=False))
# partnership_account_group_id = SelectField(_('Account Group'), [Optional()], coerce=int)
def validate_mobile_number(form, field):
# Check if the input is numeric and between 10 and 12 characters
if not field.data.isdigit() or not (10 <= len(field.data) <= 12):
raise ValidationError('Mobile number must be a numeric value between 10 and 12 characters.')
class PartnershipAccountUserForm(FlaskForm):
first_name = StringField(_('User First Name'), [DataRequired(), Length(1, 64)])
last_name = StringField(_('User Last Name'), [Optional(), Length(1, 64)])
email = EmailField(_('User Email'), [DataRequired(), Length(1, 256)])
mobile_number = StringField(_('User Mobile Number'), [DataRequired(), Length(10, 12), validate_mobile_number])
role = SelectField(_("User Role"), choices=[('admin', 'Admin'), ('agent', 'Agent')])
temp_password = PasswordField(_('User Temp Password'), [DataRequired(), Length(8, 32)])
class PartnershipAccountCreateForm(FlaskForm):
name = StringField(_('Account Name'), [DataRequired(), Length(1, 128)])
partner_account_code = StringField(_('Partner Account Code'), [Length(0, 64)])
is_active = BooleanField(_('Active'), default="checked")
credit_service_provider = SelectField(_("Partner Account Credit Service Provider"),
choices=[('', ''),
('offerlogix', 'OfferLogix'),
('700Credit', '700Credit')
])
users = FieldList(FormField(PartnershipAccountUserForm), min_entries=1)
class ExternalApiServiceProvider(FlaskForm):
external_api_service_provider_id = SelectField(_('External Service Provider'), [Optional()], choices=[], coerce=int)
url = StringField(_('Data URL'), [Optional(), Length(1, 128)])
token_url = StringField(_('Token URL'), [Optional(), Length(1, 128)])
client_id = StringField(_('Client ID'), [Optional(), Length(1, 128)])
username = StringField(_('Username'), [Optional(), Length(1, 128)])
password = StringField(_('Password'), [Optional(), Length(1, 128)])
secret = StringField(_('Secret'), [Optional(), Length(1, 128)])
source = StringField(_('Source'), [Optional(), Length(1, 128)])
app_source = StringField(_('App Source'), [Optional(), Length(1, 128)])
class PartnershipSignupForm(ModelForm):
reset_token = HiddenField()
password = PasswordField(_('Password'), [DataRequired(), Length(8, 128)])
firstname = StringField(_('First name'), [DataRequired(), Length(1, 128)])
lastname = StringField(_('Last name'), [DataRequired(), Length(1, 128)])
# email = HiddenField(validators=[
# DataRequired(),
# Email()
# ])
password = PasswordField(_('Password'), [DataRequired(), Length(8, 128)])
phonenumber = StringField(_('Phone number'), [DataRequired(), Length(8, 20)])
tos_agreement = BooleanField(_(''), [DataRequired()])
class PartnershipTwilioApiForm(FlaskForm):
cpaas_account_id = StringField(_('Twilio Account SID'), [DataRequired(), Length(1, 128)])
cpaas_api_token = StringField(_('Twilio API Token'), [DataRequired(), Length(1, 128)])
cpaas_caller_id = StringField(_('Twilio Test Phone Number'), [DataRequired(), Length(1, 12)])
class PartnershipBandwidthApiForm(FlaskForm):
cpaas_user_id = StringField(_('Bandwidth User ID - API V1'), [DataRequired(), Length(1, 128)])
cpaas_api_token = StringField(_('Bandwidth API Token - API V1'), [DataRequired(), Length(1, 128)])
cpaas_api_secret = StringField(_('Bandwidth API Secret - API V1'), [DataRequired(), Length(1, 128)])
cpaas_account_id = StringField(_('Bandwidth Account ID - API V2'), [DataRequired(), Length(1, 128)])
cpaas_api_username = StringField(_('Bandwidth API Username - API V2'), [DataRequired(), Length(1, 128)])
cpaas_api_password = StringField(_('Bandwidth API Password - API V2'), [DataRequired(), Length(1, 128)])
cpaas_site_id = StringField(_('Bandwidth Site ID - API V2'), [DataRequired(), Length(1, 128)])
cpaas_location_id = StringField(_('Bandwidth Location/Peer ID - API V2'), [DataRequired(), Length(1, 128)])
cpaas_sms_application_id = StringField(_('Bandwidth SMS Application ID - API V2'), [DataRequired(), Length(1, 64)])
cpaas_voice_application_id = StringField(_('Bandwidth Voice Application ID - API V2'), [DataRequired(), Length(1, 64)])
cpaas_caller_id = StringField(_('Bandwidth Test Phone Number'), [DataRequired(), Length(1, 12)])
cpaas_cnam_password = StringField(_('Bandwidth CNAM Password - API V2'), [Length(1, 64)])
class PartnerFinservPrequalifyForm(FlaskForm):
active = BooleanField(_('Integration Enabled'))
api_username = StringField(_('Finserv Client ID'), [DataRequired(), Length(1, 128)])
api_password = StringField(_('Finserv Client Secret'), [DataRequired(), Length(1, 128)])
api_account = StringField(_('Finserv Dealer Code'), [DataRequired(), Length(1, 128)])