本文整理汇总了Python中comport.department.models.Department.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Department.get_by_id方法的具体用法?Python Department.get_by_id怎么用?Python Department.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comport.department.models.Department
的用法示例。
在下文中一共展示了Department.get_by_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_extractor
# 需要导入模块: from comport.department.models import Department [as 别名]
# 或者: from comport.department.models.Department import get_by_id [as 别名]
def edit_extractor(extractor_id):
extractor = Extractor.get_by_id(extractor_id)
if not extractor:
abort(404)
form = EditExtractorForm(request.form, departments=[d.id for d in extractor.departments])
form.departments.choices = [(d.id, d.name) for d in Department.query.order_by('name')]
if request.method == 'POST':
extractor.departments = [Department.get_by_id(int(d)) for d in form.departments.data]
extractor.save()
flash('Extractor updated.', 'info')
return redirect(url_for('admin.admin_dashboard'))
return render_template("admin/editExtractor.html", form=form, extractor=extractor)
示例2: edit_user
# 需要导入模块: from comport.department.models import Department [as 别名]
# 或者: from comport.department.models.Department import get_by_id [as 别名]
def edit_user(user_id):
user = User.get_by_id(user_id)
if not user:
abort(404)
form = EditUserForm(request.form, departments=[d.id for d in user.departments])
form.departments.choices = [(d.id, d.name) for d in Department.query.order_by('name')]
if request.method == 'POST':
user.departments = [Department.get_by_id(int(d)) for d in form.departments.data]
user.save()
flash('User updated.', 'info')
return redirect(url_for('admin.admin_dashboard'))
return render_template("admin/editUser.html", form=form, user=user)
示例3: register
# 需要导入模块: from comport.department.models import Department [as 别名]
# 或者: from comport.department.models.Department import get_by_id [as 别名]
def register():
form = RegisterForm(request.form, csrf_enabled=False)
if form.validate_on_submit():
invite_code = Invite_Code.query.filter_by(code=form.invite_code.data).first()
invite_code.used = True
invite_code.save()
new_user = User.create(
username=form.username.data,
email=form.email.data,
password=form.password.data,
active=True
)
new_user.departments.append(Department.get_by_id(invite_code.department_id))
flash("Thank you for registering. You can now log in.", 'success')
return redirect(url_for('public.home'))
else:
flash_errors(form)
return render_template('public/register.html', form=form)