def get_context_for_object(self, obj): return { 'instance': obj, 'controller': self, 'instance_json': lambda: as_json({ self.model_name: ggrc.builder.json.publish(obj) }) }
def get_all_attributes_json(load_custom_attributes=False): """Get a list of all attribute definitions This exports all attributes related to a given model, including custom attributes and mapping attributes, that are used in csv import and export. """ with benchmark('Loading all attributes JSON'): published = {} ca_cache = collections.defaultdict(list) if load_custom_attributes: # get only GCA and exclude external CADs # external GCA should be deleted from internal GCA table definitions = models.CustomAttributeDefinition.eager_query( ).filter(~models.CustomAttributeDefinition.definition_type.in_( constants.GGRCQ_OBJ_TYPES_FOR_SYNC)).group_by( models.CustomAttributeDefinition.title, models.CustomAttributeDefinition.definition_type) for attr in definitions: ca_cache[attr.definition_type].append(attr) ecad = models.ExternalCustomAttributeDefinition definitions = ecad.eager_query().group_by( models.ExternalCustomAttributeDefinition.title, models.ExternalCustomAttributeDefinition.definition_type) for attr in definitions: ca_cache[attr.definition_type].append(attr) for model in models.all_models.all_models: published[model.__name__] = \ reflection.AttributeInfo.get_attr_definitions_array( model, ca_cache=ca_cache) return services_common.as_json(published)
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_context_for_object(self, obj): return { 'instance': obj, 'controller': self, 'instance_json': lambda: as_json({ self.model._inflector.table_singular: ggrc.builder.json.publish(obj) }) }
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_object_json(self, obj): """Returns object json""" with benchmark("Get object JSON"): return as_json({ self.model._inflector.table_singular: filter_resource( ggrc.builder.json.publish_representation( ggrc.builder.json.publish(obj, (), inclusion_filter))) })
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 related_objects(): obj_id = request.args['oid'] obj_type = request.args['otype'] far_type = request.args['related_model'] related_object_results = RelatedObjectResults(obj_id, obj_type, far_type) results = related_object_results.get_results() current_app.make_response(( 'application/json', 200, [('Content-Type', 'application/json')])) return as_json(results)
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 related_objects(): obj_id = request.args['oid'] obj_type = request.args['otype'] far_type = request.args['related_model'] related_object_results = RelatedObjectResults(obj_id, obj_type, far_type) results = related_object_results.get_results() current_app.make_response( ('application/json', 200, [('Content-Type', 'application/json')])) return as_json(results)
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_current_user_json(): """Get current user""" with benchmark("Get current user JSON"): person = get_current_user() return as_json({ "id": person.id, "company": person.company, "email": person.email, "language": person.language, "name": person.name, "system_wide_role": person.system_wide_role, })
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_all_attributes_json(load_custom_attributes=False): """Get a list of all attribute definitions This exports all attributes related to a given model, including custom attributes and mapping attributes, that are used in csv import and export. """ with benchmark('Loading all attributes JSON'): published = {} ca_cache = collections.defaultdict(list) if load_custom_attributes: definitions = models.CustomAttributeDefinition.eager_query().group_by( models.CustomAttributeDefinition.title, models.CustomAttributeDefinition.definition_type) for attr in definitions: ca_cache[attr.definition_type].append(attr) for model in all_models.all_models: published[model.__name__] = \ AttributeInfo.get_attr_definitions_array(model, ca_cache=ca_cache) return as_json(published)
def get_all_attributes_json(load_custom_attributes=False): """Get a list of all attribute definitions This exports all attributes related to a given model, including custom attributes and mapping attributes, that are used in csv import and export. """ with benchmark('Loading all attributes JSON'): published = {} ca_cache = collections.defaultdict(list) if load_custom_attributes: definitions = models.CustomAttributeDefinition.eager_query( ).group_by(models.CustomAttributeDefinition.title, models.CustomAttributeDefinition.definition_type) for attr in definitions: ca_cache[attr.definition_type].append(attr) for model in all_models.all_models: published[model.__name__] = \ AttributeInfo.get_attr_definitions_array(model, ca_cache=ca_cache) return 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"): # 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