def vote(request): if not request.method == 'POST': return HttpResponse("Wrong request method") placemark = Placemark.objects.get(id=int(request.POST['id'])) if Vote.objects.filter(user=request.user, placemark=placemark).exists(): currentvote = Vote.objects.get(user=request.user, placemark=placemark) currentvote.positive = request.POST['positive'] == 'True' currentvote.save() return HttpResponse("Updated") newvote = Vote() newvote.placemark = placemark newvote.user = request.user newvote.positive = request.POST['positive'] == 'True' newvote.save() return HttpResponse("OK")
def addplacemark(request): if not request.method == 'POST': return HttpResponse("Wrong request method") if Placemark.objects.filter(place__id=request.POST['place'], address=request.POST['address'], city=request.POST['city'], lat=request.POST['lat'], lng=request.POST['lng']).exists(): return HttpResponse("exists") newplacemark = Placemark(); newplacemark.place_id = int(request.POST['place']) newplacemark.city = request.POST['city'] newplacemark.address = request.POST['address'] newplacemark.lat = float(request.POST['lat']) newplacemark.lng = float(request.POST['lng']) newplacemark.save() newvote = Vote() newvote.placemark = newplacemark newvote.user = request.user newvote.positive = 'True' newvote.save() return HttpResponse("OK")
def addplacemark(request): if not request.method == 'POST': return HttpResponseNotAllowed("Wrong request method") if Placemark.objects.filter(place__id=request.POST['place'], address=request.POST['address'], city=request.POST['city'], lat=request.POST['lat'], lng=request.POST['lng']).exists(): return HttpResponse("exists") newplacemark = Placemark(); newplacemark.place_id = int(request.POST['place']) newplacemark.city = request.POST['city'] newplacemark.address = request.POST['address'] newplacemark.lat = float(request.POST['lat']) newplacemark.lng = float(request.POST['lng']) newplacemark.save() newvote = Vote() newvote.placemark = newplacemark newvote.user = request.user newvote.positive = 'True' newvote.save() return HttpResponse(newplacemark.id)