def search(request): query = get_query(request) page = get_page(request) qd = request.GET.copy() if 'page' in qd: qd.pop('page') posts = None if query: if 'search' in request.COOKIES: message = 'You are searching too often. Slow down.' return render_to_response('post/error.html', {'message': message} ) qset = ( Q(title__icontains=query) | Q(content__icontains=query) ) posts = Post.objects.filter(qset, status='publish').distinct().order_by('-date') title = 'Search results for: %s' % query response = render_to_response('search.html', { 'query': query, 'posts': posts, 'page': page, 'pagi_path': qd.urlencode(), 'title': title, }, RequestContext(request)) response.set_cookie('search',request.META['REMOTE_ADDR'], max_age=1) return response
def comment_list(request): page = get_page(request) comments = Comment.objects.in_public() return render_to_response('comment/comment_list.html', { 'comments': comments, 'page': page, 'current': 'comments', }, context_instance = RequestContext(request))
def index(request): page = get_page(request) posts = Post.objects.get_post() return render_to_response('post/post_list.html', { 'posts': posts, 'page': page, }, context_instance=RequestContext(request) )
def tag_view(request, name): tag = get_object_or_404(Tag, name=name) posts = TaggedItem.objects.get_by_model(Post, tag).order_by('-date') page = get_page(request) title = 'Tag archives for: %s' % tag return render_to_response('tag/tag.html', { 'tag': tag, 'posts': posts, 'page': page, 'pagi_path': request.path, 'title': title, }, context_instance = RequestContext(request))
def archive_view(request, year, month): posts = Post.objects.get_post_by_date(year, month) page = get_page(request) title = 'Monthly Archives: %s-%s' % (year, month) return render_to_response('post/archive.html', { 'year': year, 'month': month, 'posts': posts, 'path': request.path, 'page': page, 'title': title, }, context_instance=RequestContext(request) )
def category_view(request, slug): cat = get_object_or_404(Category, slug=slug) posts = Post.objects.get_post_by_category(cat) page = get_page(request) title = 'Category Archives: %s' % cat.title return render_to_response('post/archive.html', { 'category': cat, 'posts': posts, 'path': request.path, 'page': page, 'title': title, }, context_instance=RequestContext(request) )