def blog_category_create(request): user_id = authenticated_userid(request) category = Category() form = BlogCategoryCreateForm(request.POST) if request.method == 'POST' and form.validate(): form.populate_obj(category) category.slug = urlify(category.name) DBSession.add(category) return HTTPFound(location=request.route_url('blog')) return {'user_id': user_id, 'action': 'create', 'form': form, }
def blog_category(request): user_id = authenticated_userid(request) page = int(request.params.get('page', 1)) category_slug = request.matchdict.get('category', 1) paginator = Category.get_paginator(request, page=page, category_slug=category_slug) recent = Post.get_recent() posts= Post.all() years = Post.get_years_desc() categories = Category.get_all() tags = Tag.get_all() return {'paginator': paginator, 'user_id': user_id, 'recent': recent, 'posts': posts, 'years': years, 'categories': categories, 'tags': tags, }
def blog_category_edit(request): user_id = authenticated_userid(request) category_id = int(request.params.get('id', 1)) category = Category.by_id(category_id) if not category: return HTTPNotFound() form = BlogCategoryUpdateForm(request.POST, category) if request.method == 'POST' and form.validate(): form.populate_obj() DBSession.add(category) return HTTPFound(location=request.route_url('blog')) return {'user_id': user_id, 'action': 'edit', 'form': form, }
def blog_details(request): user_id = authenticated_userid(request) post_id = int(request.matchdict.get('id', 1)) blog_post = Post.by_id(post_id) if not blog_post: return HTTPNotFound() recent = Post.get_recent() posts= Post.all() years = Post.get_years_desc() categories = Category.get_all() tags = Tag.get_all() return {'blog_post': blog_post, 'user_id': user_id, 'recent': recent, 'posts': posts, 'post': blog_post, 'years': years, 'categories': categories, 'tags': tags, }