def post_edit(request): """ View: Form for editing of blog post. """ post = request.context blog = post.blog if request.POST: # got post data, let's try to save: post.date = request.POST.getone('date') post.title = request.POST.getone('title') post.slug = slugify(request.POST.getone('slug')) post.content = request.POST.getone('content') if post.slug == u'': post.slug = slugify(post.title) post.published = (request.POST.get('published', 'not') == u'published') post.set_item_tags_by_string(request.POST.getone('tags')) post.set_item_categories_by_string(request.POST.getone('cats')) DBSession.flush() raise HTTPFound(request.resource_url(post)) return { 'Title':u'Edit post: %s' % post.title, 'blog':blog, 'post':post, 'published_checked':u'checked' if post.published else u'', }
def view_post(request): post = request.context blog = post.blog if request.POST: if request.POST.get('.post_comment'): title = request.POST.getone('title') content = request.POST.getone('content') comment = Comment(main_item=post, direct_item=post) comment.title = title comment.content = content comment.poster_ip = request.remote_addr comment.depth = 1 if request.user is None: comment.poster_name = request.POST.getone('name') comment.poster_email = request.POST.getone('email') else: comment.creator = request.user comment.owner = request.user DBSession.add(comment) DBSession.flush() raise HTTPFound(request.resource_path(post)) return { 'blog':blog, 'post':post, }
def post_delete(request): """ View: Delete a post from blog. """ post = request.context blog = post.blog if request.POST and request.POST.has_key('.delete'): DBSession.delete(post) DBSession.flush() raise HTTPFound(request.resource_url(blog)) return { 'Title':u'Delete post: %s' % post.title, 'post':post, 'blog':blog, }
def post_form(request): """View: Form for posting a new post in blog. """ blog = request.context title = u'' slug = u'' content = u'' date = datetime.date.today() published = False tags = u'' cats = u'' if request.POST: # got post data, let's try to save: post = Post(blog=blog) post.date = request.POST.get('date', datetime.date.today()) post.title = request.POST.getone('title') post.slug = slugify(request.POST.getone('slug')) post.content = request.POST.getone('content') post.creator = request.user post.set_item_tags_by_string(request.POST.getone('tags')) post.set_item_categories_by_string(request.POST.getone('cats')) if post.slug == u'': post.slug = slugify(post.title) post.published = (request.POST.get('published', 'not') == u'published') DBSession.flush() # return Response('a') raise HTTPFound(request.resource_url(blog)) return { 'Title':u'Create new post', 'blog':blog, 'title':title, 'slug':slug, 'content':content, 'date':date, 'tags':tags, 'cats':cats, 'published_checked':u'checked' if published else u'', }