Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@jsonify.when('isinstance(obj, MyClass)')
def jsonify_myclass(obj):
return {'result':'wo-hoo!'}
@jsonify.when('isinstance(obj, MyClass)')
def jsonify_myclass(obj):
return {'result':'wo-hoo!'}
if 'simplesearch_label' in kw:
self.simplesearch_label = kw['simplesearch_label']
else:
self.simplesearch_label = 'Search'
self.button_widget = MyButton(name='quick_search')
self.quickly_searches = []
if 'quick_searches' in kw:
if kw['quick_searches'] is not None:
for elem,name in kw['quick_searches']:
vals = elem.split('-')
if len(vals) != 3:
log.error('Quick searches expects vals as --. The following is incorrect: %s' % (elem))
else:
self.quickly_searches.append((name, '%s-%s-%s' % (vals[0],vals[1],vals[2])))
self.date_picker = jsonify.encode(kw.get('date_picker',list()) )
controllers = kw.get('table_search_controllers',dict())
self.table_search_controllers_stringified = str(controllers)
self.to_json = UtilJSON.dynamic_json()
self.extra_callbacks_stringified = str(self.extra_callbacks)
self.fields.extend(new_inputs)
self.fields.extend(new_selects)
created = DateTimeCol(default=datetime.now)
# Old names
groupId = DeprecatedAttr("groupId", "group_name")
displayName = DeprecatedAttr("displayName", "display_name")
# collection of all users belonging to this group
users = RelatedJoin("TG_User", intermediateTable="tg_user_group",
joinColumn="group_id", otherColumn="user_id")
# collection of all permissions for this group
permissions = RelatedJoin("TG_Permission", joinColumn="group_id",
intermediateTable="tg_group_permission",
otherColumn="permission_id")
[jsonify.when('isinstance(obj, TG_Group)')]
def jsonify_group(obj):
"""Convert group to JSON."""
result = jsonify_sqlobject(obj)
result["users"] = [u.user_name for u in obj.users]
result["permissions"] = [p.permission_name for p in obj.permissions]
return result
class TG_User(InheritableSQLObject):
"""Reasonably basic User definition."""
class sqlmeta:
table = "tg_user"
user_name = UnicodeCol(length=16, alternateID=True,
alternateMethodName="by_user_name")
email_address = UnicodeCol(length=255, alternateID=True,
@jsonify.when('isinstance(obj, sqlalchemy.orm.query.Query)')
def jsonify_sa_select_results(obj):
'''Transform selectresults into lists.
The one special thing is that we bind the special json_props into each
descendent. This allows us to specify a json_props on the toplevel
query result and it will pass to all of its children.
:arg obj: sqlalchemy Query object to jsonify
:Returns: list representation of the Query with each element in it given
a json_props attributes
'''
if 'json_props' in obj.__dict__:
for element in obj:
element.json_props = obj.json_props
return list(obj)
@jsonify.when('isinstance(obj, Group)')
def jsonify_group(obj):
result = jsonify_sqlobject( obj )
result["users"] = [u.user_name for u in obj.users]
result["permissions"] = [p.permission_name for p in obj.permissions]
return result
@jsonify.when('isinstance(obj, User)')
def jsonify_user(obj):
result = jsonify_sqlobject( obj )
del result['password']
result["groups"] = [g.group_name for g in obj.groups]
result["permissions"] = [p.permission_name for p in obj.permissions]
return result
@jsonify.when('''(
isinstance(obj, sqlalchemy.orm.collections.InstrumentedList) or
isinstance(obj, sqlalchemy.orm.attributes.InstrumentedAttribute) or
isinstance(obj, sqlalchemy.ext.associationproxy._AssociationList))''')
def jsonify_salist(obj):
'''Transform SQLAlchemy InstrumentedLists into json.
The one special thing is that we bind the special json_props into each
descendent. This allows us to specify a json_props on the toplevel
query result and it will pass to all of its children.
:arg obj: One of the sqlalchemy list types to jsonify
:Returns: list of jsonified elements
'''
if 'json_props' in obj.__dict__:
for element in obj:
element.json_props = obj.json_props
except identity.exceptions.IdentityManagementNotEnabledException:
# Creating identity provider just to encrypt password
# (so we don't reimplement the encryption step).
ip = SqlObjectCsrfIdentityProvider()
hash = ip.encrypt_password(cleartext_password)
if hash == cleartext_password:
log.info("Identity provider not enabled,"
" and no encryption algorithm specified in config."
" Setting password as plaintext.")
self._SO_set_password(hash)
def set_password_raw(self, password):
"""Save the password as-is to the database."""
self._SO_set_password(password)
[jsonify.when('isinstance(obj, TG_User)')]
def jsonify_user(obj):
"""Convert user to JSON."""
result = jsonify_sqlobject(obj)
del result['password']
result["groups"] = [g.group_name for g in obj.groups]
result["permissions"] = [p.permission_name for p in obj.permissions]
return result
class TG_Permission(InheritableSQLObject):
"""Permissions for a given group."""
class sqlmeta:
table = "tg_permission"
permission_name = UnicodeCol(length=16, alternateID=True,
alternateMethodName="by_permission_name")
@jsonify.when("isinstance(obj, sqlalchemy.orm.attributes.InstrumentedAttribute) or isinstance(obj, sqlalchemy.ext.associationproxy._AssociationList)")
def jsonify_salist(obj):
'''Transform SQLAlchemy InstrumentedLists into json.
The one special thing is that we bind the special jsonProps into each
descendent. This allows us to specify a jsonProps on the toplevel
query result and it will pass to all of its children.
'''
if 'jsonProps' in obj.__dict__:
for element in obj:
element.jsonProps = obj.jsonProps
return [jsonify(element) for element in obj]