def _transform_to_json(objects, fields=None): """Make a JSON representation of objects from the list.""" objects_json = [json.publish(obj) for obj in objects] objects_json = json.publish_representation(objects_json) if fields: objects_json = [{f: o.get(f) for f in fields} for o in objects_json] return objects_json
def get_full_user_json(): """Get the full current user""" with benchmark("Get full user JSON"): from ggrc.models.person import Person current_user = get_current_user() person = Person.eager_query().filter_by(id=current_user.id).one() result = publish_representation(publish(person, (), inclusion_filter)) return as_json(result)
def get_full_user_json(): """Get the full current user""" with benchmark("Get full user JSON"): from ggrc.models.person import Person current_user = get_current_user() person = Person.eager_query().filter_by(id=current_user.id).one() result = publish_representation(publish(person, (), inclusion_filter)) return as_json(result)
def _transform_to_json(objects, fields=None): """Make a JSON representation of objects from the list.""" objects_json = [json.publish(obj) for obj in objects] objects_json = json.publish_representation(objects_json) if fields: objects_json = [{f: o.get(f) for f in fields} for o in objects_json] return objects_json
def get_access_control_roles_json(): """Get a list of all access control roles""" with benchmark("Get access roles JSON"): attrs = all_models.AccessControlRole.query.all() published = [] for attr in attrs: published.append(publish(attr)) published = publish_representation(published) return as_json(published)
def get_roles_json(): """Get a list of all roles""" with benchmark("Get roles JSON"): attrs = all_models.Role.query.all() published = [] for attr in attrs: published.append(publish(attr, attribute_whitelist=('id', 'name'))) published = publish_representation(published) return as_json(published)
def get_roles_json(): """Get a list of all roles""" with benchmark("Get roles JSON"): attrs = all_models.Role.query.all() published = [] for attr in attrs: published.append(publish(attr, attribute_whitelist=('id', 'name'))) published = publish_representation(published) return as_json(published)
def get_access_control_roles_json(): """Get a list of all access control roles""" with benchmark("Get access roles JSON"): attrs = all_models.AccessControlRole.query.all() published = [] for attr in attrs: published.append(publish(attr)) published = publish_representation(published) return as_json(published)
def get_attributes_json(): """Get a list of all custom attribute definitions""" with benchmark("Get attributes JSON"): attrs = models.CustomAttributeDefinition.eager_query().filter( models.CustomAttributeDefinition.definition_id.is_(None)) published = [] for attr in attrs: published.append(publish(attr)) published = publish_representation(published) return as_json(published)
def get_access_control_roles_json(): """Get a list of all access control roles""" with benchmark("Get access roles JSON"): attrs = all_models.AccessControlRole.query.options( sqlalchemy.orm.undefer_group("AccessControlRole_complete")).all() published = [] for attr in attrs: published.append(publish(attr)) published = publish_representation(published) return as_json(published)
def get_attributes_json(): """Get a list of all custom attribute definitions""" with benchmark("Get attributes JSON"): attrs = models.CustomAttributeDefinition.eager_query().filter( models.CustomAttributeDefinition.definition_id.is_(None) ) published = [] for attr in attrs: published.append(publish(attr)) published = publish_representation(published) return as_json(published)
def get_internal_roles_json(): """Get a list of all access control roles""" with benchmark("Get access roles JSON"): attrs = all_models.AccessControlRole.query.options( sqlalchemy.orm.undefer_group("AccessControlRole_complete") ).filter(all_models.AccessControlRole.internal == true()).all() published = [] for attr in attrs: published.append(publish(attr)) published = publish_representation(published) return as_json(published)
def get_internal_roles_json(): """Get a list of all access control roles""" with benchmark("Get access roles JSON"): attrs = models.all_models.AccessControlRole.query.options( sqlalchemy.orm.undefer_group("AccessControlRole_complete")).filter( models.all_models.AccessControlRole.internal == sqlalchemy.true()).all() published = [] for attr in attrs: published.append(builder_json.publish(attr)) published = builder_json.publish_representation(published) return services_common.as_json(published)
def get_attributes_json(): """Get a list of all custom attribute definitions""" with benchmark("Get attributes JSON"): with benchmark("Get attributes JSON: query"): attrs = models.CustomAttributeDefinition.eager_query().filter( models.CustomAttributeDefinition.definition_id.is_( None)).all() with benchmark("Get attributes JSON: publish"): published = [] for attr in attrs: published.append(builder_json.publish(attr)) published = builder_json.publish_representation(published) with benchmark("Get attributes JSON: json"): publish_json = services_common.as_json(published) return publish_json
def get_attributes_json(): """Get a list of all custom attribute definitions""" with benchmark("Get attributes JSON"): with benchmark("Get attributes JSON: query"): attrs = models.CustomAttributeDefinition.eager_query().filter( models.CustomAttributeDefinition.definition_id.is_(None) ).all() with benchmark("Get attributes JSON: publish"): published = [] for attr in attrs: published.append(builder_json.publish(attr)) published = builder_json.publish_representation(published) with benchmark("Get attributes JSON: json"): publish_json = services_common.as_json(published) return publish_json
def get_attributes_json(): """Get a list of all custom attribute definitions""" with benchmark("Get attributes JSON"): with benchmark("Get attributes JSON: query"): # get only GCA and exclude external CADs # external GCA should be deleted from internal GCA table attrs = models.CustomAttributeDefinition.eager_query().filter( models.CustomAttributeDefinition.definition_id.is_(None), ~models.CustomAttributeDefinition.definition_type.in_( constants.GGRCQ_OBJ_TYPES_FOR_SYNC)).all() ext_attrs = models.ExternalCustomAttributeDefinition.eager_query( ).all() with benchmark("Get attributes JSON: publish"): published = [] for attr in attrs: published.append(builder_json.publish(attr)) for attr in ext_attrs: published.append(builder_json.publish(attr)) published = builder_json.publish_representation(published) with benchmark("Get attributes JSON: json"): publish_json = services_common.as_json(published) return publish_json