Beispiel #1
0
def edit():
    # retrieve the page if it exists
    page = db.page(request.args(0,0,int),created_by=auth.user.id) \
        or redirect(URL('index'))   
    if cannot('edit','page',page):
        redirect(URL('no_edit_permission'))
    save_mode = request.env.request_method=='POST' and request.vars.body
    if save_mode:
        if not session.cdict: session.cdict={}
        naked_body = re.sub(THISAPP,'://THIS/',request.vars.body)
        tanned_body = autolinks.expand_html(naked_body,session.cdict)
        full_html = inject_body(page.full_html, tanned_body)
        full_html = inject_title(full_html, page.title)
        body_text = extract_text(naked_body)
        page.update_record(body=naked_body,
                           body_text=body_text,
                           full_html=full_html)
        return ''
    # inject corners 
    editablebody = URL('static','js/editablebody.js',vars=dict(
            body='true' if page.owner==auth.user.id and request.vars.body else 'false',
            home_url=URL('index'),
            back_url=URL('read',args=(page.id,IS_SLUG.urlify(page.title))),
            save_url=URL('edit',args=page.id)))
    data = page.full_html
    if page.body: data = inject_body(data, page.body)
    data = inject_script(data,editablebody)
    drawers = URL('static','js/drawers.js',vars=dict(
            left_url=URL('docs',args=page.id),left_label='Docs',
            right_url=URL('tags',args=page.id),right_label='Tags'))
    data = inject_script(data,drawers)
    # fix all links, the app may have moved
    data = data.replace('@{page.theme}',
                        URL('static','themes',args=page.theme))
    return data
Beispiel #2
0
def index():
    if request.env.request_method=='POST':
        session.body_saved = request.now
        session.body = request.vars.body
        return
    if session.body and (request.now-session.body_saved).seconds>60:
        session.body = None
    path = os.path.join(request.folder,'views','default','index.html')
    data = response.render(open(path,'rb'))
    if session.body:
        new_body = session.body
        if not request.vars.edit: 
            if not session.cdict: session.cdict={}
            new_body = autolinks.expand_html(new_body,session.cdict)
        data = inject_body(data, new_body)

    editablebody = URL('static','js/editablebody.js',vars=dict(
            home_url=URL('index'),
            edit_url='' if request.vars.edit else URL('index',vars=dict(edit='true')),
            back_url=URL('index'),
            save_url=URL('index')))
    data = inject_script(data,editablebody)
    drawers = URL('static','js/drawers.js',vars=dict(
            left_url=URL('docs') if auth.user \
                else URL('static','demo/docs.html'),
            left_label='Docs'))
    share = URL('static','js/share.js',vars=dict(
            static=URL('static','images')))
    if not request.vars.edit:
        data = inject_script(data,MATHJAX)
    data = inject_script(data,drawers)
    data = inject_script(data,share)
    return data
Beispiel #3
0
def edit():
    # retrieve the page if it exists
    page = db.page(request.args(0,0,int),created_by=auth.user.id) \
        or redirect(URL('index'))
    if cannot('edit', 'page', page):
        redirect(URL('no_edit_permission'))
    save_mode = request.env.request_method == 'POST' and request.vars.body
    if save_mode:
        if not session.cdict: session.cdict = {}
        naked_body = re.sub(THISAPP, '://THIS/', request.vars.body)
        tanned_body = autolinks.expand_html(naked_body, session.cdict)
        full_html = inject_body(page.full_html, tanned_body)
        full_html = inject_title(full_html, page.title)
        body_text = extract_text(naked_body)
        page.update_record(body=naked_body,
                           body_text=body_text,
                           full_html=full_html)
        return ''
    # inject corners
    editablebody = URL(
        'static',
        'js/editablebody.js',
        vars=dict(body='true' if page.owner == auth.user.id
                  and request.vars.body else 'false',
                  home_url=URL('index'),
                  back_url=URL('read',
                               args=(page.id, IS_SLUG.urlify(page.title))),
                  save_url=URL('edit', args=page.id)))
    data = page.full_html
    if page.body: data = inject_body(data, page.body)
    data = inject_script(data, editablebody)
    drawers = URL('static',
                  'js/drawers.js',
                  vars=dict(left_url=URL('docs', args=page.id),
                            left_label='Docs',
                            right_url=URL('tags', args=page.id),
                            right_label='Tags'))
    data = inject_script(data, drawers)
    # fix all links, the app may have moved
    data = data.replace('@{page.theme}',
                        URL('static', 'themes', args=page.theme))
    return data
Beispiel #4
0
def index():
    if request.env.request_method == 'POST':
        session.body_saved = request.now
        session.body = request.vars.body
        return
    if session.body and (request.now - session.body_saved).seconds > 60:
        session.body = None
    path = os.path.join(request.folder, 'views', 'default', 'index.html')
    data = response.render(open(path, 'rb'))
    if session.body:
        new_body = session.body
        if not request.vars.edit:
            if not session.cdict: session.cdict = {}
            new_body = autolinks.expand_html(new_body, session.cdict)
        data = inject_body(data, new_body)

    editablebody = URL('static',
                       'js/editablebody.js',
                       vars=dict(home_url=URL('index'),
                                 edit_url='' if request.vars.edit else URL(
                                     'index', vars=dict(edit='true')),
                                 back_url=URL('index'),
                                 save_url=URL('index')))
    data = inject_script(data, editablebody)
    drawers = URL('static','js/drawers.js',vars=dict(
            left_url=URL('docs') if auth.user \
                else URL('static','demo/docs.html'),
            left_label='Docs'))
    share = URL('static',
                'js/share.js',
                vars=dict(static=URL('static', 'images')))
    if not request.vars.edit:
        data = inject_script(data, MATHJAX)
    data = inject_script(data, drawers)
    data = inject_script(data, share)
    return data