Example #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)
Example #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)
Example #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
Example #4
0
File: rpc.py Project: 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
Example #5
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
Example #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'
Example #7
0
File: rpc.py Project: 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"
Example #8
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'