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, }
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, }
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)
def __get_category_list(info=None, error=None): m = { '__view__' : 'manage_category_list', 'categories' : model.get_categories(), } if info: m['info'] = info if error: m['error'] = error return m
def __get_category_list(info=None, error=None): m = { '__view__': 'manage_category_list', 'categories': model.get_categories(), } if info: m['info'] = info if error: m['error'] = error return m
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)
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)
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)
def _categories(user, app, context): btn = context.get_argument('btn', '') if btn=='add': # add category: if context.method=='get': return { '__view__' : 'manage_category_editor', 'add' : True, 'category' : model.BlogCategory(name='Unamed', description=''), } 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)
def _categories(user, app, context): btn = context.get_argument('btn', '') if btn == 'add': # add category: if context.method == 'get': return { '__view__': 'manage_category_editor', 'add': True, 'category': model.BlogCategory(name='Unamed', description=''), } 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)