def _create_post(num, ref_user, title_prefix, tag, category, func_state=lambda x: model.POST_PUBLISHED): ' create number of posts ' for i in range(num-1, -1, -1): model.create_post( ref_user, func_state(i), '%s-%d' % (title_prefix, i,), 'just a test. no. %d' % i, category, tag, True ) time.sleep(0.01)
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 create_post(): post = model.create_post(request.form) if post: if post.as_draft: return redirect(url_for('drafts')) else: return redirect(url_for('slug', slug=post.slug)) else: # todo: error message return redirect(url_for('new_post'))
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)