Exemple #1
1
def _edit_page(user, app, context):
    if context.method=='get':
        btn = context.get_argument('btn', '')
        if btn=='edit':
            p =  model.get_post(context.get_argument('id'), static=True, published_only=False)
            return {
                    '__view__' : 'manage_editor',
                    'post' : p,
            }
        return __get_page_list(context)

    if context.method=='post':
        btn = context.get_argument('btn', '')
        id = context.get_argument('id', '')
        ok = False
        if btn=='edit':
            p = model.get_post(id, True, False)
            if p:
                title = context.get_argument('title')
                content = context.get_argument('content')
                draft = context.get_argument('draft')=='True'
                allow_comment = context.get_argument('allow_comment')=='True'
                state = model.POST_PUBLISHED
                if draft:
                    state = model.POST_DRAFT
                p = model.update_page(id, user, state, title, content, allow_comment)
                return __json_result(False, p)
        elif btn=='publish':
            ok = model.publish_post(id, static=True)
        elif btn=='unpublish':
            ok = model.unpublish_post(id, static=True)
        elif btn=='delete':
            ok = model.delete_post(id, static=True)
        elif btn=='perm_delete':
            ok = model.delete_post(id, static=True, permanent=True)
        elif btn=='undelete':
            ok = model.undelete_post(id, static=True)
        if not ok:
            logging.warning('Operation failed: %s, id=%s' % (btn, id,))
        return __get_page_list(context)
Exemple #2
0
def _edit_post(user, app, context):
    if context.method == 'get':
        btn = context.get_argument('btn', '')
        if btn == 'edit':
            p = model.get_post(context.get_argument('id'),
                               published_only=False)
            if user.role >= store.ROLE_AUTHOR and p.ref != user.id:
                raise ApplicationError('Permission denied.')
            return {
                '__view__': 'manage_editor',
                'post': p,
                'categories': model.get_categories(),
            }
        return __get_post_list(user, context)

    if context.method == 'post':
        btn = context.get_argument('btn', '')
        id = context.get_argument('id', '')
        ok = False
        if btn == 'edit' and user.role >= store.ROLE_AUTHOR:
            p = model.get_post(id, False, False)
            if p and p.ref == user.id:
                title = context.get_argument('title')
                content = context.get_argument('content')
                category = model.get_category(context.get_argument('category'))
                tags = context.get_argument('tags')
                draft = context.get_argument('draft') == 'True'
                allow_comment = context.get_argument('allow_comment') == 'True'
                state = model.POST_PUBLISHED
                if draft:
                    state = model.POST_DRAFT
                p = model.update_post(id, user, state, title, content,
                                      category, tags, allow_comment)
                return __json_result(False, p)
        elif btn == 'publish' and user.role >= store.ROLE_AUTHOR:
            p = model.get_post(id, False, False)
            if p and p.ref == user.id:
                ok = model.pending_post(id)
        elif btn == 'publish' and user.role <= store.ROLE_EDITOR:
            ok = model.publish_post(id)
        elif btn == 'unpublish' and user.role <= store.ROLE_EDITOR:
            ok = model.unpublish_post(id)
        elif btn == 'approve' and user.role <= store.ROLE_EDITOR:
            ok = model.approve_post(id)
        elif btn == 'delete' and user.role <= store.ROLE_EDITOR:
            ok = model.delete_post(id)
        elif btn == 'perm_delete' and user.role <= store.ROLE_EDITOR:
            ok = model.delete_post(id, permanent=True)
        elif btn == 'undelete' and user.role <= store.ROLE_EDITOR:
            ok = model.undelete_post(id)
        if not ok:
            logging.warning('Operation failed: %s, id=%s' % (
                btn,
                id,
            ))
        return __get_post_list(user, context)
Exemple #3
0
def _edit_post(user, app, context):
    if context.method=='get':
        btn = context.get_argument('btn', '')
        if btn=='edit':
            p =  model.get_post(context.get_argument('id'), published_only=False)
            if user.role >= store.ROLE_AUTHOR and p.ref != user.id:
                raise ApplicationError('Permission denied.')
            return {
                    '__view__' : 'manage_editor',
                    'post' : p,
                    'categories' : model.get_categories(),
            }
        return __get_post_list(user, context)

    if context.method=='post':
        btn = context.get_argument('btn', '')
        id = context.get_argument('id', '')
        ok = False
        if btn=='edit' and user.role >= store.ROLE_AUTHOR:
            p = model.get_post(id, False, False)
            if p and p.ref==user.id:
                title = context.get_argument('title')
                content = context.get_argument('content')
                category = model.get_category(context.get_argument('category'))
                tags = context.get_argument('tags')
                draft = context.get_argument('draft')=='True'
                allow_comment = context.get_argument('allow_comment')=='True'
                state = model.POST_PUBLISHED
                if draft:
                    state = model.POST_DRAFT
                p = model.update_post(id, user, state, title, content, category, tags, allow_comment)
                return __json_result(False, p)
        elif btn=='publish' and user.role >= store.ROLE_AUTHOR:
            p = model.get_post(id, False, False)
            if p and p.ref==user.id:
                ok = model.pending_post(id)
        elif btn=='publish' and user.role <= store.ROLE_EDITOR:
            ok = model.publish_post(id)
        elif btn=='unpublish' and user.role <= store.ROLE_EDITOR:
            ok = model.unpublish_post(id)
        elif btn=='approve' and user.role <= store.ROLE_EDITOR:
            ok = model.approve_post(id)
        elif btn=='delete' and user.role <= store.ROLE_EDITOR:
            ok = model.delete_post(id)
        elif btn=='perm_delete' and user.role <= store.ROLE_EDITOR:
            ok = model.delete_post(id, permanent=True)
        elif btn=='undelete' and user.role <= store.ROLE_EDITOR:
            ok = model.undelete_post(id)
        if not ok:
            logging.warning('Operation failed: %s, id=%s' % (btn, id,))
        return __get_post_list(user, context)
Exemple #4
0
def _edit_page(user, app, context):
    if context.method == 'get':
        btn = context.get_argument('btn', '')
        if btn == 'edit':
            p = model.get_post(context.get_argument('id'),
                               static=True,
                               published_only=False)
            return {
                '__view__': 'manage_editor',
                'post': p,
            }
        return __get_page_list(context)

    if context.method == 'post':
        btn = context.get_argument('btn', '')
        id = context.get_argument('id', '')
        ok = False
        if btn == 'edit':
            p = model.get_post(id, True, False)
            if p:
                title = context.get_argument('title')
                content = context.get_argument('content')
                draft = context.get_argument('draft') == 'True'
                allow_comment = context.get_argument('allow_comment') == 'True'
                state = model.POST_PUBLISHED
                if draft:
                    state = model.POST_DRAFT
                p = model.update_page(id, user, state, title, content,
                                      allow_comment)
                return __json_result(False, p)
        elif btn == 'publish':
            ok = model.publish_post(id, static=True)
        elif btn == 'unpublish':
            ok = model.unpublish_post(id, static=True)
        elif btn == 'delete':
            ok = model.delete_post(id, static=True)
        elif btn == 'perm_delete':
            ok = model.delete_post(id, static=True, permanent=True)
        elif btn == 'undelete':
            ok = model.undelete_post(id, static=True)
        if not ok:
            logging.warning('Operation failed: %s, id=%s' % (
                btn,
                id,
            ))
        return __get_page_list(context)
Exemple #5
0
def remove(key):
	model.delete_post(key)
	return redirect(url_for('index'))