本文整理汇总了Python中models.Site.get_admin_or_404方法的典型用法代码示例。如果您正苦于以下问题:Python Site.get_admin_or_404方法的具体用法?Python Site.get_admin_or_404怎么用?Python Site.get_admin_or_404使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Site
的用法示例。
在下文中一共展示了Site.get_admin_or_404方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_site
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import get_admin_or_404 [as 别名]
def edit_site(site_id):
site = Site.get_admin_or_404(site_id)
form = SiteForm(request.form, site)
if request.method == 'POST':
if form.validate():
site.name = form.name.data
site.put()
if request.is_xhr:
return 'OK'
elif request.is_xhr:
return render_template('form_errors.html', form=form)
if request.is_xhr:
return render_template('site_editor.html', form=form, site=site)
return render_template('edit_site.html', form=form, site=site)
示例2: new_page
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import get_admin_or_404 [as 别名]
def new_page(site_id):
site = Site.get_admin_or_404(site_id)
form = PageForm(request.form, site=site)
if request.method == 'POST':
if form.validate():
page = Page.new_page(site, form.name.data, form.url.data)
new_url = url_for('editor', page_id=page.key().id())
if request.is_xhr:
return jsonify(dict(type='success', redirect=new_url))
return redirect(new_url)
elif request.is_xhr:
return jsonify(dict(type='error', errors=render_template('form_errors.html', form=form)))
if request.is_xhr:
return render_template('page_creator.html', form=form, site=site)
return render_template('new_page.html', form=form, site=site)
示例3: remove_user
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import get_admin_or_404 [as 别名]
def remove_user(site_id):
site = Site.get_admin_or_404(site_id)
admin = users.get_current_user()
user_id = request.form.get('user_id', None)
if not user_id or admin.user_id() == user_id:
abort(400)
remove_admin_only = request.form.get('remove_admin_only', False)
them = [u for u in site.users if u.user_id() == user_id]
for user in them:
if not remove_admin_only:
site.users.remove(user)
if user in site.admins:
site.admins.remove(user)
site.put()
return 'OK'
示例4: invite
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import get_admin_or_404 [as 别名]
def invite(site_id):
user = users.get_current_user()
site = Site.get_admin_or_404(site_id)
form = InviteForm(request.form)
if form.validate():
invite_hash = sha1()
invite_hash.update(str(site.key()))
invite_hash.update(os.urandom(8))
invite_hash.update(form.email.data)
invite_hash = b32encode(invite_hash.digest()).lower()
invite = Invitation(
hash=invite_hash,
email=form.email.data,
site=site,
admin=form.admin.data,
inviter=user
)
invite.put()
mail.send_mail(
sender = settings.invite_sender_email,
to = invite.email,
subject = '%s invited you to join them on %s' % (user.email(), settings.appname),
body = render_template('invite_email.txt', invite=invite),
html = render_template('invite_email.html', invite=invite),
)
if request.is_xhr:
return 'OK'
flash('Invitation Sent!', 'success')
else:
errors = sum(form.errors.values(), [])
if request.is_xhr:
return ', '.join(errors)
for error in errors:
flash(error, 'error')
flash(form.email.data, 'error')
return redirect(url_for('edit_siteusers', site_id=site_id))
示例5: delete_site
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import get_admin_or_404 [as 别名]
def delete_site():
site_id = int(request.form.get('site_id', -1))
site = Site.get_admin_or_404(site_id)
site.delete()
return 'OK'
示例6: edit_siteusers
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import get_admin_or_404 [as 别名]
def edit_siteusers(site_id):
site = Site.get_admin_or_404(site_id)
invite_form = InviteForm()
if request.is_xhr:
return render_template('siteusers_editor.html', site=site, invite_form=invite_form)
return render_template('edit_siteusers.html', site=site, invite_form=invite_form)