Exemple #1
0
def blog_detail(request, blog_pk):
    # blog = get_object_or_404(Blog, pk=blog_pk)
    # read_cookie_key = read_statistic_once_read(request, blog)
    # blog_content_type = ContentType.objects.get_for_model(blog)
    # comments = Comment.objects.filter(content_type=blog_content_type, object_id=blog.pk, parent=None)
    #
    # context = {}
    # context['previous_blog'] = Blog.objects.filter(created_time__gt=blog.created_time).last()
    # context['next_blog'] = Blog.objects.filter(created_time__lt=blog.created_time).first()
    # context['blog'] = blog
    # context['comments'] = comments.order_by('-comment_time')
    # context['comment_form'] = CommentForm(initial={'content_type': blog_content_type.model, 'object_id': blog_pk, 'reply_comment_id': 0})
    # response = render(request, 'blog/blog_detail.html', context)  # 响应
    # response.set_cookie(read_cookie_key, 'true')  # 阅读cookie标记
    # return response

    blog = get_object_or_404(Blog, pk=blog_pk)
    read_cookie_key = read_statistic_once_read(request, blog)

    context = {}
    context['previous_blog'] = Blog.objects.filter(
        created_time__gt=blog.created_time).last()
    context['next_blog'] = Blog.objects.filter(
        created_time__lt=blog.created_time).first()
    context['blog'] = blog
    response = render(request, 'blog/blog_detail.html', context)  # 响应
    response.set_cookie(read_cookie_key, 'true')  # 阅读cookie标记
    return response
Exemple #2
0
def blog_detail(request, blog_pk): #導入 blog_pk 變數
    blog = get_object_or_404(Blog, pk=blog_pk)  #獲取blog_pk
    read_cookie_key = read_statistic_once_read(request, blog) #使用閱讀計數
    
    context={}
    context['previous_blog'] = Blog.objects.filter(created_time__gt=blog.created_time).last()
    context['next_blog'] = Blog.objects.filter(created_time__lt=blog.created_time).first()
    context['blog'] = blog
    response = render(request, 'blog/blog_detail.html', context) #將字典返回到'blog_detail.html'
    response.set_cookie(read_cookie_key, 'true') #閱讀cookie
    return response
Exemple #3
0
    def get(self, request, blog_pk):
        blog = get_object_or_404(Blog, pk=blog_pk)
        read_cookie_key = read_statistic_once_read(request, blog)

        context = {}
        context['previous_blog'] = Blog.objects.filter(
            created_time__lt=blog.created_time).first()
        context['next_blog'] = Blog.objects.filter(
            created_time__gt=blog.created_time).last()
        context['blog'] = blog
        response = render(request, 'blog/blog_detail.html', context)  # 响应
        response.set_cookie(read_cookie_key, 'true')  # 阅读cookie标记
        return response
Exemple #4
0
def blog_detail(request, blog_pk):
    context = {}
    blog = get_object_or_404(Blog, pk=blog_pk)
    read_cookie_key = read_statistic_once_read(request, blog)
    context['previous_blog'] = Blog.objects.filter(
        created_time__gt=blog.created_time).last()
    context['next_blog'] = Blog.objects.filter(
        created_time__lt=blog.created_time).first()
    context['blog'] = blog
    context["content"] = blog.content
    context["login_form"] = LoginForm()
    response = render(request, 'blog/blog_detail.html', context)
    response.set_cookie(read_cookie_key, 'true')
    return response
Exemple #5
0
def blog_detail(request, blog_id):
    blog = get_object_or_404(Blog, id=blog_id)
    read_cookie_key = read_statistic_once_read(request, blog)

    context = {}
    context['previous_blog'] = Blog.objects.filter(
        created_time__gt=blog.created_time).last()
    context['next_blog'] = Blog.objects.filter(
        created_time__lt=blog.created_time).first()
    context['blog'] = blog
    context['login_form'] = LoginForm()
    response = render(request, 'blog/blog_detail.html', context)
    response.set_cookie(read_cookie_key, 'ture')  #阅读的标记
    return response
Exemple #6
0
def news_detail(request,
                news_pk):  #此处的news_pk与url文件中urlpatterns中的<int:news_pk>对应
    news = get_object_or_404(Anews, pk=news_pk)
    getcookies = read_statistic_once_read(request, news)
    content_type = ContentType.objects.get_for_model(news)
    comments = Commment.objects.filter(content_type=content_type,
                                       object_id=news_pk,
                                       parent=None)  #显示一级评论

    #form的初始化
    data = {}
    data['content_type'] = content_type
    data['object_id'] = news_pk
    data['reply_comment_id'] = 0
    comment_form = CommentForm(initial=data)

    images = Image.objects.filter(content_type=content_type, object_id=news_pk)
    image_list = []
    for i in range(images.count()):
        image_list.append(i)
    images_list_tuple = zip(image_list, images)

    login_form = LoginForm()
    context = {}
    current_news = news
    context['loginform'] = login_form
    context['comment_count'] = Commment.objects.filter(
        content_type=content_type, object_id=news_pk).count()
    context['comment_form'] = comment_form
    context['image_list'] = image_list
    context['images'] = images_list_tuple
    context['comments'] = comments.order_by('-comment_time')
    context['news'] = current_news
    context['previous_news'] = Anews.objects.filter(
        created_time__gt=current_news.created_time).last()
    context['next_news'] = Anews.objects.filter(
        created_time__lt=current_news.created_time).first()
    response = render(request, 'news/news_detail.html', context)
    response.set_cookie(getcookies, 'true', max_age=60)
    return response