當前位置: 首頁>>代碼示例>>Python>>正文


Python Site.get_admin_or_404方法代碼示例

本文整理匯總了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)
開發者ID:1ncnspcuous,項目名稱:WebPutty,代碼行數:16,代碼來源:views.py

示例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)
開發者ID:1ncnspcuous,項目名稱:WebPutty,代碼行數:17,代碼來源:views.py

示例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'
開發者ID:1ncnspcuous,項目名稱:WebPutty,代碼行數:17,代碼來源:views.py

示例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))
開發者ID:1ncnspcuous,項目名稱:WebPutty,代碼行數:38,代碼來源:views.py

示例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'
開發者ID:1ncnspcuous,項目名稱:WebPutty,代碼行數:7,代碼來源:views.py

示例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)
開發者ID:1ncnspcuous,項目名稱:WebPutty,代碼行數:8,代碼來源:views.py


注:本文中的models.Site.get_admin_or_404方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。