예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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
예제 #4
0
파일: rpc.py 프로젝트: tghw/WebPutty
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
예제 #5
0
파일: rpc.py 프로젝트: 1ncnspcuous/WebPutty
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
예제 #6
0
def _channel_presence(presence):
    client_id = request.form.get('from', '')
    channel = PageChannel.get_or_404(client_id=client_id)
    page = channel.page
    if presence == 'connected':
        page.add_channel(channel)
    elif presence == 'disconnected':
        page.remove_channel(channel, True)
    page.update_locks()
    return 'OK'
예제 #7
0
파일: rpc.py 프로젝트: tghw/WebPutty
def _channel_presence(presence):
    client_id = request.form.get("from", "")
    channel = PageChannel.get_or_404(client_id=client_id)
    page = channel.page
    if presence == "connected":
        page.add_channel(channel)
    elif presence == "disconnected":
        page.remove_channel(channel, True)
    page.update_locks()
    return "OK"
예제 #8
0
파일: rpc.py 프로젝트: 1ncnspcuous/WebPutty
def _channel_presence(presence):
    client_id = request.form.get('from', '')
    channel = PageChannel.get_or_404(client_id=client_id)
    page = channel.page
    if presence == 'connected':
        page.add_channel(channel)
    elif presence == 'disconnected':
        page.remove_channel(channel, True)
    page.update_locks()
    return 'OK'