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)
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 _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(self, id): """View single post""" if session.login > 0: post = model.get_post(int(id), session.login) return render.view(post) else: raise web.seeother('/')
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)
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)
def get_page(key): ''' Show a single page. Args: key: page key as string. ''' page = model.get_post(key, True) if page is None: raise NotFoundError() return { '__theme__': True, '__view__': 'page', '__title__': page.title, 'page': page, }
def get_page(key): ''' Show a single page. Args: key: page key as string. ''' page = model.get_post(key, True) if page is None: raise NotFoundError() return { '__theme__' : True, '__view__' : 'page', '__title__' : page.title, 'page' : page, }
def get_post(key): ''' Show a single published post. Args: key: post key as string. ''' post = model.get_post(key) if post is None: raise NotFoundError() return { '__theme__': True, '__view__': 'post', '__title__': post.title, 'post': post, 'comments': store.get_all_comments(post.id), }
def get_post(key): ''' Show a single published post. Args: key: post key as string. ''' post = model.get_post(key) if post is None: raise NotFoundError() return { '__theme__' : True, '__view__' : 'post', '__title__' : post.title, 'post' : post, 'comments' : store.get_all_comments(post.id), }
def test_get_post(self, get_db_mock): mock_db = get_db_mock() id = 1 result = model.get_post(id) self.assertTrue(mock_db.select.called)