def get_bookmark_comment(request, bookmark_id): oauth_status = check_auth(request) if oauth_status: conn = get_redis_conn() comment_dao = CommentDao(conn) if request.method =='GET': comments = comment_dao.get_bookmark_comment(bookmark_id) result = json.dumps(comments, default=Comment.json_encode) return HttpResponse(result) else: return HttpResponse() else: return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
def delete(request, comment_id): oauth_status = check_auth(request) if oauth_status: conn = get_redis_conn() comment_dao = CommentDao(conn) if request.method =='POST': status = comment_dao.delete(id) if status: return HttpResponse('{"status":"Success"}') else: return HttpResponse('{"status":"Error"}') else: return HttpResponse() else: return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
def add(request): oauth_status = check_auth(request) if oauth_status: conn = get_redis_conn() comment_dao = CommentDao(conn) if request.method == 'POST': owner_id = request.POST["owner_id"] bookmark_id = request.POST["bookmark_id"] text = request.POST["text"] comment = Comment(owner_id, bookmark_id, text) id = comment_dao.save(comment) if id: comment = comment_dao.get_comment(id) result = json.dumps(comment, default=Comment.json_encode) return HttpResponse(result) else: result = '{"status":"error"}' return HttpResponse(result) else: return HttpResponse() else: return HttpResponseRedirect(settings.BUZZFIRE_LOGIN_URL)
def test_comment_dao(self): conn = redis.Redis("localhost") comment = Comment("1", "1", "hello") commentDao = CommentDao(conn) commentDao.save(comment) commentDao.get_comment("1")