当前位置: 首页>>代码示例>>Python>>正文


Python Schema.by_name方法代码示例

本文整理汇总了Python中grano.model.Schema.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.by_name方法的具体用法?Python Schema.by_name怎么用?Python Schema.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grano.model.Schema的用法示例。


在下文中一共展示了Schema.by_name方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decode

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
 def decode(self, node, cstruct):
     if isinstance(cstruct, Schema):
         return cstruct
     if isinstance(cstruct, basestring):
         return Schema.by_name(self.project, cstruct)
     if isinstance(cstruct, dict):
         if cstruct.get('name'):
             return Schema.by_name(self.project,
                 cstruct.get('name'))
     return None
开发者ID:ahurriyetoglu,项目名称:grano,代码行数:12,代码来源:references.py

示例2: apply_alias

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def apply_alias(project, author, canonical_name, alias_name):
    """ Given two names, find out if there are existing entities for one or 
    both of them. If so, merge them into a single entity - or, if only the 
    entity associated with the alias exists - re-name the entity. """

    canonical_name = canonical_name.strip()

    # Don't import meaningless aliases.
    if canonical_name == alias_name or not len(canonical_name):
        return log.info("No alias: %s", canonical_name)

    canonical = Entity.by_name(project, canonical_name)
    alias = Entity.by_name(project, alias_name)
    schema = Schema.by_name(project, 'base')

    # Don't artificially increase entity counts.
    if canonical is None and alias is None:
        return log.info("Neither alias nor canonical exist: %s", canonical_name)

    # Rename an alias to its new, canonical name.
    if canonical is None:
        properties_logic.set(alias, author, 'name', schema, canonical_name,
            active=True, source_url=None)
        _entity_changed.delay(alias.id)
        return log.info("Renamed: %s", alias_name)

    # Already done, thanks.
    if canonical == alias:
        return log.info("Already aliased: %s", canonical_name)

    # Merge two existing entities, declare one as "same_as"
    if canonical is not None and alias is not None:
        _merge_entities(alias, canonical)
        _entity_changed.delay(canonical.id)
        return log.info("Mapped: %s -> %s", alias.id, canonical.id)
开发者ID:eocaollai,项目名称:grano,代码行数:37,代码来源:entities.py

示例3: delete

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def delete(slug, name):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    schema = object_or_404(Schema.by_name(project, name))
    schemata.delete(schema)
    db.session.commit()
    raise Gone()
开发者ID:ahurriyetoglu,项目名称:grano,代码行数:9,代码来源:schemata_api.py

示例4: view

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def view(slug, name):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))
    if not project.private:
        validate_cache(last_modified=project.updated_at)
    schema = object_or_404(Schema.by_name(project, name))
    return jsonify(schema)
开发者ID:ahurriyetoglu,项目名称:grano,代码行数:9,代码来源:schemata_api.py

示例5: update

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def update(slug, name):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    schema = object_or_404(Schema.by_name(project, name))
    data = request_data({'project': project})
    schema = schemata.save(data, schema=schema)
    db.session.commit()
    return jsonify(schema)
开发者ID:ahurriyetoglu,项目名称:grano,代码行数:10,代码来源:schemata_api.py

示例6: facet_schema_list

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def facet_schema_list(obj, facets):
    results = []
    project = Project.by_slug('openinterests')
    for facet in facets:
        schema = Schema.by_name(project, facet.get('term'))
        if schema is not None and not schema.hidden:
            results.append((schema, facet.get('count')))
    return results
开发者ID:IuliiSe,项目名称:openinterests.eu,代码行数:10,代码来源:util.py

示例7: delete

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def delete(slug, name):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    schema = object_or_404(Schema.by_name(project, name))
    deleted = schemata.delete(schema)
    db.session.commit()
    if deleted:
        raise Gone()
    else:
        return jsonify(schema)
开发者ID:4bic,项目名称:grano,代码行数:12,代码来源:schemata_api.py

示例8: import_schema

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def import_schema(project, fh):
    data = yaml.load(fh.read())
    if isinstance(data, dict):
        data = [data]
    try:
        for cur in data:
            schema = Schema.by_name(project, cur.get('name'))
            cur['project'] = project
            save(cur, schema=schema)
        db.session.commit()
    except Invalid, inv:
        pprint(inv.asdict())
开发者ID:gabelula,项目名称:grano,代码行数:14,代码来源:schemata.py

示例9: save

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def save(data, schema=None):
    """ Create a schema. """
    data = validate(data)

    operation = 'create' if schema is None else 'update'
    if schema is None:
        schema = Schema()
        schema.name = data.get('name')
        schema.project = data.get('project')

    schema.label = data.get('label')
    schema.obj = data.get('obj')
    schema.hidden = data.get('hidden')
    schema.meta = data.get('meta')
    schema.parent = data.get('parent')

    if schema.name in DEFAULTS.values():
        schema.parent = None
    elif schema.parent is None or schema.is_circular():
        schema.parent = Schema.by_name(schema.project,
                                       DEFAULTS.get(schema.obj))

    schema.project.updated_at = datetime.utcnow()
    db.session.add(schema)

    inherited = [a.name for a in schema.inherited_attributes]
    names = []

    for attribute in data.get('attributes', []):
        if attribute.get('name') in inherited:
            continue
        attribute['schema'] = schema
        attr = attributes.save(attribute)
        schema.local_attributes.append(attr)
        names.append(attr.name)
    
    for attr in schema.local_attributes:
        if attr.name not in names:
            attributes.delete(attr)

    db.session.flush()
    _schema_changed(schema.project.slug, schema.name, operation)
    return schema
开发者ID:01-,项目名称:grano,代码行数:45,代码来源:schemata.py

示例10: apply_alias

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def apply_alias(project, author, canonical_name, alias_name, source_url=None):
    """ Given two names, find out if there are existing entities for one or
    both of them. If so, merge them into a single entity - or, if only the
    entity associated with the alias exists - re-name the entity. """

    # Don't import meaningless aliases.
    if not len(canonical_name) or not len(alias_name):
        return log.info("Not an alias: %s", canonical_name)

    canonical = None

    # de-duplicate existing entities with the same name.
    known_names = set()
    for existing in Entity.by_name_many(project, canonical_name):

        for prop in existing.properties:
            if prop.name != 'name':
                continue
            known_names.add(prop.value)

            # make sure the canonical name is actually active
            # TODO: is this desirable?
            if prop.value == canonical_name:
                prop.active = True
            else:
                prop.active = False

        if canonical is not None and canonical.id != existing.id:
            canonical = merge(existing, canonical)
        else:
            canonical = existing

    schema = Schema.by_name(project, 'base')
    attribute = schema.get_attribute('name')

    # Find aliases, i.e. entities with the alias name which are not
    # the canonical entity.
    q = Entity.by_name_many(project, alias_name)
    if canonical is not None:
        q = q.filter(Entity.id != canonical.id)
    aliases = q.all()

    # If there are no existing aliases with that name, add the alias
    # name to the canonical entity.
    if not len(aliases) and canonical is not None:
        if alias_name not in known_names:
            data = {
                'value': alias_name,
                'schema': schema,
                'attribute': attribute,
                'active': False,
                'name': 'name',
                'source_url': source_url
            }
            properties_logic.save(canonical, data)
            _entity_changed.delay(canonical.id, 'update')
        log.info("Alias: %s -> %s", alias_name, canonical_name)

    for alias in aliases:
        if canonical is None:
            # Rename an alias to its new, canonical name.
            data = {
                'value': canonical_name,
                'schema': schema,
                'attribute': attribute,
                'active': True,
                'name': 'name',
                'source_url': source_url
            }
            properties_logic.save(alias, data)
            _entity_changed.delay(alias.id, 'update')
            log.info("Renamed: %s -> %s", alias_name, canonical_name)
        else:
            # Merge two existing entities, declare one as "same_as"
            merge(alias, canonical)
            log.info("Mapped: %s -> %s", alias.id, canonical.id)

    db.session.commit()
开发者ID:scott2b,项目名称:grano,代码行数:80,代码来源:entities.py

示例11: view

# 需要导入模块: from grano.model import Schema [as 别名]
# 或者: from grano.model.Schema import by_name [as 别名]
def view(slug, name):
    project = object_or_404(Project.by_slug(slug))
    validate_cache(last_modified=project.updated_at)
    schema = object_or_404(Schema.by_name(project, name))
    return jsonify(schemata.to_rest(schema))
开发者ID:eocaollai,项目名称:grano,代码行数:7,代码来源:schemata_api.py


注:本文中的grano.model.Schema.by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。