Example #1
0
def _create_example_site(user):
    site = Site(
        name='Example Site',
        owner = user,
        users = [user],
        admins = [user],
        example = True,
    )
    site.put()

    for v in [4, 5]:
        name = 'Html%d Example' % v
        style = Style(site=site, name=name)
        style.put()
        rev = StyleRevision(parent=style, rev=0)
        rev.put()
        rev.update(render_template('examples/blog-html%d.css' % v))
        style.published_rev = rev
        rev = StyleRevision(parent=style, rev=1)
        rev.put()
        rev.update(render_template('examples/blog-html%d-preview.css' % v))
        style.preview_rev = rev
        style.put()
        page = Page(site=site, name=name, url=url_for('example%d' % v, page_key=0, _external=True), _styles=[style.key()])
        page.put()
        page.url = url_for('example%d' % v, page_key=page.key(), _external=True)
        page.put()
        page.queue_refresh()
Example #2
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 #3
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 #4
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 #5
0
                del parser

        importer.put()
        queue_import(page)
        return 'IMPORTED'
    else:
        page.import_state = IMPORT_DONE
        style = page.styles[0]
        errors = ''
        if importer.errors:
            errors = 'Errors:\n%s\n\n' % ('\n'.join(importer.errors))
        existing_rev = style.preview_rev if style.preview_rev else style.published_rev
        existing_scss = existing_rev.raw
        rev = style.preview_rev
        if not rev:
            rev = StyleRevision(parent=page.styles[0])
            rev.put()
            style.preview_rev = rev
            style.put()
        rev.raw = '%s\n\n%s/* End of imported styles */\n\n%s' % (importer.style, errors, existing_scss)
        rev.put()
        page.put()
        importer.delete()
        return 'DONE'

@tasks.route('/tasks/upload_style', methods=['GET', 'POST'])
@csrf_exempt
def upload_style():
    page_key = request.form.get('page_key', None)
    if page_key:
        page = Page.get(page_key)
Example #6
0
def fix_css_naming():
    for rev in StyleRevision.all():
        if hasattr(rev, 'css'):
            rev.update(rev.css)
Example #7
0
def _create_example_site(user):
    site = Site(
        name='Example Site',
        owner=user,
        users=[user],
        admins=[user],
        example=True,
    )
    site.put()

    for v in [4, 5]:
        name = 'Html%d Example' % v
        style = Style(site=site, name=name)
        style.put()
        rev = StyleRevision(parent=style, rev=0)
        rev.put()
        rev.update(render_template('examples/blog-html%d.css' % v))
        style.published_rev = rev
        rev = StyleRevision(parent=style, rev=1)
        rev.put()
        rev.update(render_template('examples/blog-html%d-preview.css' % v))
        style.preview_rev = rev
        style.put()
        page = Page(site=site,
                    name=name,
                    url=url_for('example%d' % v, page_key=0, _external=True),
                    _styles=[style.key()])
        page.put()
        page.url = url_for('example%d' % v,
                           page_key=page.key(),
                           _external=True)
        page.put()
        page.queue_refresh()