Exemplo n.º 1
0
def save(data):
    """ Create or update an attribute.
    CAUTION: This does not, on its own, validate any data."""

    schema = data.get('schema')
    name = data.get('name')
    obj = Attribute.by_schema_and_name(schema, name)
    if obj is None:
        obj = Attribute()
        obj.name = name
        obj.datatype = data.get('datatype')
        obj.schema = schema

    obj.label = data.get('label')
    obj.hidden = data.get('hidden')
    obj.inherited = data.get('inherited')
    obj.description = data.get('description')
    db.session.add(obj)
    return obj
Exemplo n.º 2
0
def save(data):
    """ Create or update an attribute. 
    CAUTION: This does not, on its own, validate any data."""

    schema = data.get("schema")
    name = data.get("name")
    obj = Attribute.by_schema_and_name(schema, name)
    if obj is None:
        obj = Attribute()
    obj.name = name
    obj.label = data.get("label")
    obj.hidden = data.get("hidden")
    obj.description = data.get("description")
    obj.datatype = data.get("datatype")
    obj.schema = schema
    db.session.add(obj)
    return obj
Exemplo n.º 3
0
def filter_query(cls, q, args):
    q = q.join(Project)
    q = q.outerjoin(Permission)
    q = q.filter(or_(Project.private==False,
        and_(Permission.reader==True, Permission.account==request.account)))
    
    project = args.get('project')
    if project:
        q = q.filter(Project.slug==project)
    
    for prop, value, only_active in property_filters(args):
        attributes = Attribute.all_named(prop)
        q = cls._filter_property(q, attributes, value,
                only_active=only_active)

    return q
Exemplo n.º 4
0
def property_filters(cls, q):
    """ Parse the query arguments and apply any specified property
    filters to the given query ``q``. The property-holding object
    (a relation or entity) is given as ``cls``. """
    for key in request.args.keys():
        if not key.startswith(PROPERTY):
            continue
        prop = key[len(PROPERTY):]

        only_active = True
        if prop.startswith(ALIASES):
            prop = prop[len(ALIASES):]
            only_active = False

        attributes = Attribute.all_named(prop)
        value = single_arg(key)
        q = cls._filter_property(q, attributes, value, only_active=only_active)
    return q
Exemplo n.º 5
0
def property_filters(cls, q):
    """ Parse the query arguments and apply any specified property
    filters to the given query ``q``. The property-holding object
    (a relation or entity) is given as ``cls``. """
    for key in request.args.keys():
        if not key.startswith(PROPERTY):
            continue
        prop = key[len(PROPERTY):]

        only_active = True
        if prop.startswith(ALIASES):
            prop = prop[len(ALIASES):]
            only_active = False

        attributes = Attribute.all_named(prop)
        value = single_arg(key)
        q = cls._filter_property(q, attributes, value,
                                 only_active=only_active)
    return q