Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fields(self):
fields = ew_core.NameList()
fields.append(ffw.MarkdownEdit(name='text'))
fields.append(ew.HiddenField(name='forum', if_missing=None))
fields.append(ew.Checkbox(name='subscribe', label='Subscribe', if_missing=False))
if ew_core.widget_context.widget:
# we are being displayed
if ew_core.widget_context.render_context.get('show_subject', self.show_subject):
fields.append(
ew.TextField(name='subject', attrs=dict(style="width:97%")))
else:
# We are being validated
validator = fev.UnicodeString(not_empty=True, if_missing='')
fields.append(ew.TextField(name='subject', validator=validator))
fields.append(NullValidator(name=self.att_name))
return fields
@expose('json')
@validate(validators={'file_id': validators.Int(),
'budge_infront_id': validators.Int()})
def reorder_file(self, id, file_id, budge_infront_id, **kwargs):
"""Change the position of the given file relative to the 2nd file.
:param file_id: The file to move
:type file_id: ``int``
:param budge_infront_id: The file whos position the first file takes.
All files behind/after this file are bumped back as well.
:type budge_infront_id: ``int`` or ``None``
:rtype: JSON dict
:returns:
success
bool
"""
media = fetch_row(Media, id)
class AuthorizationResponsePackageValidator(Schema):
"""Authorization Response Package entity validator"""
service_pins = ForEach()
auth_request = validators.String() # UUID
response = validators.Bool()
device_id = validators.String()
allow_extra_fields = True
class AuthMethodsValidator(Schema):
"""Auth methods validator"""
method = validators.String()
set = validators.Bool(if_empty=None)
active = validators.Bool(if_empty=None)
allowed = validators.Bool(if_empty=None)
supported = validators.Bool(if_empty=None)
user_required = validators.Bool(if_empty=None)
passed = validators.Bool(if_empty=None)
error = validators.Bool(if_empty=None)
class GeoFenceValidator(Schema):
""" GeoFence Validator, can represent both GeoFence and GeoCircleFence """
name = validators.String(if_missing=None)
latitude = validators.Number()
longitude = validators.Number()
radius = validators.Number()
class GeoCircleFenceValidator(GeoFenceValidator):
""" GeoFence Validator, can represent ONLY GeoCircleFence """
type = validators.OneOf(["GEO_CIRCLE"])
name = validators.UnicodeString(not_empty=True)
class NoteSchema(Schema):
allow_extra_fields = True
name = validators.UnicodeString(not_empty=True)
text = validators.UnicodeString(not_empty=True)
pad_id = validators.Int()
class ForgotPasswordSchema(Schema):
allow_extra_fields = False
email = All(EmailExists(), validators.Email(not_empty=True))
class ChangePasswordSchema(Schema):
allow_extra_fields = False
old_password = All(PasswordCorrect(), validators.UnicodeString(min=6))
password = validators.UnicodeString(min=6)
confirm_password = validators.UnicodeString(min=6)
passwords_match = [
validators.FieldsMatch('password', 'confirm_password')
]
""" need a special class that will allow None through but not '' """
def is_empty(self, value):
# only consider None empty, not an empty string
return value is None
class _ValidatesMinLength(ValidatorBase):
fe_validator = _MinLength
def arg_for_fe_validator(self, index, unknown_arg):
if isinstance(unknown_arg, int):
return True
return False
class _IPAddress(fev.IPAddress):
""" need a special class that will allow None through but not '' """
def is_empty(self, value):
# only consider None empty, not an empty string
return value is None
class _ValidatesIPAddress(ValidatorBase):
fe_validator = _IPAddress
class _URL(fev.URL):
""" need a special class that will allow None through but not '' """
def is_empty(self, value):
# only consider None empty, not an empty string
return value is None
allow_extra_fields = True
filter_extra_fields = True
name = formencode.validators.String(if_missing=None)
description = formencode.validators.String(if_missing=None)
os_variant = formencode.validators.String(if_missing=None)
os_type = formencode.validators.String(if_missing=None)
os_arch = formencode.validators.String(if_missing=None)
hypervisor = formencode.validators.String(if_missing=None)
owner = formencode.validators.String(if_missing=None)
expires = formencode.validators.String(if_missing=None)
#expires = formencode.validators.DateTime???
read_only = formencode.validators.StringBool(if_missing=None)
unauthenticated_access = formencode.validators.StringBool(if_missing=None)
def validate_raw_image(params):
schema = NewImageForm()
try:
result = schema.to_python(params)
except formencode.validators.Invalid, error:
for e,v in error.error_dict.iteritems():
if e=='name' and v.state=='CONFLICT':
abort(409, '409 Conflict')
else:
abort(400, '400 Bad Request')
else:
return result
class RawImageForm(formencode.Schema):
for plugin in getFactoredPlugins():
pluginpath = os.path.join(app.base_auth_url, plugin.path)
if pluginpath == req.path:
return plugin(req)
class UsernameSchema(BaseSchema):
username = validators.MinLength(3, not_empty=True)
referrer = validators.UnicodeString(if_missing=u'')
class CodeSchema(BaseSchema):
username = validators.MinLength(3, not_empty=True)
code = validators.MinLength(4, not_empty=True)
remember = validators.Bool()
referrer = validators.UnicodeString(if_missing=u'')
class BasePlugin(object):
name = None
path = None
username_schema = UsernameSchema
code_schema = CodeSchema
content_renderer = "templates/auth.pt"
_formtext = {
'title': None,
'legend': None,
'username': {
'label': None,
'desc': None
},
email = validators.Email(not_empty=True)
password = validators.UnicodeString(min=6)
class PadSchema(Schema):
allow_extra_fields = True
name = validators.UnicodeString(not_empty=True)
class NoteSchema(Schema):
allow_extra_fields = True
name = validators.UnicodeString(not_empty=True)
text = validators.UnicodeString(not_empty=True)
pad_id = validators.Int()
class ForgotPasswordSchema(Schema):
allow_extra_fields = False
email = All(EmailExists(), validators.Email(not_empty=True))
class ChangePasswordSchema(Schema):
allow_extra_fields = False
old_password = All(PasswordCorrect(), validators.UnicodeString(min=6))
password = validators.UnicodeString(min=6)
confirm_password = validators.UnicodeString(min=6)
passwords_match = [
validators.FieldsMatch('password', 'confirm_password')
@without_trailing_slash
@expose()
@validate(dict(
since=h.DateTimeConverter(if_empty=None, if_invalid=None),
until=h.DateTimeConverter(if_empty=None, if_invalid=None),
page=validators.Int(if_empty=None),
limit=validators.Int(if_empty=None)))
def feed(self, since=None, until=None, page=None, limit=None):
if request.environ['PATH_INFO'].endswith('.atom'):
feed_type = 'atom'
else:
feed_type = 'rss'
title = 'Recent changes to Project %s' % c.project.name
feed = M.Feed.feed(
dict(project_id=c.project._id),
feed_type,
title,
c.project.url(),
title,
since, until, page, limit)
response.headers['Content-Type'] = ''
response.content_type = 'application/xml'