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


Python Entity.all方法代码示例

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


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

示例1: setUp

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
 def setUp(self):
     self.app = make_test_app()
     Entity.all().delete()
     # Consistently include an extra private project with Entity
     # that should not show in any test results
     project, permission = _project_and_permission(private=True)
     entity = Entity(project=project, status=authz.PUBLISHED_THRESHOLD)
     db.session.add(entity)
开发者ID:01-,项目名称:grano,代码行数:10,代码来源:test_filters.py

示例2: rebuild

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
def rebuild():
    """ Execute the change processing handlers for all entities and
    relations currently loaded. This can be used as a housekeeping
    function. """

    for project in Project.all():
        _project_changed(project.slug, 'delete')
        _project_changed(project.slug, 'create')

        for schema in project.schemata:
            _schema_changed(schema.project.slug, schema.name, 'delete')
            _schema_changed(schema.project.slug, schema.name, 'create')

        eq = Entity.all().filter_by(same_as=None)
        eq = eq.filter_by(project=project)
        for i, entity in enumerate(eq):
            if i > 0 and i % 1000 == 0:
                log.info("Rebuilt: %s entities", i)
            _entity_changed(entity.id, 'delete')
            _entity_changed(entity.id, 'create')

        rq = Relation.all().filter_by(project=project)
        for i, relation in enumerate(rq):
            if i > 0 and i % 1000 == 0:
                log.info("Rebuilt: %s relation", i)
            _relation_changed(relation.id, 'delete')
            _relation_changed(relation.id, 'create')
开发者ID:01-,项目名称:grano,代码行数:29,代码来源:plugins.py

示例3: save

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
    def save(self):
        """ Save the entity to the database. Do this only once, after all
        properties have been set. """

        # fetch existing:
        q = Entity.all()
        q = q.filter(Entity.project==self.loader.project)
        for name, only_active in self.update_criteria:
            value = self.properties.get(name).get('value')
            attr = self.loader.project.get_attribute('entity', name)
            q = Entity._filter_property(q, [attr], value,
                only_active=only_active)

        entity = q.first()

        try:
            data = {
                'project': self.loader.project,
                'author': self.loader.account,
                'schemata': self.schemata,
                'properties': self.properties
            }
            self._entity = entities.save(data, entity=entity)

        except Invalid, inv:
            log.warning("Validation error: %r", inv)
开发者ID:nimblemachine,项目名称:grano,代码行数:28,代码来源:loader.py

示例4: index

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
def index():
    query = filter_query(Entity, Entity.all(), request.args)

    for schema in request.args.getlist('schema'):
        alias = aliased(Schema)
        query = query.join(alias, Entity.schemata)
        query = query.filter(alias.name.in_(schema.split(',')))

    pager = Pager(query)
    conv = lambda es: [entities.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
开发者ID:nimblemachine,项目名称:grano,代码行数:13,代码来源:entities_api.py

示例5: export_aliases

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
def export_aliases(project, path):
    """ Dump a list of all entity names to a CSV file. The table will contain the 
    active name of each entity, and one of the other existing names as an alias. """
    with open(path, 'w') as fh:
        writer = DictWriter(fh, ['entity_id', 'alias', 'canonical', 'schemata'])
        writer.writeheader()
        q = Entity.all().filter_by(same_as=None)
        q = q.filter(Entity.project==project)
        for i, entity in enumerate(q):
            export_entity(entity, writer)
            if i % 100 == 0:
                log.info("Dumped %s entity names...", i)
开发者ID:eocaollai,项目名称:grano,代码行数:14,代码来源:aliases.py

示例6: index_project

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
    def index_project(self, project=None):
        """ Index an entire project, or the entire database if no
        project is given. """
        q = Entity.all().filter_by(same_as=None)
        if project is not None:
            q = q.filter(Entity.project == project)

        for i, entity in enumerate(q):
            self.index_entity(entity)
            if i > 0 and i % 1000 == 0:
                log.info("Indexed: %s entities", i)
                es.indices.refresh(index=es_index)
        es.indices.refresh(index=es_index)
开发者ID:c0ns0le,项目名称:grano-elasticsearch,代码行数:15,代码来源:indexer.py

示例7: rebuild

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
def rebuild():
    """ Execute the change processing handlers for all entities and
    relations currently loaded. This can be used as a housekeeping
    function. """

    for i, entity in enumerate(Entity.all().filter_by(same_as=None)):
        if i > 0 and i % 1000 == 0:
            log.info("Rebuilt: %s entities", i)
        _entity_changed(entity.id)

    for i, relation in enumerate(Relation.all()):
        if i > 0 and i % 1000 == 0:
            log.info("Rebuilt: %s relation", i)
        _relation_changed(relation.id)
开发者ID:jacqui,项目名称:grano,代码行数:16,代码来源:plugins.py

示例8: index_entities

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
def index_entities():
    """ Re-build an index for all enitites from scratch. """
    for i, entity in enumerate(Entity.all().filter_by(same_as=None)):
        body = entities.to_index(entity)
        
        if 'name' not in body.get('properties', {}):
            log.warn('No name: %s, skipping!', entity.id)
            #pprint(body)
            continue
    
        es.index(index=es_index, doc_type='entity', id=body.pop('id'), body=body)
        if i > 0 and i % 1000 == 0:
            log.info("Indexed: %s entities", i)
            es.indices.refresh(index=es_index)
        
    es.indices.refresh(index=es_index)
开发者ID:nimblemachine,项目名称:grano,代码行数:18,代码来源:indexer.py

示例9: generate_sitemap

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
def generate_sitemap(count=40000):
    """ Generate a static sitemap.xml for the most central entities in the 
    database. """

    PATTERN = app.config.get('ENTITY_VIEW_PATTERN')
    
    entities = []
    for i, entity in enumerate(Entity.all().yield_per(5000)):
        dt = entity.updated_at.strftime('%Y-%m-%d')
        entities.append((PATTERN % entity.id, dt, entity.degree))
        if i > 0 and i % 1000 == 0:
            log.info("Loaded %s entities...", i)

    upper = max([e[2] for e in entities])
    entities = sorted(entities, key=lambda e: e[2], reverse=True)[:count]
    entities = [(i, d, '%.2f' % max(0.3, ((float(s)**0.3)/upper))) for (i,d,s) in entities]

    xml = render_template('sitemap.xml', entities=entities)
    with open(os.path.join(app.static_folder, 'sitemap.xml'), 'w') as fh:
        fh.write(xml)
开发者ID:eocaollai,项目名称:grano,代码行数:22,代码来源:sitemap.py

示例10: index

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
def index():
    query = filter_query(Entity, Entity.all(), request.args)

    if 'q' in request.args and len(request.args.get('q').strip()):
        q = '%%%s%%' % request.args.get('q').strip()
        query = query.join(EntityProperty)
        query = query.filter(EntityProperty.name=='name')
        query = query.filter(EntityProperty.value_string.ilike(q))

    for schema in request.args.getlist('schema'):
        if not len(schema.strip()):
            continue
        alias = aliased(Schema)
        query = query.join(alias, Entity.schemata)
        query = query.filter(alias.name.in_(schema.split(',')))

    query = query.filter(Entity.same_as==None)
    query = query.distinct()
    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
开发者ID:clkao,项目名称:grano,代码行数:23,代码来源:entities_api.py

示例11: save

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import all [as 别名]
    def save(self):
        """ Save the entity to the database. Do this only once, after all
        properties have been set. """
        # fetch existing:
        q = Entity.all()
        q = q.filter(Entity.project == self.loader.project)
        for name, only_active in self.update_criteria:
            v = self.properties.get(name).get('value')
            q = Entity._filter_property(q, name, v, only_active=only_active)
        entity = q.first()

        try:
            data = {
                'project': self.loader.project,
                'author': self.loader.account,
                'schema': self.schema,
                'properties': self.properties
            }
            self._entity = entities.save(data, entity=entity)

        except Invalid, inv:
            if not self.loader.ignore_errors:
                raise
            log.warning("Validation error: %r", inv.asdict())
开发者ID:01-,项目名称:grano,代码行数:26,代码来源:loader.py


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