47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
from django.shortcuts import render,HttpResponse
|
|
from django.http import JsonResponse,HttpResponseNotAllowed,HttpResponseRedirect,JsonResponse
|
|
from django.views.decorators.http import require_http_methods
|
|
|
|
from comment.models import *
|
|
from home.models import *
|
|
# Create your views here.
|
|
|
|
@require_http_methods(["POST"])
|
|
def add_comment(request, id):
|
|
create_comment = Comment.objects.create(comment_Content=request.POST.get("comment"),comment_User=request.POST.get("username"), comment_Time=datetime.now(), archives_Id=id, qq=request.POST.get("qqNum"))
|
|
create_comment.save()
|
|
return HttpResponseRedirect("/archives/"+id)
|
|
|
|
@require_http_methods(["POST"])
|
|
def check_like(request, id, uuid):
|
|
articles_likes = ArticlesLike.objects.filter(articles_id=id,uuid=uuid)
|
|
if articles_likes:
|
|
return JsonResponse({"liked":True})
|
|
else:
|
|
return JsonResponse({"liked":False})
|
|
|
|
@require_http_methods(["POST"])
|
|
def like(request, id, uuid):
|
|
article_stat = 0
|
|
if not ArticlesLike.objects.filter(articles_id=id, uuid=uuid):
|
|
ArticlesLike.objects.create(articles_id=id, uuid=uuid)
|
|
article = Articles.objects.get(id=id)
|
|
article.stat += 1
|
|
article_stat = article.stat
|
|
article.save()
|
|
return JsonResponse({"success":True,"new_count": article_stat})
|
|
|
|
@require_http_methods(["POST"])
|
|
def un_like(request,id, uuid):
|
|
article_stat = 0
|
|
if ArticlesLike.objects.filter(articles_id=id, uuid=uuid):
|
|
ArticlesLike.objects.filter(articles_id=id, uuid=uuid).delete()
|
|
article = Articles.objects.get(id=id)
|
|
article.stat -= 1
|
|
article_stat = article.stat
|
|
article.save()
|
|
|
|
return JsonResponse({"success":True,"new_count": article_stat})
|