本文整理汇总了Python中app.utils.module.ModuleAPI类的典型用法代码示例。如果您正苦于以下问题:Python ModuleAPI类的具体用法?Python ModuleAPI怎么用?Python ModuleAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModuleAPI类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_api_get_users
def group_api_get_users(group_id):
if not (ModuleAPI.can_read("group")):
return abort(403)
group = Group.query.get(group_id)
users = group.users.order_by(User.first_name, User.last_name).all()
res = [{"val": user.id, "label": user.name} for user in users]
return jsonify(users=res)
示例2: view
def view(page_nr=1):
if not (ModuleAPI.can_read("group")):
return abort(403)
form = ViewGroupForm(request.form)
pagination = Group.query.order_by(Group.name).paginate(page_nr, 15, False)
if form.validate_on_submit():
if form.delete_group.data:
if ModuleAPI.can_write("group"):
group_ids = []
for group, form_entry in zip(pagination.items, form.entries):
if form_entry.select.data:
group_ids.append(group.id)
groups = Group.query.filter(Group.id.in_(group_ids)).all()
for group in groups:
db.session.delete(group)
db.session.commit()
if len(groups) > 1:
flash("The selected groups have been deleted.", "success")
else:
flash("The selected group has been deleted.", "success")
return redirect(url_for("group.view"))
else:
flash("This incident has been reported to our authorities.", "warning")
else:
for group in pagination.items:
form.entries.append_entry()
flash_form_errors(form)
return render_template(
"group/view.htm",
form=form,
pagination=pagination,
groups=zip(pagination.items, form.entries),
current_user=current_user,
title="Groups",
)