def write_review(req, request_id): if req.method == 'POST': try: data = json.loads(req.body) except ValueError: data = req.POST request = Request.objects.get(id=request_id) worker_id = request.proposal_set.get(status=Request.ACCEPTED).worker_id request.status = Request.CLOSED request.save() user = req.user worker = Worker.objects.get(id=worker_id) rating = data['rating'] type = Review.CUSTOMER_WORKER message = data['message'] review = Review(user=user, worker=worker, rating=rating, type=type, message=message) review.save() return JsonResponse({ 'status': 'success', 'message': review.user.username }) response = JsonResponse({ 'status': 'error', 'message': 'Invalid request method' }) response.status_code = 405 return response
def write_review(req, request_id): try: data = json.loads(req.body) except ValueError: data = req.POST request = Request.objects.get(id=request_id) request.status = Request.CLOSED request.save() user_id = request.user_id worker = req.worker rating = data['rating'] type = Review.WORKER_CUSTOMER message = data['message'] review = Review(user_id=user_id, worker=worker, rating=rating, type=type, message=message) review.save() return JsonResponse({ 'status': 'success', 'message': review.user.username })