def to_dict(self): data = self.to_dict_index() data['settings'] = self.settings data['author'] = self.author.to_dict_index() data['schemata_index_url'] = url_for('schemata_api.index', slug=self.slug) data['entities_index_url'] = url_for('entities_api.index', project=self.slug) data['relations_index_url'] = url_for('relations_api.index', project=self.slug) return data
def to_rest(project): data = to_rest_index_stats(project) data['settings'] = project.settings data['author'] = accounts.to_rest_index(project.author) data['schemata_index_url'] = url_for('schemata_api.index', slug=project.slug) data['entities_index_url'] = url_for('entities_api.index', project=project.slug) data['relations_index_url'] = url_for('relations_api.index', project=project.slug) return data
def to_dict_index(self): return { 'id': self.id, 'project': self.project.to_dict_index(), 'api_url': url_for('files_api.view', id=self.id), 'serve_api_url': url_for('files_api.serve', id=self.id), 'file_name': self.file_name, 'mime_type': self.mime_type }
def to_rest_base(entity): data = { 'id': entity.id, 'project': projects_logic.to_rest_index(entity.project), 'api_url': url_for('entities_api.view', id=entity.id), 'same_as': entity.same_as } if entity.same_as: data['same_as_url'] = url_for('entities_api.view', id=entity.same_as) return data
def to_dict(self): """ Full serialization of the entity. """ data = self.to_dict_index() data['created_at'] = self.created_at data['updated_at'] = self.updated_at if data['degree_in'] > 0: data['inbound_url'] = url_for('relations_api.index', target=self.id) if data['degree_out'] > 0: data['outbound_url'] = url_for('relations_api.index', source=self.id) return data
def to_dict_base(self): data = { 'id': self.id, 'project': self.project.to_dict_index(), 'api_url': url_for('entities_api.view', id=self.id), } data['schemata'] = [s.to_dict_index() for s in self.schemata] if self.same_as: data['same_as'] = self.same_as data['same_as_url'] = url_for('entities_api.view', id=self.same_as) return data
def status(): validate_cache(last_modified=startup_time) return jsonify({ 'service': app_name, 'status': 'ok', 'version': app_version, 'docs': 'http://docs.grano.cc/rest_api.html', 'api_url': url_for('base_api.status'), 'services': { 'projects_index_url': url_for('projects_api.index'), 'entities_index_url': url_for('entities_api.index'), 'relations_index_url': url_for('relations_api.index'), 'sessions_status_url': url_for('sessions_api.status') } })
def status(): permissions = {} if authz.logged_in(): for permission in request.account.permissions: permissions[permission.project.slug] = { 'reader': permission.reader, 'editor': permission.editor, 'admin': permission.admin } keys = { 'p': repr(permissions), 'i': request.account.id if authz.logged_in() else None } validate_cache(keys=keys) oauth_providers = {} for name, provider in PROVIDERS.items(): if not isinstance(provider, Stub): oauth_providers[name] = url_for('.login', provider=name) return jsonify({ 'logged_in': authz.logged_in(), 'api_key': request.account.api_key if authz.logged_in() else None, 'account': request.account if request.account else None, 'permissions': permissions, 'oauth': oauth_providers })
def convert(props): for prop in props: data.append({ 'name': prop.value, 'api_url': url_for('entities_api.view', id=prop.entity_id) }) return data
def to_dict_short(self): return { 'slug': self.slug, 'label': self.label, 'private': self.private, 'api_url': url_for('projects_api.view', slug=self.slug) }
def status(): validate_cache(last_modified=startup_time) return jsonify( { "service": app_name, "status": "ok", "version": app_version, "docs": "http://granoproject.org/docs", "api_url": url_for("base_api.status"), "services": { "projects_index_url": url_for("projects_api.index"), "entities_index_url": url_for("entities_api.index"), "relations_index_url": url_for("relations_api.index"), "sessions_status_url": url_for("sessions_api.status"), }, } )
def url(self, query): url = url_for(request.endpoint, **dict(self.kwargs)) if len(query): qs = urlencode(query) url = url + '?' + qs #if self.name is not None: # url = url + '#' + self.name return url
def to_dict_index(self): return { 'name': self.name, 'label': self.label, 'hidden': self.hidden, 'obj': self.obj, 'api_url': url_for('schemata_api.view', slug=self.project.slug, name=self.name) }
def url(self, query): url = url_for(request.endpoint, **dict(self.kwargs)) if len(query): qs = urlencode(query) url = url + '?' + qs if self.name is not None: url = url + '#' + self.name return url
def to_rest_index(schema): data = to_basic(schema) data['obj'] = schema.obj data['project'] = projects_logic.to_rest_index(schema.project) data['api_url'] = url_for('schemata_api.view', slug=schema.project.slug, name=schema.name) return data
def to_dict_index(self): return { 'slug': self.slug, 'label': self.label, 'private': self.private, 'api_url': url_for('projects_api.view', slug=self.slug), 'entities_count': self.entities.count(), 'relations_count': self.relations.count() }
def entity_link(entity, **kwargs): if isinstance(entity, Entity): prop = entity['name'] id, name = entity.id, prop.value if prop else 'forward' else: prop = entity.get('properties', {}).get('name', {}) id, name = entity.get('id'), prop.get('value', 'forward') return url_for('entities.view', id=id, slug=url_slug(name), **kwargs)
def twitter_login(): if not app.config.get('TWITTER_API_KEY'): return provider_not_enabled('twitter') callback = url_for('sessions_api.twitter_authorized') session.clear() if not request.args.get('next_url'): raise BadRequest("No 'next_url' is specified.") session['next_url'] = request.args.get('next_url') return twitter.authorize(callback=callback)
def twitter_login(): if not app.config.get('TWITTER_API_KEY'): return provider_not_enabled('twitter') callback=url_for('sessions_api.twitter_authorized') session.clear() if not request.args.get('next_url'): raise BadRequest("No 'next_url' is specified.") session['next_url'] = request.args.get('next_url') return twitter.authorize(callback=callback)
def facebook_login(): if not app.config.get('FACEBOOK_APP_ID'): return provider_not_enabled('facebook') callback=url_for('sessions_api.facebook_authorized') session.clear() if not request.args.get('next_url'): raise BadRequest("No 'next_url' is specified.") session['next_url'] = request.args.get('next_url') return facebook.authorize(callback=callback)
def github_login(): if not app.config.get('GITHUB_CLIENT_ID'): return provider_not_enabled('github') callback=url_for('sessions_api.github_authorized') session.clear() if not request.args.get('next_url'): raise BadRequest("No 'next_url' is specified.") session['next_url'] = request.args.get('next_url') return github.authorize(callback=callback)
def login(provider): if provider not in PROVIDERS: raise BadRequest('Unknown provider: %s' % provider) callback = url_for('sessions_api.%s_authorized' % provider) session.clear() if not request.args.get('next_url'): raise BadRequest("No 'next_url' is specified.") session['next_url'] = request.args.get('next_url') return PROVIDERS[provider].authorize(callback=callback)
def github_login(): if not app.config.get('GITHUB_CLIENT_ID'): return provider_not_enabled('github') callback = url_for('sessions_api.github_authorized') session.clear() if not request.args.get('next_url'): raise BadRequest("No 'next_url' is specified.") session['next_url'] = request.args.get('next_url') return github.authorize(callback=callback)
def facebook_login(): if not app.config.get('FACEBOOK_APP_ID'): return provider_not_enabled('facebook') callback = url_for('sessions_api.facebook_authorized') session.clear() if not request.args.get('next_url'): raise BadRequest("No 'next_url' is specified.") session['next_url'] = request.args.get('next_url') return facebook.authorize(callback=callback)
def convert(props): for prop in props: data.append({ 'properties': { 'name': prop.to_dict_index(), }, 'id': prop.entity_id, 'api_url': url_for('entities_api.view', id=prop.entity_id) }) return data
def to_dict_index(self): return { 'id': self.id, 'reader': self.reader, 'editor': self.editor, 'admin': self.admin, 'project': self.project.to_dict_index(), 'account': self.account.to_dict_index(), 'api_url': url_for('permissions_api.view', slug=self.project.slug, id=self.id) }
def to_rest_index(permission): return { "id": permission.id, "reader": permission.reader, "editor": permission.editor, "admin": permission.admin, "project": projects_logic.to_rest_index(permission.project), "account": accounts_logic.to_rest_index(permission.account), "api_url": url_for("permissions_api.view", slug=permission.project.slug, id=permission.id), }
def to_dict_base(self): return { 'id': self.id, 'properties': {}, 'project': self.project.to_dict_index(), 'api_url': url_for('relations_api.view', id=self.id), 'schema': self.schema.to_dict_index(), 'source': self.source.to_dict_index(), 'target': self.target.to_dict_index() }
def to_dict(self): """ Full serialization of the entity. """ data = self.to_dict_base() data['created_at'] = self.created_at data['updated_at'] = self.updated_at data['properties'] = {} for prop in self.active_properties: name, prop = prop.to_dict() data['properties'][name] = prop data['inbound_relations'] = self.inbound.count() if data['inbound_relations'] > 0: data['inbound_url'] = url_for('relations_api.index', target=self.id) data['outbound_relations'] = self.outbound.count() if data['outbound_relations'] > 0: data['outbound_url'] = url_for('relations_api.index', source=self.id) return data
def to_dict_index(self): return { 'id': self.id, 'level': self.level, 'message': self.message, 'error': self.error, 'api_url': url_for('log_entries_api.view_entry', pipeline_id=self.pipeline.id, id=self.id), 'created_at': self.created_at, 'updated_at': self.updated_at }
def to_rest_base(relation): from grano.logic import entities as entities_logic return { 'id': relation.id, 'properties': {}, 'project': projects_logic.to_rest_index(relation.project), 'api_url': url_for('relations_api.view', id=relation.id), 'schema': schemata_logic.to_rest_index(relation.schema), 'source': entities_logic.to_rest_index(relation.source), 'target': entities_logic.to_rest_index(relation.target) }
def to_dict_index(self): """ Convert an entity to the REST API form. """ data = { 'id': self.id, 'status': self.status, 'project': self.project.to_dict_index(), 'api_url': url_for('entities_api.view', id=self.id), 'properties': {} } data['schemata'] = [s.to_dict_index() for s in self.schemata] for prop in self.active_properties: name, prop = prop.to_dict_kv() data['properties'][name] = prop if self.same_as: data['same_as'] = self.same_as data['same_as_url'] = url_for('entities_api.view', id=self.same_as) return data
def to_dict_index(self): """ Convert an entity to the REST API form. """ data = { 'id': self.id, 'degree': self.degree, 'degree_in': self.degree_in, 'degree_out': self.degree_out, 'project': self.project.to_dict_short(), 'schema': self.schema.to_dict_index(), 'api_url': url_for('entities_api.view', id=self.id), 'properties': {} } for prop in self.active_properties: name, prop = prop.to_dict_kv() data['properties'][name] = prop if self.same_as: data['same_as'] = self.same_as data['same_as_url'] = url_for('entities_api.view', id=self.same_as) return data
def to_dict_index(self): return { 'name': self.name, 'default': self.name == ENTITY_DEFAULT_SCHEMA, 'label': self.label, 'hidden': self.hidden, 'meta': self.meta, 'obj': self.obj, 'api_url': url_for('schemata_api.view', slug=self.project.slug, name=self.name) }
def to_rest_base(relation): from grano.logic import entities as entities_logic return { "id": relation.id, "properties": {}, "project": projects_logic.to_rest_index(relation.project), "api_url": url_for("relations_api.view", id=relation.id), "schema": schemata_logic.to_rest_index(relation.schema), "source": entities_logic.to_rest_index(relation.source), "target": entities_logic.to_rest_index(relation.target), }
def to_rest(entity): """ Full serialization of the entity. """ data = to_rest_base(entity) data['created_at'] = entity.created_at data['updated_at'] = entity.updated_at ss = [schemata_logic.to_rest_index(s) for s in entity.schemata] data['schemata'] = ss data['properties'] = {} for prop in entity.active_properties: name, prop = properties_logic.to_rest(prop) data['properties'][name] = prop data['inbound_relations'] = entity.inbound.count() if data['inbound_relations'] > 0: data['inbound_url'] = url_for('relations_api.index', target=entity.id) data['outbound_relations'] = entity.outbound.count() if data['outbound_relations'] > 0: data['outbound_url'] = url_for('relations_api.index', source=entity.id) return data
def to_dict_index(self): return { 'id': self.id, 'label': self.label, 'project': self.project.to_dict_short() if self.project else None, 'author': self.author.to_dict_index(), 'api_url': url_for('pipelines_api.view', id=self.id), 'operation': self.operation, 'status': self.status, 'created_at': self.created_at, 'updated_at': self.updated_at, 'started_at': self.started_at, 'ended_at': self.ended_at, 'config': self.config, 'percent_complete': self.percent_complete }
def sitemap_xml(): rp = db.session.execute(""" SELECT e.id AS id, p.value_string AS name, e.updated_at AS updated FROM grano_entity e, grano_property p, grano_relation r WHERE e.id = p.entity_id AND p.name = 'name' AND p.value_string IS NOT NULL AND p.active = true AND (r.target_id = e.id OR r.source_id = e.id) GROUP BY e.id, p.value_string, e.updated_at ORDER BY COUNT(r.id) DESC LIMIT 49500 """) entities = [] while True: row = rp.fetchone() if row is None: break url = url_for('entities.view', id=row['id'], slug=url_slug(row['name'])) entities.append((url, row['updated'])) text = render_template('sitemap_simple.xml', entities=entities) res = make_response(text) res.headers['Content-Type'] = 'text/xml' return res
def to_dict_index(self): return { 'id': self.id, 'api_url': url_for('accounts_api.view', id=self.id), 'display_name': self.display_name }
def to_rest_index(project): return { 'slug': project.slug, 'label': project.label, 'api_url': url_for('projects_api.view', slug=project.slug) }