Exemplo n.º 1
0
def article(request, slug):
    """A single article"""

    article = get_object_or_404(Article, slug=slug)
    ip = get_client_ip(request)
    like = LikePost.objects.filter(article=article, ip=ip).first()
    return render(request, "article.html", {"article": article, "like": like})
Exemplo n.º 2
0
def like(request, id):
    article = get_object_or_404(Article, id=id)
    ip = get_client_ip(request)
    if not LikePost.objects.filter(article=article, ip=ip):
        like = LikePost.objects.create(article=article, ip=ip)
        return HttpResponse("success")
    else:
        return HttpResponse("already like")
Exemplo n.º 3
0
 def get(self, request):
     # 获取公用数据
     common_return_dict = utils.refresh(request)
     # 页面请求地图显示所需要的数据
     if 'type' in request.GET.keys() and request.GET['type'] == utils.PARAS().TYPE_FOR_QUERY_MAP_DATA:
         MAP_DATA = utils.refresh_map_data()
         return MAP_DATA if MAP_DATA else HttpResponse([])
     ip = utils.get_client_ip(request)
     visitor = get_object_or_404(Visitor, ip=ip)
     common_return_dict['title'] = utils.PARAS().ABOUT_PAGE_TITLE
     common_return_dict.update(utils.PARAS().ABOUT_PAGE_AUTHOR_INFO)
     common_return_dict['visit_rank'] = utils.get_visitor_rank(visitor.id)
     common_return_dict['category'] = '关于'
     return render(request, 'blog/about.html', common_return_dict)
Exemplo n.º 4
0
 def get(self, request):
     # 记录访客
     threading.Thread(target=utils.record_visitor, args=(request,)).start()
     # 获取公用数据
     common_return_dict = utils.refresh(request)
     # 页面请求地图显示所需要的数据
     if 'type' in request.GET.keys() and request.GET['type'] == config.TYPE_FOR_QUERY_MAP_DATA:
         MAP_DATA = utils.refresh_map_data()
         return MAP_DATA if MAP_DATA else HttpResponse([])
     ip = utils.get_client_ip(request)
     visitor = get_object_or_404(Visitor, ip=ip)
     common_return_dict['title'] = config.ABOUT_PAGE_TITLE
     common_return_dict.update(config.ABOUT_PAGE_AUTHOR_INFO)
     common_return_dict['visit_rank'] = utils.get_visitor_rank(visitor.id)
     common_return_dict['category'] = config.ABOUT_PAGE_TITLE
     common_return_dict['project_cooparation_info'] = config.PROJECT_COOPARATION_INFO
     return render(request, 'blog/about.html', common_return_dict)