예제 #1
0
 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
예제 #2
0
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
예제 #3
0
파일: file.py 프로젝트: ahurriyetoglu/grano
 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
     }
예제 #4
0
 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
     }
예제 #5
0
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
예제 #6
0
파일: projects.py 프로젝트: eocaollai/grano
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
예제 #7
0
    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
예제 #8
0
파일: entity.py 프로젝트: clkao/grano
    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
예제 #9
0
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')
        }
    })
예제 #10
0
파일: sessions_api.py 프로젝트: 01-/grano
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
    })
예제 #11
0
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
    })
예제 #12
0
 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
예제 #13
0
 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)
     }
예제 #14
0
파일: project.py 프로젝트: 01-/grano
 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)
     }
예제 #15
0
 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
예제 #16
0
파일: base_api.py 프로젝트: 4bic/grano
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"),
            },
        }
    )
예제 #17
0
 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
예제 #18
0
파일: schema.py 프로젝트: clkao/grano
 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)
     }
예제 #19
0
파일: pager.py 프로젝트: clkao/grano
 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
예제 #20
0
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
예제 #21
0
파일: project.py 프로젝트: jacqui/grano
 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()
     }
예제 #22
0
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)
예제 #23
0
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)
예제 #24
0
파일: sessions_api.py 프로젝트: clkao/grano
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)
예제 #25
0
파일: sessions_api.py 프로젝트: clkao/grano
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)
예제 #26
0
파일: sessions_api.py 프로젝트: clkao/grano
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)
예제 #27
0
파일: sessions_api.py 프로젝트: 01-/grano
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)
예제 #28
0
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)
예제 #29
0
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)
예제 #30
0
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)
예제 #31
0
 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()
     }
예제 #32
0
 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)
     }
예제 #33
0
파일: entities_api.py 프로젝트: 01-/grano
 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
예제 #34
0
 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)
         }
예제 #35
0
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),
    }
예제 #36
0
 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()
     }
예제 #37
0
파일: entity.py 프로젝트: clkao/grano
    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
예제 #38
0
 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
     }
예제 #39
0
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)
    }
예제 #40
0
    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
예제 #41
0
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)
    }
예제 #42
0
    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
예제 #43
0
 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
예제 #44
0
파일: entity.py 프로젝트: 01-/grano
    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
예제 #45
0
파일: schema.py 프로젝트: gabelula/grano
 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)
     }
예제 #46
0
    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
예제 #47
0
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),
    }
예제 #48
0
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
예제 #49
0
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
예제 #50
0
 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
     }
예제 #51
0
 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)
     }
예제 #52
0
 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
     }
예제 #53
0
 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)
     }
예제 #54
0
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
예제 #55
0
 def to_dict_index(self):
     return {
         'id': self.id,
         'api_url': url_for('accounts_api.view', id=self.id),
         'display_name': self.display_name
     }
예제 #56
0
파일: projects.py 프로젝트: eocaollai/grano
def to_rest_index(project):
    return {
        'slug': project.slug,
        'label': project.label,
        'api_url': url_for('projects_api.view', slug=project.slug)
    }