本文整理汇总了Python中grano.model.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode
def decode(self, node, cstruct):
if isinstance(cstruct, Project):
return cstruct
if isinstance(cstruct, basestring):
return Project.by_slug(cstruct)
if isinstance(cstruct, dict):
if cstruct.get('slug'):
return Project.by_slug(cstruct.get('slug'))
return None
示例2: delete
def delete(slug, id):
project = object_or_404(Project.by_slug(slug))
authz.require(authz.project_manage(project))
permission = object_or_404(Permission.by_project_and_id(project, id))
permissions.delete(permission)
db.session.commit()
raise Gone()
示例3: 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()
示例4: suggest_property
def suggest_property(slug):
project = object_or_404(Project.by_slug(slug))
authz.require(authz.project_read(project))
prefix = '%%%s%%' % request.args.get('prefix', '')
q = db.session.query(Attribute)
q = q.join(Schema)
q = q.filter(Schema.obj=='entity')
q = q.filter(Schema.project==project)
q = q.filter(or_(Attribute.label.ilike(prefix), Attribute.name.ilike(prefix)))
q = q.limit(get_limit(default=5))
matches = []
for attribute in q:
matches.append({
'name': attribute.label,
'n:type': {
'id': '/properties/property',
'name': 'Property'
},
'id': attribute.name
})
return jsonify({
"code" : "/api/status/ok",
"status" : "200 OK",
"prefix" : request.args.get('prefix', ''),
"result" : matches
})
示例5: suggest_type
def suggest_type(slug):
project = object_or_404(Project.by_slug(slug))
authz.require(authz.project_read(project))
prefix = '%%%s%%' % request.args.get('prefix', '')
log.info("Suggesting types in %s: %r", project.slug, prefix)
q = db.session.query(Schema)
q = q.filter(Schema.obj == 'entity')
q = q.filter(Schema.hidden == False) # noqa
q = q.filter(Schema.project == project)
q = q.filter(or_(Schema.label.ilike(prefix), Schema.name.ilike(prefix)))
q = q.limit(get_limit(default=5))
matches = []
for schema in q:
matches.append({
'name': schema.label,
'id': '/%s/%s' % (slug, schema.name)
})
return jsonify({
"code": "/api/status/ok",
"status": "200 OK",
"prefix": request.args.get('prefix', ''),
"result": matches
})
示例6: es_index
def es_index(project=None):
""" Re-index all entities in the system, or those in a project. """
if project is not None:
project = Project.by_slug(project)
if project is None:
raise ValueError("Project not found.")
script_indexer.index_project(project=project)
示例7: 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)
示例8: schema_import
def schema_import(project, path):
""" Load a schema specification from a YAML file. """
pobj = Project.by_slug(project)
if pobj is None:
pobj = save_project({"slug": project, "label": project, "author": console_account()})
with open(path, "r") as fh:
import_schema(pobj, fh)
示例9: suggest_property
def suggest_property(slug):
project = object_or_404(Project.by_slug(slug))
authz.require(authz.project_read(project))
prefix = "%%%s%%" % request.args.get("prefix", "")
log.info("Suggesting property names in %s: %r", project.slug, prefix)
q = db.session.query(Attribute)
q = q.join(Schema)
q = q.filter(Schema.obj == "entity")
q = q.filter(Schema.project == project)
q = q.filter(or_(Attribute.label.ilike(prefix), Attribute.name.ilike(prefix)))
q = q.limit(get_limit(default=5))
matches = []
for attribute in q:
matches.append(
{
"name": attribute.label,
"n:type": {"id": "/properties/property", "name": "Property"},
"id": attribute.name,
}
)
return jsonify(
{"code": "/api/status/ok", "status": "200 OK", "prefix": request.args.get("prefix", ""), "result": matches}
)
示例10: create
def create(slug):
project = object_or_404(Project.by_slug(slug))
authz.require(authz.project_manage(project))
data = request_data({'project': project})
permission = permissions.save(data)
db.session.commit()
return jsonify(permission, status=201)
示例11: rebuild
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')
示例12: update
def update(slug):
project = object_or_404(Project.by_slug(slug))
authz.require(authz.project_manage(project))
data = request_data({'author': request.account})
project = projects.save(data, project=project)
db.session.commit()
return jsonify(project)
示例13: create
def create(slug):
project = object_or_404(Project.by_slug(slug))
authz.require(authz.project_manage(project))
data = request_data({"project": project})
schema = schemata.save(data)
db.session.commit()
return jsonify(schema, status=201)
示例14: reconcile
def reconcile(slug):
"""
Reconciliation API, emulates Google Refine API. See:
http://code.google.com/p/google-refine/wiki/ReconciliationServiceApi
"""
project = object_or_404(Project.by_slug(slug))
authz.require(authz.project_read(project))
# TODO: Add proper support for types and namespacing.
data = request.args.copy()
data.update(request.form.copy())
if 'query' in data:
# single
q = data.get('query')
if q.startswith('{'):
try:
q = json.loads(q)
except ValueError:
raise BadRequest()
else:
q = data
return jsonify(reconcile_op(project, q))
elif 'queries' in data:
# multiple requests in one query
qs = data.get('queries')
try:
qs = json.loads(qs)
except ValueError:
raise BadRequest()
queries = {}
for k, q in qs.items():
queries[k] = reconcile_op(project, q)
return jsonify(queries)
else:
return reconcile_index(project)
示例15: 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"))