コード例 #1
0
ファイル: appmanage.py プロジェクト: cng1985/express-me
def __get_post_list(user, context):
    category = None
    cat = context.get_argument('category', '')
    if cat:
        category = model.get_category(cat)
    offset = context.get_argument('offset', '')
    if not offset:
        offset = None
    index = 1
    if offset:
        index = int(context.get_argument('index'))
    categories = model.get_categories()
    ref = None
    if user.role >= store.ROLE_AUTHOR:
        ref = user.id
    ps, next_cursor = model.get_posts(5, offset, ref, category, published_only=False)
    return {
            '__view__' : 'manage_post_list',
            'static' : False,
            'ps' : ps,
            'category' : cat,
            'categories' : categories,
            'offset' : offset,
            'next' : next_cursor,
            'index' : index,
    }
コード例 #2
0
ファイル: appmanage.py プロジェクト: bopopescu/express-me-1
def __get_post_list(user, context):
    category = None
    cat = context.get_argument('category', '')
    if cat:
        category = model.get_category(cat)
    offset = context.get_argument('offset', '')
    if not offset:
        offset = None
    index = 1
    if offset:
        index = int(context.get_argument('index'))
    categories = model.get_categories()
    ref = None
    if user.role >= store.ROLE_AUTHOR:
        ref = user.id
    ps, next_cursor = model.get_posts(5,
                                      offset,
                                      ref,
                                      category,
                                      published_only=False)
    return {
        '__view__': 'manage_post_list',
        'static': False,
        'ps': ps,
        'category': cat,
        'categories': categories,
        'offset': offset,
        'next': next_cursor,
        'index': index,
    }
コード例 #3
0
ファイル: appmanage.py プロジェクト: bopopescu/express-me-1
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)
コード例 #4
0
ファイル: appmanage.py プロジェクト: cng1985/express-me
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)
コード例 #5
0
ファイル: appmanage.py プロジェクト: cng1985/express-me
def _add_post(user, app, context):
    if context.method=='get':
        return {
                '__view__' : 'manage_editor',
                'post' : __empty_post(user, False),
                'categories' : model.get_categories(),
        }
    if context.method=='post':
        title = context.get_argument('title')
        content = context.get_argument('content')
        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.create_post(user, state, title, content, model.get_category(category), tags, allow_comment)
        return __json_result(True, p)
コード例 #6
0
ファイル: appmanage.py プロジェクト: bopopescu/express-me-1
def _add_post(user, app, context):
    if context.method == 'get':
        return {
            '__view__': 'manage_editor',
            'post': __empty_post(user, False),
            'categories': model.get_categories(),
        }
    if context.method == 'post':
        title = context.get_argument('title')
        content = context.get_argument('content')
        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.create_post(user, state, title, content,
                              model.get_category(category), tags,
                              allow_comment)
        return __json_result(True, p)
コード例 #7
0
def get_posts_by_category(cat_key, **kw):
    ctx = kw['context']
    category = model.get_category(cat_key)
    number = 20
    offset = ctx.get_argument('offset', '')
    if not offset:
        offset = None
    index = ctx.get_argument('index', '')
    if index:
        index = int(index)
    else:
        index = 1
    posts, next = model.get_posts(number, offset, category=category)
    return {
        '__theme__': True,
        '__view__': 'posts',
        '__title__': 'Posts of %s' % category.name,
        '__header__': blog.get_feed_html(),
        'category': category,
        'posts': posts,
        'index': index,
        'next': next,
        'offset': offset,
    }
コード例 #8
0
ファイル: controller.py プロジェクト: cng1985/express-me
def get_posts_by_category(cat_key, **kw):
    ctx = kw['context']
    category = model.get_category(cat_key)
    number = 20
    offset = ctx.get_argument('offset', '')
    if not offset:
        offset = None
    index = ctx.get_argument('index', '')
    if index:
        index = int(index)
    else:
        index = 1
    posts, next = model.get_posts(number, offset, category=category)
    return {
            '__theme__' : True,
            '__view__' : 'posts',
            '__title__' : 'Posts of %s' % category.name,
            '__header__' : blog.get_feed_html(),
            'category' : category,
            'posts' : posts,
            'index' : index,
            'next' : next,
            'offset' : offset,
    }
コード例 #9
0
ファイル: appmanage.py プロジェクト: cng1985/express-me
        name = context.get_argument('name')
        description = context.get_argument('description', '')
        model.create_category(name, description)
        return __get_category_list('Category "%s" created.' % name)

    if btn=='delete':
        if len(model.get_categories())==1:
            return __get_category_list(error='You cannot delete the only 1 category.')
        try:
            model.delete_category(context.get_argument('id'))
        except ApplicationError, e:
            return __get_category_list(error=e.message)

    if btn=='edit':
        id = context.get_argument('id')
        category = model.get_category(id)
        if context.method=='get':
            return {
                    '__view__' : 'manage_category_editor',
                    'add' : False,
                    'category' : category,
            }
        name = context.get_argument('name')
        description = context.get_argument('description', '')
        category.name = name
        category.description = description
        category.put()
        return __get_category_list('Category "%s" updated.' % name)

    return __get_category_list()
コード例 #10
0
ファイル: model_test.py プロジェクト: bopopescu/express-me-1
 def test_create_post(self):
     user = _create_user()
     p = model.create_post(user, model.POST_PUBLISHED, 'test post', 'test content', model.get_category(), 'aa,bb,cc', True)
     self.assertEquals(user.id, p.ref)
     self.assertEquals(user.nicename, p.author)
     p2 = model.get_post(p.id)
     self.assertEquals(user.id, p2.ref)
     self.assertEquals(user.nicename, p2.author)
コード例 #11
0
ファイル: appmanage.py プロジェクト: bopopescu/express-me-1
        description = context.get_argument('description', '')
        model.create_category(name, description)
        return __get_category_list('Category "%s" created.' % name)

    if btn == 'delete':
        if len(model.get_categories()) == 1:
            return __get_category_list(
                error='You cannot delete the only 1 category.')
        try:
            model.delete_category(context.get_argument('id'))
        except ApplicationError, e:
            return __get_category_list(error=e.message)

    if btn == 'edit':
        id = context.get_argument('id')
        category = model.get_category(id)
        if context.method == 'get':
            return {
                '__view__': 'manage_category_editor',
                'add': False,
                'category': category,
            }
        name = context.get_argument('name')
        description = context.get_argument('description', '')
        category.name = name
        category.description = description
        category.put()
        return __get_category_list('Category "%s" updated.' % name)

    return __get_category_list()