Beispiel #1
0
def commentdislike(request):
	try:
		commentid = request.POST.get('commentid')
		comment = Comment.objects.get(pk=commentid)
		user = request.user
	except Article.DoesNotExist:
		raise Http404("Article does not exist")
	try:
		commentdislike = CommentDisLike.objects.get(comment=comment, user=user)
	except:
		commentdislike = None
	if commentdislike: 
		commentdislikecount = -1
		#commentdislike.delete()
		instancedelete.delay(commentdislike)
		#减去缓存中评论点赞数
		cachekey = "comment_dislike_count_" + str(comment.id)
		if cache.get(cachekey) != None:
			cache.decr(cachekey)
		else:
			cache.set(cachekey,  comment.commentdislike_set.count())
			cache.decr(cachekey)
		# comment.readers = comment.readers - 1
		# comment.save()
		readersout.delay(comment)
	else:
		commentdislikecount = +1
		#加上缓存中评论点赞数
		cachekey = "comment_dislike_count_" + str(comment.id)
		if cache.get(cachekey) != None:
			cache.incr(cachekey)
		else:
			cache.set(cachekey,  comment.commentdislike_set.count())
			cache.incr(cachekey)
		# comment.readers = comment.readers + 1
		# comment.save()
		readersin.delay(comment)
		c = CommentDisLike(user=user, comment=comment)
		#c.save()
		instancesave.delay(c)
	data = {
	 'commentdislikecount': commentdislikecount,
	}
	json_data = json.dumps(data)
	#print 'commentlike'
	return HttpResponse(json_data, content_type='application/json')
Beispiel #2
0
def deleteinfo(request):
	try:
		instancetable = {
			'Comment':Comment,
			'Notification':Notification,
			'Collection': Collection,
			'CollectionTopic': CollectionTopic,
			'Topic': Topic,
		}
		instanceid = request.POST.get('instanceid')
		instancetype = request.POST.get('instancetype')
		instace = instancetable.get(instancetype).objects.get(pk=instanceid)
		#instace.delete()
		instancedelete.delay(instace)
		data = {
			"test": 'test',
		}
		json_data = json.dumps(data)
	except:
		traceback.print_exc()
	return HttpResponse(json_data, content_type='application/json')