当前位置: 首页>>代码示例>>Python>>正文


Python Page.get_edit_or_404方法代码示例

本文整理汇总了Python中models.Page.get_edit_or_404方法的典型用法代码示例。如果您正苦于以下问题:Python Page.get_edit_or_404方法的具体用法?Python Page.get_edit_or_404怎么用?Python Page.get_edit_or_404使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Page的用法示例。


在下文中一共展示了Page.get_edit_or_404方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: editor

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def editor(page_id):
    page = Page.get_edit_or_404(page_id)
    user = users.get_current_user()
    client_id = 'page-%d-%s-%s' % (page_id, user.user_id(), b32encode(os.urandom(10)))
    token = gae_channels.create_channel(client_id)
    channel = PageChannel(user=user, page=page, token=token, client_id=client_id)
    channel.put()
    return render_template('editor.html', page=page, channel_token=token)
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:10,代码来源:views.py

示例2: page_rpc

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_rpc(page_id):
    page = Page.get_edit_or_404(page_id)
    try:
        message = json.loads(request.form.get("message", ""))
    except Exception:
        abort(400)
    data = message.get("data", None)
    token = message.get("from", None)
    if not token or not data:
        logging.warn("RPC received no token or data.")
        abort(400)
    cmd = data.get("cmd", None)
    if not cmd:
        logging.warn("RPC received no cmd.")
        abort(400)

    channel = PageChannel.gql("WHERE token=:1", token).get()
    if not channel:
        # We've timed out the channel. User should refresh the page.
        logging.debug("Could not find token: %s", token)
        return dict(cmd="refresh")
    channel.dt_last_update = datetime.utcnow()
    channel.put()

    # Commands
    if cmd == "open":
        page.add_channel(channel)
        page.update_locks()
        return "OK"
    elif cmd == "claimLock":
        page.clean_channels()
        page.add_channel_first(channel)
        page.update_locks()
        return "OK"
    elif cmd == "save":
        style_id = data.get("style_id", "")
        style = Style.get_edit_or_404(style_id)
        if not style.preview_rev:
            preview_rev = StyleRevision(parent=style, rev=style.published_rev.rev + 1)
            preview_rev.put()
            style.preview_rev = preview_rev
            style.put()
        log = style.preview_rev.update(data.get("scss", ""))
        publish = data.get("fPublish", False)
        preview = not publish
        if publish:
            style.published_rev = style.preview_rev
            style.preview_rev = None
            style.put()
            page_key = str(page.key())
            memcache.delete(page_key + "-css")
            memcache.delete(page_key + "-css-etag")
            page.queue_refresh()
        return jsonify({"css": page.compressed_css(preview), "log": log})
    else:
        logging.warn("Got a bad command: %s", cmd)
        abort(400)  # Bad cmd
开发者ID:tghw,项目名称:WebPutty,代码行数:59,代码来源:rpc.py

示例3: page_rpc

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_rpc(page_id):
    page = Page.get_edit_or_404(page_id)
    try:
        message = json.loads(request.form.get('message', ''))
    except Exception:
        abort(400)
    data = message.get('data', None)
    token = message.get('from', None)
    if not token or not data:
        logging.warn('RPC received no token or data.')
        abort(400)
    cmd = data.get('cmd', None)
    if not cmd:
        logging.warn('RPC received no cmd.')
        abort(400)

    channel = PageChannel.gql('WHERE token=:1', token).get()
    if not channel:
        # We've timed out the channel. User should refresh the page.
        logging.debug('Could not find token: %s', token)
        return dict(cmd='refresh')
    channel.dt_last_update = datetime.utcnow()
    channel.put()

    # Commands
    if cmd == 'open':
        page.add_channel(channel)
        page.update_locks()
        return 'OK'
    elif cmd == 'claimLock':
        page.clean_channels()
        page.add_channel_first(channel)
        page.update_locks()
        return 'OK'
    elif cmd == 'save':
        style_id = data.get('style_id', '')
        style = Style.get_edit_or_404(style_id)
        if not style.preview_rev:
            preview_rev = StyleRevision(parent=style, rev=style.published_rev.rev + 1)
            preview_rev.put()
            style.preview_rev = preview_rev
            style.put()
        log = style.preview_rev.update(data.get('scss', ''))
        publish = data.get('fPublish', False)
        preview = not publish
        if publish:
            style.published_rev = style.preview_rev
            style.preview_rev = None
            style.put()
            page_key = str(page.key())
            memcache.delete(page_key + '-css')
            memcache.delete(page_key + '-css-etag')
            page.queue_refresh()
        return jsonify({'css': page.compressed_css(preview), 'log': log})
    else:
        logging.warn('Got a bad command: %s', cmd)
        abort(400) # Bad cmd
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:59,代码来源:rpc.py

示例4: page_import

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_import(page_id):
    page = Page.get_edit_or_404(page_id)
    if request.method == 'POST':
        if 'fOk' in request.form:
            queue_import(page, first_time=True)
            return redirect(url_for('page_import', page_id=page_id))
        else:
            return redirect(url_for('editor', page_id=page_id))
    else:
        if page.import_state == IMPORT_DONE:
            page.import_state = CAN_IMPORT
            page.put()
            return redirect(url_for('editor', page_id=page_id))
        return render_template('page_import.html', page=page)
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:16,代码来源:views.py

示例5: page_styles

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_styles(page_id):
    page = Page.get_edit_or_404(page_id)
    return Response(page.styles_json(), content_type='application/json')
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:5,代码来源:views.py

示例6: page_preview

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_edit_or_404 [as 别名]
def page_preview(page_id):
    page = Page.get_edit_or_404(page_id)
    if page.preview_img:
        return _send_file(page.preview_img, 'image/png')
    else:
        return redirect('/static/img/loading-preview.png')
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:8,代码来源:views.py


注:本文中的models.Page.get_edit_or_404方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。