def add(request): error = "" response = "" status = 201 if not request.user.is_authenticated(): status = 403 error += "Must be logged in to do that" elif request.method == "POST": data = request.POST.copy() # We shouldn't be allowed to review a restroom twice if len(Review.objects.filter(user=request.user).filter(toilet=data["toilet"])) == 0: r = Review() with transaction.commit_on_success(): toilet = Toilet.objects.get(pk=data["toilet"]) data["toilet"] = toilet toilet.updateRating(data["rank"]) data["date"] = currentTime() data["user"] = request.user data["up_down_rank"] = 0 r.setattrs(data) # validation r.full_clean() r.save() response = serialize([r]) else: error += "Cannot write more than one review.\n" status = 403 else: error += "No POST data in request.\n" status = 415 return HttpResponse(package_error(response, error), status=status)
def add(request): error = '' response = '' status = 201 if request.method == 'POST': data = request.POST.copy() #We shouldn't be allowed to review a restroom twice if len(Review.objects.filter(user=request.user).filter(toilet=data['toilet'])) == 0: r = Review() toilet = Toilet.objects.get(pk=data['toilet']) data['date'] = currentTime() data['user'] = request.user data['toilet'] = toilet data['up_down_rank'] = 0; r.setattrs(data) r.save() toilet.updateRating(data['rank']) response = serialize([r]) else: error += 'Cannot write more than one review.\n' status = 403 else: error += 'No POST data in request.\n' status = 415 return HttpResponse(package_error(response,error), status=status)
def add(request): error = '' response = '' status = 201 if request.method == 'POST': data = request.POST.copy() if not request.user.is_authenticated(): status = 401 error += 'Unauthorized creation of restroom. Please log in.\n' else: t = Toilet() data['date'] = currentTime() data['creator'] = request.user info = AdditionalUserInfo.objects.get(user=request.user) if info.male == False and info.female == False: data['male'] = True data['male'] = True else: data['male'] = info.male data['female'] = info.female t.setattrs(data) t.save() response = serialize([t]) else: error += 'No POST data in request.\n' status = 415 return HttpResponse(package_error(response,error), status=status)
def add(request): error = '' response = '' status = 201 if request.method == 'POST': data = request.POST.copy() if not request.user.is_authenticated(): status = 401 error += 'Unauthorized creation of restroom. Please log in.\n' else: t = Toilet() data['date'] = currentTime() data['creator'] = request.user t.setattrs(data) t.save() response = serialize([t]) else: error += 'No POST data in request.\n' status = 415 return HttpResponse(package_error(response,error), status=status)