本文整理汇总了Python中grano.model.Project.by_slug方法的典型用法代码示例。如果您正苦于以下问题:Python Project.by_slug方法的具体用法?Python Project.by_slug怎么用?Python Project.by_slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grano.model.Project
的用法示例。
在下文中一共展示了Project.by_slug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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: es_index
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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)
示例3: schema_import
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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)
示例4: update
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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)
示例5: delete
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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()
示例6: suggest_type
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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
})
示例7: create
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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)
示例8: suggest_property
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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
})
示例9: reconcile
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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)
示例10: view
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [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)
示例11: delete
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [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()
示例12: create
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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)
示例13: suggest_property
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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}
)
示例14: index
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [as 别名]
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"))
示例15: facet_schema_list
# 需要导入模块: from grano.model import Project [as 别名]
# 或者: from grano.model.Project import by_slug [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