コード例 #1
0
ファイル: facets.py プロジェクト: gabelula/grano
def parse_relation_facets(relation_obj, full_facet, facet, q):
    """ Parse a facet related to an entity and return a modified
    query. """
    if facet == 'project':
        facet_obj = aliased(Project)
        q = q.join(facet_obj, relation_obj.project)
        return apply_facet_obj(q, facet_obj)
    elif facet == 'schema':
        facet_obj = aliased(Schema)
        if not arg_bool('facet_%s_hidden' % full_facet, default=False):
            q = q.filter(facet_obj.hidden == False)
        q = q.join(facet_obj, relation_obj.schema)
        return apply_facet_obj(q, facet_obj)
    elif facet.startswith('properties.'):
        return apply_property_facet(q, facet, Property,
                                    relation_obj)
    elif facet.startswith('source.'):
        _, subfacet = facet.split('.', 1)
        ent_obj = aliased(Entity)
        q = q.join(ent_obj, relation_obj.source)
        return parse_entity_facets(ent_obj, full_facet, subfacet, q)
    elif facet.startswith('target.'):
        _, subfacet = facet.split('.', 1)
        ent_obj = aliased(Entity)
        q = q.join(ent_obj, relation_obj.target)
        return parse_entity_facets(ent_obj, full_facet, subfacet, q)
    else:
        raise BadRequest("Unknown facet: %s" % facet)
コード例 #2
0
ファイル: facets.py プロジェクト: gabelula/grano
def parse_entity_facets(entity_obj, full_facet, facet, q):
    """ Parse a facet related to a relation object and return a
    modified query. """
    # TODO: Status facet.
    # TODO: Author facet.
    if facet == 'project':
        facet_obj = aliased(Project)
        q = q.join(facet_obj, entity_obj.project)
        return apply_facet_obj(q, facet_obj)
    elif facet == 'schema':
        facet_obj = aliased(Schema)
        if not arg_bool('facet_%s_hidden' % full_facet, default=False):
            q = q.filter(facet_obj.hidden == False)
        q = q.join(facet_obj, entity_obj.schemata)
        return apply_facet_obj(q, facet_obj)
    elif facet.startswith('properties.'):
        return apply_property_facet(q, facet, Property,
                                    entity_obj)
    elif facet.startswith('inbound.'):
        _, subfacet = facet.split('.', 1)
        rel_obj = aliased(Relation)
        q = q.join(rel_obj, entity_obj.inbound)
        return parse_relation_facets(rel_obj, full_facet, subfacet, q)
    elif facet.startswith('outbound.'):
        _, subfacet = facet.split('.', 1)
        rel_obj = aliased(Relation)
        q = q.join(rel_obj, entity_obj.outbound)
        return parse_relation_facets(rel_obj, full_facet, subfacet, q)
    else:
        raise BadRequest("Unknown facet: %s" % facet)
コード例 #3
0
ファイル: facets.py プロジェクト: j-norwood-young/grano
def parse_relation_facets(relation_obj, full_facet, facet, q):
    """ Parse a facet related to an entity and return a modified
    query. """
    if facet == 'project':
        facet_obj = aliased(Project)
        q = q.join(facet_obj, relation_obj.project)
        return apply_facet_obj(q, facet_obj)
    elif facet == 'schema':
        facet_obj = aliased(Schema)
        if not arg_bool('facet_%s_hidden' % full_facet, default=False):
            q = q.filter(facet_obj.hidden == False)
        q = q.join(facet_obj, relation_obj.schema)
        return apply_facet_obj(q, facet_obj)
    elif facet.startswith('properties.'):
        return apply_property_facet(q, facet, Property,
                                    relation_obj)
    elif facet.startswith('source.'):
        _, subfacet = facet.split('.', 1)
        ent_obj = aliased(Entity)
        q = q.join(ent_obj, relation_obj.source)
        return parse_entity_facets(ent_obj, full_facet, subfacet, q)
    elif facet.startswith('target.'):
        _, subfacet = facet.split('.', 1)
        ent_obj = aliased(Entity)
        q = q.join(ent_obj, relation_obj.target)
        return parse_entity_facets(ent_obj, full_facet, subfacet, q)
    else:
        raise BadRequest("Unknown facet: %s" % facet)
コード例 #4
0
ファイル: facets.py プロジェクト: j-norwood-young/grano
def parse_entity_facets(entity_obj, full_facet, facet, q):
    """ Parse a facet related to a relation object and return a
    modified query. """
    # TODO: Status facet.
    # TODO: Author facet.
    if facet == 'project':
        facet_obj = aliased(Project)
        q = q.join(facet_obj, entity_obj.project)
        return apply_facet_obj(q, facet_obj)
    elif facet == 'schema':
        facet_obj = aliased(Schema)
        if not arg_bool('facet_%s_hidden' % full_facet, default=False):
            q = q.filter(facet_obj.hidden == False)
        q = q.join(facet_obj, entity_obj.schemata)
        return apply_facet_obj(q, facet_obj)
    elif facet.startswith('properties.'):
        return apply_property_facet(q, facet, Property,
                                    entity_obj)
    elif facet.startswith('inbound.'):
        _, subfacet = facet.split('.', 1)
        rel_obj = aliased(Relation)
        q = q.join(rel_obj, entity_obj.inbound)
        return parse_relation_facets(rel_obj, full_facet, subfacet, q)
    elif facet.startswith('outbound.'):
        _, subfacet = facet.split('.', 1)
        rel_obj = aliased(Relation)
        q = q.join(rel_obj, entity_obj.outbound)
        return parse_relation_facets(rel_obj, full_facet, subfacet, q)
    else:
        raise BadRequest("Unknown facet: %s" % facet)
コード例 #5
0
ファイル: schemata_api.py プロジェクト: 4bic/grano
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))
    validate_cache(last_modified=project.updated_at)
    query = Schema.all()
    query = query.filter_by(project=project)
    pager = Pager(query, slug=slug)
    return jsonify(pager, index=not arg_bool("full"))
コード例 #6
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))
    validate_cache(last_modified=project.updated_at)
    query = Schema.all()
    query = query.filter_by(project=project)
    pager = Pager(query, slug=slug)
    return jsonify(pager, index=not arg_bool('full'))
コード例 #7
0
def _index(query, obj):
    authz.require(authz.project_read(obj.project))
    active_only = arg_bool('active', default=True)
    if active_only:
        query = query.filter_by(active=True)

    if 'name' in request.args:
        query = query.filter_by(name=request.args.get('name'))

    query = query.order_by(Property.created_at.desc())
    pager = Pager(query, obj_id=obj.id)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=False)
コード例 #8
0
def check_auth():
    api_key = request.headers.get('X-Grano-API-Key') \
        or request.args.get('api_key')
    if session.get('id'):
        request.account = Account.by_id(session.get('id'))
        if request.account is None:
            del session['id']
            raise Unauthorized()
    elif api_key is not None:
        request.account = Account.by_api_key(api_key)
        if request.account is None:
            raise Unauthorized()
        if arg_bool('api_key_cookie'):
            session['id'] = request.account.id
    else:
        request.account = None