Пример #1
0
def blog(request):
    user_id = authenticated_userid(request)
    page = int(request.params.get('page', 1))
    paginator = Post.get_paginator(request, page)
    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,
            }
Пример #2
0
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,
            }
Пример #3
0
def blog_edit(request):
    user_id = authenticated_userid(request)
    post_id = int(request.params.get('id', 1))
    
    blog_post = Post.by_id(post_id)
    if not blog_post:
        return HTTPNotFound()
    form = BlogUpdateForm(request.POST, blog_post)
    if request.method == 'POST' and form.validate():
        form.populate_obj(blog_post)
        tags = request.params['tags']
        update_tags(tags, blog_post)

        return HTTPFound(location=request.route_url('blog_details',
                                                    id=blog_post.id,
                                                    slug=blog_post.slug))

    tag_list = (', ').join(blog_post.get_tags())
    return {'form': form, 'action': 'edit',
            'user_id': user_id, 
            'tags': tag_list}