def render_post(post, with_comments=False, recommend_by=None, template='jabber/post.txt'): post.comments_count = post.comments.count() post.post_tags = post.tags.all() context = {} context['post'] = post context['recommend_by'] = recommend_by if with_comments: context['comments'] = reversed(BlogInterface.paginate( post.comments.filter().select_related('user').order_by('-number'), per_page=100)) return render_to_string(template, context)
#users = Profile.attach_user_info(User.objects.filter(username=username)) #user = username and get_object_or_404(users, username=username) user = None if username: try: user = UserInterface(request.user).get_user_info(username=username) except InterfaceError, error: raise Http404(error) try: page = int(page) except ValueError: return redirect('.') blog_interface = BlogInterface(request.user) posts = blog_interface.get_posts(username=user, tag_name=tagname) paginate = Paginator(posts, PER_PAGE) try: page = paginate.page(page) except (EmptyPage, InvalidPage): page = paginate.page(paginate.num_pages) posts = page.object_list posts = posts.select_related_tag() context = {} context['user_blog'] = user context['posts'] = posts