Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from flask_wtf import FlaskForm
from sqlalchemy.sql import and_, exists
from wtforms import fields, validators, widgets
from apollo import constants, models, services
class UserDetailsForm(FlaskForm):
username = fields.StringField(_('Username'))
email = fields.StringField(_('Email'), validators=[
validators.DataRequired(), validators.Email()])
password = fields.StringField(
_('Password'),
validators=[validators.EqualTo('password_confirm')],
widget=widgets.PasswordInput())
password_confirm = fields.StringField(
_('Confirm Password'),
widget=widgets.PasswordInput())
locale = fields.SelectField(_('Language'),
choices=constants.LANGUAGE_CHOICES)
def __init__(self, *args, **kwargs):
self.instance = kwargs.get('instance')
if self.instance:
initial_data = {
'email': self.instance.email,
'locale': self.instance.locale,
'username': self.instance.username,
}
kwargs.update(data=initial_data)
class TestForm(Form):
test = fields.RadioField(
'test',
choices = (
('val','label'),
('val2','label2'),
('val3','label3'),
('val4','label4'),
)
)
class AddPageForm(Form):
pass
class FrontendEditPageForm(Form):
title = fields.StringField('Title')
content = PageDownField('Content')
class OrderFilterForm(FilterForm):
network = QuerySelectField('Network',
allow_blank=True,
query_factory=instances('network'),
blank_text='Select Network')
gateway = QuerySelectField('Gateway',
allow_blank=True,
query_factory=instances('gateway'),
blank_text='Select Gateway')
user = QuerySelectField('User',
allow_blank=True,
query_factory=instances('user'),
blank_text='Select User')
status = f.SelectField('Status', default='', choices=status_choices())
created_from = f.StringField('Created From')
created_to = f.StringField('Created To')
def filter_created_from(self, q, k, v):
return q.filter(Order.created_at >= v)
def filter_created_to(self, q, k, v):
return q.filter(Order.created_at < v)
class OrderForm(FlaskForm):
gateway = f.SelectField('Gateway', default=lambda: current_user.gateway)
product = QuerySelectField('Product', query_factory=instances('product'))
quantity = f.IntegerField('Quantity', default=1)
price = f.DecimalField('Price', [validators.Required()])
def conv_String(self, model, field, kwargs):
if field.regex:
kwargs['validators'].append(validators.Regexp(regex=field.regex))
self._string_common(model, field, kwargs)
password_field = kwargs.pop('password', False)
textarea_field = kwargs.pop('textarea', False) or not field.max_length
if password_field:
return f.PasswordField(**kwargs)
if textarea_field:
return f.TextAreaField(**kwargs)
return f.StringField(**kwargs)
from flask_wtf import Form
from wtforms.ext.sqlalchemy.orm import QuerySelectField
from wtforms import fields, validators,widgets
from flask_pagedown.fields import PageDownField
from flask_codemirror.fields import CodeMirrorField
from ..page.fields import CKTextEditorField
from wtforms.widgets.html5 import DateInput as DateWidget
#factory = Type.query.all()
class AddSettingForm(Form):
name = fields.StringField('Setting Name',validators=[validators.InputRequired()])
#type = QuerySelectField('setting type',query_factory=factory,validators=[validators.InputRequired()])
default = fields.StringField('Default Value')
value = fields.StringField('Setting Value')
class AddSettingTypeForm(Form):
name = fields.StringField('Setting Type Name',validators=[validators.InputRequired()])
widget = fields.StringField('Input Widget')
class TestForm(Form):
title = fields.StringField('Title')
content = PageDownField('content')
class BaseTemplateForm(Form):
template = fields.SelectField('base template',validators=[validators.InputRequired()])#,choices=[('a','a'),('b','b'),('c','c')])
class TemplateBodyFieldForm(Form):
modification_mode = IndicoEnumSelectField(_("Modification allowed"), enum=ModificationMode,
description=_("Will users be able to modify their data? When?"))
publish_registrations_enabled = BooleanField(_('Publish registrations'), widget=SwitchWidget(),
description=_("Registrations from this form will be displayed in the "
"event page"))
publish_registration_count = BooleanField(_("Publish number of registrations"), widget=SwitchWidget(),
description=_("Number of registered participants will be displayed in "
"the event page"))
publish_checkin_enabled = BooleanField(_('Publish check-in status'), widget=SwitchWidget(),
description=_("Check-in status will be shown publicly on the event page"))
base_price = DecimalField(_('Registration fee'), [NumberRange(min=0, max=999999.99), Optional(),
_check_if_payment_required], filters=[lambda x: x if x is not None else 0],
widget=NumberInput(step='0.01'),
description=_("A fixed fee all users have to pay when registering."))
currency = SelectField(_('Currency'), [DataRequired()], description=_('The currency for new registrations'))
notification_sender_address = StringField(_('Notification sender address'), [IndicoEmail()],
filters=[lambda x: (x or None)])
message_pending = TextAreaField(_("Message for pending registrations"),
description=_("Text included in emails sent to pending registrations"))
message_unpaid = TextAreaField(_("Message for unpaid registrations"),
description=_("Text included in emails sent to unpaid registrations"))
message_complete = TextAreaField(_("Message for complete registrations"),
description=_("Text included in emails sent to complete registrations"))
manager_notifications_enabled = BooleanField(_('Enabled'), widget=SwitchWidget(),
description=_("Enable notifications to managers about registrations"))
manager_notification_recipients = EmailListField(_('List of recipients'),
[HiddenUnless('manager_notifications_enabled',
preserve_data=True), DataRequired()],
description=_("Email addresses that will receive notifications"))
def __init__(self, *args, **kwargs):
self.event = kwargs.pop('event')
from flask_wtf import Form
from wtforms import fields, validators
from wtforms.widgets.html5 import DateInput as DateWidget
class EditProfileForm(Form):
first_name = fields.StringField('First Name')
last_name = fields.StringField('Last Name')
email = fields.StringField('Email Address',validators=[validators.Required(),validators.Email()])
phone_number = fields.StringField('phone number');
birth_date = fields.DateField('Birth Date',format="%m-%d-%Y",validators=[validators.Optional()],widget=DateWidget())
"""Form to handle thrash view confirmation."""
view_id = IntegerField('View ID', validators=[DataRequired()])
class EventCreateForm(BaseForm):
"""Generic form to handle event addition. E.g. message and timestamp."""
timestamp = StringField('timestamp', validators=[DataRequired()])
timestamp_desc = StringField('timestamp_desc', validators=[DataRequired()])
message = StringField('message', validators=[DataRequired()])
class EventAnnotationForm(BaseForm):
"""Generic form to handle event annotation. E.g. comment and labels."""
annotation = StringField('Annotation', validators=[DataRequired()])
annotation_type = StringField('Type', validators=[DataRequired()])
events = StringField('Events', validators=[DataRequired()])
class UploadFileForm(BaseForm):
"""Form to handle file uploads."""
file = FileField(
'file',
validators=[
FileRequired(),
FileAllowed(['plaso', 'csv', 'jsonl'],
'Allowed file extensions: .plaso, .csv, or .jsonl')
])
name = StringField('Timeline name', validators=[Optional()])
sketch_id = IntegerField('Sketch ID', validators=[Optional()])
class StoryForm(BaseForm):
widget = fields.StringField('Input Widget')
class TestForm(Form):
title = fields.StringField('Title')
content = PageDownField('content')
class BaseTemplateForm(Form):
template = fields.SelectField('base template',validators=[validators.InputRequired()])#,choices=[('a','a'),('b','b'),('c','c')])
class TemplateBodyFieldForm(Form):
body = CKTextEditorField('body')
class AddBlogForm(Form):
name = fields.StringField('Blog Name',validators=[validators.InputRequired()])
title = fields.StringField('Blog Title',validators=[validators.InputRequired()])
slug = fields.StringField('Url Slug')
author_id = fields.HiddenField()
date_added = fields.HiddenField()
class AddPageForm(Form):
date_added = fields.DateField('Publish On:',format="%m-%d-%Y",widget=DateWidget())
date_end = fields.DateField('Expire On:',format="%m-%d-%Y",validators=[validators.Optional()],widget=DateWidget())
name = fields.StringField('Page Name',validators=[validators.InputRequired()])
description = fields.TextAreaField('Description',validators=[validators.Optional()])
slug = fields.StringField('Page Slug',validators=[validators.InputRequired()])
short_url = fields.StringField('Url',validators=[validators.Optional()])
title = fields.StringField('Page Title',validators=[validators.InputRequired()])
add_to_nav = fields.BooleanField('Add to Navbar')
add_sidebar = fields.BooleanField('Add Sidebar')
@staticmethod
def validate_family_name(form, field):
if field.data is None:
return
if field.data not in FAMILY_NAMES:
raise validators.StopValidation('Incorrect family name.')
class ListReceiptsForm(ProtoForm):
ids = fields.StringField()
if isinstance(ids, list):
ids = fields.FieldList(fields.StringField(), min_entries=1)
@staticmethod
def validate_ids(form, field):
if field.data == '' or field.data is None:
raise validators.StopValidation('Missed list of identifiers.')
if not isinstance(field.data, list):
raise validators.StopValidation('Incorrect identifier.')
for data in field.data:
if not isinstance(data, str):
raise validators.StopValidation('Incorrect identifier.')
if re.match(r'^[0-9a-f]{128}$', data) is None:
raise validators.StopValidation('Incorrect identifier.')