Exemplo n.º 1
0
def api_update_page(pid):
    page = Pages.get_by_id(pid)
    if page is None:
        raise notfound()
    i = ctx.request.input()
    update = False
    if 'name' in i:
        page.name = assert_not_empty(i.name, 'name')
        update = True
    if 'tags' in i:
        page.tags = texts.format_tags(i.tags)
        update = True
    if 'draft' in i:
        draft = i.draft.lower() == 'true'
        if draft != page.draft:
            page.draft = draft
            update = True
    if 'content' in i:
        content = assert_not_empty(i.content, 'content')
        page.content = content
        update = True

    if hasattr(page, 'content'):
        page.content_id = texts.set(page._id, page.content)
    if update:
        page.update()
    return dict(_id=page._id)
Exemplo n.º 2
0
def edit_page():
    page = Pages.get_by_id(ctx.request['_id'])
    if page is None:
        raise notfound()
    return dict( \
        form_title = 'Edit Page', \
        form_action = '/api/pages/%s/update' % page._id, \
        _id = page._id, \
        alias = page.alias, \
        name = page.name, \
        tags = page.tags, \
        draft = page.draft, \
        content = texts.get(page.content_id))
Exemplo n.º 3
0
def api_delete_page(pid):
    p = Pages.get_by_id(pid)
    if p is None:
        raise notfound()
    p.delete()
    return dict(result=True)