Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import wtforms
from godmode.widgets.base import BaseWidget
def parse_value(value):
try:
return json.loads(value) if value else None
except Exception as ex:
raise ValueError("Bad JSON: {}".format(ex))
class JSONWidget(BaseWidget):
filterable = False
field = wtforms.TextAreaField(filters=[parse_value])
def render_edit(self, form=None, item=None):
value = getattr(item, self.name, None) if item else None
if value is not None:
value = json.dumps(value)
else:
value = ""
return """<textarea style="height: 100px;" name="%s">%s</textarea>""" % (self.name, value)
def render_details(self, item):
value = getattr(item, self.name, None)
template = ""
if value:
for k, v in value.items():
template += "%s: %s<br>" % (k, v)
return template
WIDGET_ALLOWED = {}
for attr in ALLOWED_TAGS:
allowed = ALLOWED_ATTRIBUTES.get(attr, True)
if not isinstance(allowed, bool):
allowed = {tag: True for tag in allowed}
WIDGET_ALLOWED[attr] = allowed
class EventForm(Form):
title = StringField(label=_l("Title"), filters=(strip,), validators=[required()])
start = DateTimeField(_l("Start"), validators=[required()])
end = DateTimeField(_l("End"), validators=[required()])
location = TextAreaField(label=_l("Location"), filters=(strip,))
url = URLField(label=_l("URL"), filters=(strip,))
description = TextAreaField(
label=_l("Description"),
widget=RichTextWidget(allowed_tags=WIDGET_ALLOWED),
filters=(strip,),
validators=[required()],
)
def validate_description(self, field):
field.data = bleach.clean(
field.data,
tags=ALLOWED_TAGS,
attributes=ALLOWED_ATTRIBUTES,
styles=ALLOWED_STYLES,
text = TextAreaField( _('Registration Protocol'), [ validators.Length(min=6, max=12000) ] )
class WelcomeNewUserForm(Form):
# TODO: make sure it's exist
text = TextAreaField( _('Welcome New User'), [ validators.Length(min=6, max=12000) ] )
class SendMailForm(Form):
#fromaddr = TextField( _('From'), [validators.Length(min=6, max=35), validators.Email()] )
#totype = SelectField( _('To Type'), choices=[
# ('user', _('Single User')),
# ('group', _('Group User')),
# ] )
to = TextAreaField( _('To') )
cc = TextAreaField( _('CC') )
bcc = TextAreaField( _('BCC') )
subject = TextField( _('Subject') )
body = TextAreaField( _('Body'), [ validators.Length(min=6, max=12000) ] )
class QQAuth2Form(Form):
app_id = TextField( 'APP ID' )
app_key = TextField( 'APP KEY' )
redirect_uri = TextField( 'Redirect URI' )
enabled = BooleanField( 'Is Enabled ?', default = False )
# Created Time: 2015-11-25 21:58:14
#*************************************************************************
#!/usr/bin/env python
# -*- coding=UTF-8 -*-
from flask.ext.wtf import Form
from wtforms import StringField,SubmitField,PasswordField,validators,\
SelectField,TextAreaField
from wtforms.validators import Required
class EditUserInforForm(Form):
passwd = PasswordField('密码', [validators.Required()])
new_passwd = PasswordField('新密码', [validators.Length(min=4, max=25)])
retry_new_passwd = PasswordField('重复新密码',
[validators.Length(min=4, max=25)])
introduce = TextAreaField('个人介绍', [validators.Required()])
school = StringField('学校/公司', [validators.Required()])
edit = SubmitField('修改')
class EditRegisterForm(Form):
name = StringField('用户名', [validators.Length(min=4, max=25)])
is_superuser = SelectField('是否授予超级管理员权限',
choices=[('True','True'), ('False', 'False')],
validators=[Required()])
roles = SelectField('用户组',
choices=[('super','Super'),('admin', 'Admin'),
('writer', 'Writer'),('editor','Editor'),
('visitor','Visitor')],
validators=[Required()])
is_confirmed = SelectField('修改用户验证状态',
choices=[('True','True'), ('False', 'False')],
validators=[Required()])
'上传文件只能为图片且图片格式为jpg,png')])
class PrivacyForm(Form):
online_status = SelectField(
_('Login status:'), coerce=str, choices=choices)
topic_list = SelectField(_('Topic List:'), coerce=str, choices=choices)
rep_list = SelectField(_('Reply List:'), coerce=str, choices=choices)
ntb_list = SelectField(_('Notebook List:'), coerce=str, choices=choices)
collect_list = SelectField(_('Collect List:'), coerce=str, choices=choices)
class ProfileForm(Form):
introduce = TextAreaField(_('Introduce:'), [Length(max=256)])
school = StringField(_('School:'), [Length(max=256)])
word = TextAreaField(_('Signature:'), [Length(max=256)])
class PasswordForm(Form):
old_password = PasswordField(
_('Old Password:'), [DataRequired(), Length(
min=4, max=20)])
new_password = PasswordField(
_('New Password:'), [DataRequired(), Length(
min=4, max=20)])
rnew_password = PasswordField(
_('New Password again:'), [DataRequired(), EqualTo('new_password')])
class BabelForm(Form):
timezone = SelectField(_('Timezone:'), coerce=str, choices=timezone)
locale = SelectField(_('Locale:'), coerce=str, choices=locale)
from wtforms.validators import Regexp
from tracker.form.validators import SamePackageBase
from tracker.form.validators import ValidIssues
from tracker.form.validators import ValidPackageNames
from tracker.form.validators import ValidURLs
from tracker.model.cvegroup import CVEGroup
from tracker.model.cvegroup import pkgver_regex
from tracker.model.enum import Affected
from .base import BaseForm
class GroupForm(BaseForm):
cve = TextAreaField(u'CVE', validators=[DataRequired(), ValidIssues()])
pkgnames = TextAreaField(u'Package', validators=[DataRequired(), ValidPackageNames(), SamePackageBase()])
affected = StringField(u'Affected', validators=[DataRequired(), Regexp(pkgver_regex)])
fixed = StringField(u'Fixed', validators=[Optional(), Regexp(pkgver_regex)])
status = SelectField(u'Status', choices=[(e.name, e.label) for e in [*Affected]], validators=[DataRequired()])
bug_ticket = StringField('Bug ticket', validators=[Optional(), Regexp(r'^\d+$')])
reference = TextAreaField(u'References', validators=[Optional(), Length(max=CVEGroup.REFERENCES_LENGTH), ValidURLs()])
notes = TextAreaField(u'Notes', validators=[Optional(), Length(max=CVEGroup.NOTES_LENGTH)])
advisory_qualified = BooleanField(u'Advisory qualified', default=True, validators=[Optional()])
force_submit = BooleanField(u'Force creation', default=False, validators=[Optional()])
submit = SubmitField(u'submit')
def __init__(self, packages=[]):
super().__init__()
self.packages = packages
def validate(self):
rv = BaseForm.validate(self)
validators.Length(min=2, max=1024) ] )
markup = SelectField(
_('Markup Language'), coerce=int, default=1,
choices=[(1, 'Markdown'),
(2, 'reStructuredText')] )
body = TextAreaField( _('Body'), [
validators.Length(min=6, max=1024*1024) ] )
is_public = BooleanField( _('Is Public ?') )
class PostEditForm(Form):
body = TextAreaField( _('Body'), [
validators.Length(min=6, max=1024*1024) ] )
comp = set([u for u, in db.session.query(Usergroup.name).
filter(Usergroup.name.in_(test)).all()])
diff = test.difference(comp)
if len(diff) > 0:
raise validators.ValidationError(
_('Not valid groups: %(x_group)s', x_group=(', '.join(diff))))
class AddMsgMESSAGEForm(InvenioBaseForm):
"""Define form for writing new message."""
sent_to_user_nicks = StringField(_('Users'), [validate_user_nicks])
sent_to_group_names = StringField(_('Groups'), [validate_group_names])
subject = StringField(_('Subject'))
body = TextAreaField(_('Message'), [
validators.length(
0, CFG_WEBMESSAGE_MAX_SIZE_OF_MESSAGE,
message=_(
"Your message is too long, please edit it. "
"Maximum size allowed is %{length}i characters.",
length=CFG_WEBMESSAGE_MAX_SIZE_OF_MESSAGE
)
)
])
received_date = DateTimeField(_('Send later'), [validators.optional()],
widget=DateTimePickerWidget())
def validate_sent_to_user_nicks(self, field):
"""Check whenever user nickname or group name was posted."""
if len(msg_split_addr(self.sent_to_user_nicks.data)) == 0 and \
len(msg_split_addr(self.sent_to_group_names.data)) == 0:
)
keypair_error_msg = _(u'Key pair is required')
keypair = wtforms.SelectField(
label=_(u'Key name'),
validators=[validators.InputRequired(message=keypair_error_msg)],
)
securitygroup_error_msg = _(u'Security group is required')
securitygroup = wtforms.SelectMultipleField(
label=_(u'Security group'),
validators=[validators.InputRequired(message=securitygroup_error_msg)],
)
associate_public_ip_address = wtforms.SelectField(label=_(u'VPC IP assignment'))
associate_public_ip_address_helptext = _(u'This setting only applies \
when this launch configuration is used with a scaling group using a VPC network.')
role = wtforms.SelectField()
userdata = wtforms.TextAreaField(label=_(u'User data'))
userdata_file_helptext = _(u'User data file may not exceed 16 KB')
userdata_file = wtforms.FileField(label='')
kernel_id = wtforms.SelectField(label=_(u'Kernel ID'))
ramdisk_id = wtforms.SelectField(label=_(u'RAM disk ID (RAMFS)'))
monitoring_enabled = wtforms.BooleanField(label=_(u'Enable monitoring'))
create_sg_from_lc = wtforms.BooleanField(label=_(u'Create scaling group using this launch configuration'))
def __init__(self, request, image=None, securitygroups=None, conn=None, iam_conn=None, **kwargs):
super(CreateLaunchConfigForm, self).__init__(request, **kwargs)
self.image = image
self.securitygroups = securitygroups
self.conn = conn
self.iam_conn = iam_conn
self.cloud_type = request.session.get('cloud_type', 'euca')
self.set_error_messages()
self.monitoring_enabled.data = True
# -*- coding: utf-8 -*-
import simplejson
import wtforms
from eventframe.forms import Form, DictField, valid_name
__all__ = ['DataForm']
class DataForm(Form):
name = wtforms.TextField(u"URL name", validators=[wtforms.validators.Required(), valid_name])
title = wtforms.TextField(u"Title", validators=[wtforms.validators.Required()])
data = wtforms.TextAreaField(u"Data", validators=[wtforms.validators.Required()],
description=u"Enter JSON data")
properties = DictField(u"Properties")
def validate_data(self, field):
# Check for exceptions when loading data
parsed = simplejson.loads(field.data, use_decimal=True)
if not isinstance(parsed, dict):
raise wtforms.ValidationError(u'This is not a valid JSON object. Use {"key": value, ...}')