本文整理汇总了Python中grano.model.Schema类的典型用法代码示例。如果您正苦于以下问题:Python Schema类的具体用法?Python Schema怎么用?Python Schema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_fixtures
def make_fixtures(self):
self.app.post('/api/1/networks',
headers=AUTHZ_HEADER,
data=NETWORK_FIXTURE)
network = Network.by_slug(NETWORK_FIXTURE['slug'])
Schema.create(network, Schema.RELATION,
h.TEST_RELATION_SCHEMA)
Schema.create(network, Schema.ENTITY,
h.TEST_ENTITY_SCHEMA)
res = self.app.post('/api/1/net/entities',
headers=AUTHZ_HEADER,
data=ENTITY1_FIXTURE,
follow_redirects=True)
body = json.loads(res.data)
self.source_id = body['id']
res = self.app.post('/api/1/net/entities',
headers=AUTHZ_HEADER,
data=ENTITY2_FIXTURE,
follow_redirects=True)
body = json.loads(res.data)
self.target_id = body['id']
RELATION_FIXTURE['source'] = self.source_id
RELATION_FIXTURE['target'] = self.target_id
res = self.app.post('/api/1/net/relations',
headers=AUTHZ_HEADER,
data=RELATION_FIXTURE,
follow_redirects=True)
print res.data
body = json.loads(res.data)
self.id = body['id']
示例2: setUp
def setUp(self):
self.client = h.make_test_app()
self.network = Network.create({'title': 'Net', 'slug': 'net'})
self.schema = Schema.create(self.network, Schema.ENTITY,
h.TEST_ENTITY_SCHEMA)
self.rschema = Schema.create(self.network, Schema.RELATION,
h.TEST_RELATION_SCHEMA)
db.session.commit()
self.context = ValidationContext(network=self.network)
示例3: decode
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
示例4: setUp
def setUp(self):
self.app = make_test_app()
self.app.post('/api/1/networks',
headers=AUTHZ_HEADER,
data=NETWORK_FIXTURE)
network = Network.by_slug(NETWORK_FIXTURE['slug'])
Schema.create(network, Schema.RELATION,
h.TEST_RELATION_SCHEMA)
Schema.create(network, Schema.ENTITY,
h.TEST_ENTITY_SCHEMA)
db.session.commit()
示例5: save
def save(data, schema=None):
""" Create a schema. """
schema_val = SchemaValidator(validator=check_attributes)
data = schema_val.deserialize(data)
if schema is None:
schema = Schema()
schema.name = data.get('name')
schema.project = data.get('project')
schema.label = data.get('label')
schema.label_in = data.get('label_in') or schema.label
schema.label_out = data.get('label_out') or schema.label
schema.obj = data.get('obj')
schema.hidden = data.get('hidden')
schema.project.updated_at = datetime.utcnow()
db.session.add(schema)
names = []
for attribute in data.get('attributes', []):
attribute['schema'] = schema
attr = attributes.save(attribute)
schema.attributes.append(attr)
names.append(attr.name)
for attr in schema.attributes:
if attr.name not in names:
attributes.delete(attr)
return schema
示例6: view
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)
示例7: delete
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()
示例8: make_fixtures
def make_fixtures(self):
self.app.post('/api/1/networks',
headers=AUTHZ_HEADER,
data=NETWORK_FIXTURE)
network = Network.by_slug(NETWORK_FIXTURE['slug'])
Schema.create(network, Schema.RELATION,
h.TEST_RELATION_SCHEMA)
Schema.create(network, Schema.ENTITY,
h.TEST_ENTITY_SCHEMA)
db.session.commit()
res = self.app.post('/api/1/net/entities',
headers=AUTHZ_HEADER,
data=ENTITY_FIXTURE,
follow_redirects=True)
body = json.loads(res.data)
self.id = body['id']
示例9: apply_alias
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)
示例10: facet_schema_list
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
示例11: index
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"))
示例12: update
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)
示例13: index
def index(slug):
project = object_or_404(Project.by_slug(slug))
validate_cache(last_modified=project.updated_at)
query = Schema.all()
query = query.filter_by(project=project)
pager = Pager(query)
conv = lambda es: [schemata.to_rest_index(e) for e in es]
return jsonify(pager.to_dict(conv))
示例14: delete
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)
示例15: setUp
def setUp(self):
self.client = h.make_test_app()
self.network = Network.create({'title': 'Net', 'slug': 'net'})
self.schema = Schema.create(self.network, Schema.RELATION,
h.TEST_RELATION_SCHEMA)
db.session.commit()
self.eschema = Schema.create(self.network, Schema.ENTITY,
h.TEST_ENTITY_SCHEMA)
self.context = ValidationContext(network=self.network)
entity = deepcopy(TEST_ENTITY)
entity['network'] = self.network.slug
entity = validate_entity(entity, self.eschema, self.context)
entity['title'] = 'Alice'
a = self.network.Entity.create(self.eschema, entity)
entity['title'] = 'Bob'
b = self.network.Entity.create(self.eschema, entity)
TEST_RELATION['source'] = a.id
TEST_RELATION['target'] = b.id
db.session.commit()