本文整理汇总了Python中nomenklatura.authz.require函数的典型用法代码示例。如果您正苦于以下问题:Python require函数的具体用法?Python require怎么用?Python require使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了require函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
def create():
data = request_data()
dataset = Dataset.from_form(data)
authz.require(authz.dataset_edit(dataset))
entity = Entity.create(dataset, data, request.account)
db.session.commit()
return redirect(url_for('.view', id=entity.id))
示例2: edit
def edit(dataset):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_manage(dataset))
html = render_template('dataset/edit.html',
dataset=dataset,
algorithms=get_algorithms())
return htmlfill.render(html, defaults=dataset.as_dict())
示例3: match
def match(dataset, link, random=False):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
link = Link.find(dataset, link)
random = random or request.args.get('random')=='True'
choices = match_op(link.key, dataset,
query=request.args.get('query'))
pager = Pager(choices, '.match',
dataset=dataset.name, link=link.id,
limit=10)
# HACK: Fetch only the values on the selected page.
value_objs = Value.id_map(dataset, map(lambda (c,v,s): v,
pager.query[pager.offset:pager.offset+pager.limit]))
for i, (c,v,s) in enumerate(pager.query):
if v in value_objs:
pager.query[i] = (c, value_objs.get(v), s)
html = render_template('link/match.html',
dataset=dataset, link=link, choices=pager,
random=random)
choice = 'INVALID' if link.is_invalid else link.value_id
if len(choices) and choice is None:
c, v, s = choices[0]
choice = 'INVALID' if s <= 50 else v
return htmlfill.render(html, force_defaults=False,
defaults={'choice': choice,
'value': link.key,
'query': request.args.get('query', ''),
'random': random})
示例4: match
def match(dataset, alias, random=False):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
alias = Alias.find(dataset, alias)
random = random or request.args.get('random')=='True'
choices = match_op(alias.name, dataset,
query=request.args.get('query'))
pager = Pager(choices, '.match',
dataset=dataset.name, alias=alias.id,
limit=10)
# HACK: Fetch only the entities on the selected page.
entities = Entity.id_map(dataset, map(lambda (c,e,s): e,
pager.query[pager.offset:pager.offset+pager.limit]))
for i, (c,e,s) in enumerate(pager.query):
if e in entities:
pager.query[i] = (c, entities.get(e), s)
html = render_template('alias/match.html',
dataset=dataset, alias=alias, choices=pager,
random=random)
choice = 'INVALID' if alias.is_invalid else alias.entity_id
if len(choices) and choice is None:
c, e, s = choices[0]
choice = 'INVALID' if s <= 50 else e.id
return htmlfill.render(html, force_defaults=False,
defaults={'choice': choice,
'name': alias.name,
'query': request.args.get('query', ''),
'random': random})
示例5: create
def create():
authz.require(authz.dataset_create())
data = request_content()
try:
dataset = Dataset.create(data, request.account)
db.session.commit()
return redirect(url_for('.view', dataset=dataset.name))
except Invalid, inv:
return handle_invalid(inv, new, data=data)
示例6: upload
def upload(dataset):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
file_ = request.files.get('file')
if not file_ or not file_.filename:
err = {'file': "You need to upload a file"}
raise Invalid("No file.", None, None, error_dict=err)
upload = Upload.create(dataset, request.account, file_)
db.session.commit()
return jsonify(upload)
示例7: upload
def upload(dataset):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
file_ = request.files.get('file')
if not file_ or not file_.filename:
inv = Invalid("No file.", None, None,
error_dict={'file': "You need to upload a file"})
raise inv
upload = upload_file(dataset, file_, request.account)
return redirect(url_for('.map', dataset=dataset.name, id=upload.id))
示例8: match_random
def match_random(dataset):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
aliases = Alias.all_unmatched(dataset)
count = aliases.count()
if count == 0:
return redirect(url_for('dataset.view',
dataset=dataset.name))
alias = aliases.offset(randint(0, count-1)).first()
return redirect(url_for('.match', dataset=dataset.name, alias=alias.id,
random=True))
示例9: upload
def upload(dataset):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
file_ = request.files.get('file')
if not file_ or not file_.filename:
inv = Invalid("No file.", None, None,
error_dict={'file': "You need to upload a file"})
return handle_invalid(inv, form, data={},
args=[dataset.name])
sig = upload_file(dataset, file_)
return redirect(url_for('.map', dataset=dataset.name, sig=sig))
示例10: update
def update(dataset):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_manage(dataset))
data = request_content()
try:
dataset.update(data)
db.session.commit()
flash("Updated %s" % dataset.label, "success")
return redirect(url_for(".view", dataset=dataset.name))
except Invalid, inv:
return handle_invalid(inv, edit, args=[dataset.name], data=data)
示例11: match_save
def match_save(dataset, alias):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
alias = Alias.find(dataset, alias)
random = request.form.get('random')=='True'
data = request_content()
try:
alias.match(dataset, data, request.account)
db.session.commit()
except Invalid, inv:
return handle_invalid(inv, match, data=data,
args=[dataset.name, alias.id, random])
示例12: submit
def submit(dataset, sig):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
data = request_content()
value_col = data.get('value') or None
link_col = data.get('link') or None
if not (value_col or link_col):
flash('You need to pick either a link or value column!', 'error')
return map(dataset.name, sig)
import_upload.delay(dataset.name, sig, request.account.id,
value_col, link_col)
flash('Loading data...', 'success')
return redirect(url_for('dataset.view', dataset=dataset.name))
示例13: update
def update(dataset, value):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
value = Value.find(dataset, value)
data = request_content()
try:
value.update(data, request.account)
db.session.commit()
flash("Updated %s" % value.value, 'success')
return redirect(url_for('.view', dataset=dataset.name, value=value.id))
except Invalid, inv:
return handle_invalid(inv, view, data=data,
args=[dataset.name, value.id])
示例14: submit
def submit(dataset, id):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
data = request_content()
entity_col = data.get('entity') or None
alias_col = data.get('alias') or None
if not (entity_col or alias_col):
flash('You need to pick either a alias or entity column!', 'error')
return map(dataset.name, id)
import_upload.delay(dataset.name, id, request.account.id,
entity_col, alias_col)
flash('Loading data...', 'success')
return redirect(url_for('dataset.view', dataset=dataset.name))
示例15: update
def update(dataset, entity):
dataset = Dataset.find(dataset)
authz.require(authz.dataset_edit(dataset))
entity = Entity.find(dataset, entity)
data = request_content()
try:
entity.update(data, request.account)
db.session.commit()
flash("Updated %s" % entity.display_name, 'success')
return redirect(url_for('.view', dataset=dataset.name, entity=entity.id))
except Invalid, inv:
return handle_invalid(inv, view, data=data,
args=[dataset.name, entity.id])