def post(self): request_data = request.get_json() downvote_object = downvote_post_handler.create_downvote(request_data) response_dict = downvote_utils.get_downvote_dict(downvote_object) auth_token = request.cookies.get('auth_key') is_valid, user_object = user_service.validate_and_get_user(auth_token) username = user_object['username'] answer_id = request_data['answerId'] answer_object = answer_get_handler.get_answer_by_id(answer_id) # print "#######################################################################" # print "Action By============================>",username # print "Owner By============================>",answer_object.user_id # print "Entity Id============================>",answer_object.id # print "entity_type============================> Downvote" # print "#######################################################################" entity_type = "Downvote" entity_id = answer_object.id action_by = username owner_by = answer_object.user_id Notification = create_Notification_Object(entity_type, entity_id, action_by, owner_by) if Notification: return jsonify({"Downvote": response_dict})
def post(self): # import pdb; pdb.set_trace() #read the auth token from cookie #request the auth token to user_service and get asociated user #if token is invalid return respose unauthorised #if token is valid then follow the step # import pdb; pdb.set_trace() auth_token = request.cookies.get('auth_key') print auth_token #user_object = User print "authToken: ", auth_token # print auth_token is_valid, user_object = user_service.validate_and_get_user(auth_token) print user_object username = user_object['username'] print username if not is_valid: return {"success": False, "message": "Invalid User !!"}, 401 #print user_object request_data = request.get_json() result = question_post_handler.create_question(request_data, username) if result: response_dict = question_utils.get_question_dict(result) return jsonify({"question": response_dict}) else: return {"success": False}
def put(self): auth_token = request.cookies.get('auth_key') is_valid, user_object = user_service.validate_and_get_user(auth_token) Notification_object = get_Notification_By_UserId(user_object) print "###########################" print "Notification Object(put) ----->", Notification_object print "###########################" Notification_read = read_all_notification(Notification_object) return None
def create_upvote(request_data): auth_token = request.cookies.get('auth_key') is_valid, user_object = user_service.validate_and_get_user(auth_token) username = user_object['username'] answer_id = request_data['answerId'] answer_object = answer_get_handler.get_answer_by_id(answer_id) try: upvote_object, is_created = Upvote.objects.get_or_create(user_id=username, answer=answer_object) return upvote_object except Exception as e: print e raise InternalServerError()
def get(self): auth_token = request.cookies.get('auth_key') is_valid, user_object = user_service.validate_and_get_user(auth_token) #//check of unautherize access Notification_object = get_Notification_By_UserId(user_object) # for x in Notification_object: # print "###########################" # print "Notification Object(Get) ----->", Notification_object # print "###########################" # print Notification_object response_dict = get_Notification_by_response_dict.get_Notification_by_response_dict( Notification_object) # print response_dict return jsonify({"notification": response_dict})
def post(self): # import pdb; # pdb.set_trace() auth_token = request.cookies.get('auth_key') print auth_token is_valid, user_object = user_service.validate_and_get_user(auth_token) print user_object username = user_object['username'] # print username if not is_valid: return {"success": False, "message": "Invalid User !!"}, 401 # print user_object request_data = request.get_json() print request_data answer_object = answer_post_handler.create_answer( request_data, username) response_dict = answer_utils.get_answer_dict(answer_object) return jsonify({"answer": response_dict})
def post(self): # import pdb; # pdb.set_trace() auth_token = request.cookies.get('auth_key') # print auth_token is_valid, user_object = user_service.validate_and_get_user(auth_token) print user_object username = user_object['username'] # print username if not is_valid: return {"success": False, "message": "Invalid User !!"}, 401 # print user_object request_data = request.get_json() # print request_data answer_object = answer_post_handler.create_answer( request_data, username) response_dict = answer_utils.get_answer_dict(answer_object) ###########Notification ########## action_by = username owner_by = answer_object.question.user_id entity_id = answer_object.question.id entity_type = "Answer" # print "=============================" # print action_by, owner_by, entity_id, entity_type # print "=============================" Notification = create_Notification_Object(entity_type, entity_id, action_by, owner_by) if Notification: return jsonify({"answer": response_dict})