def add_location(request):
    if(request.method == "POST"):
        request.POST[u"upVotes"] = 0
        request.POST[u"downVotes"] = 0
        form = AddLocation(request.POST, request.FILES)

        if(form.is_valid()):
            location = form.save()
            return HttpResponseRedirect("/location/" + str(location.id))

        return render(request, "add.html", {"form":form})
    else:
        form = AddLocation()

        return render(request, "add.html",
            dict({"form":form}.items() + request.GET.items()) # Adds on the address, latitude, and longitude
        )
def update_location(request, id=None):

    locations = Location.objects.filter(id=id)
    if len(locations) != 1:
        return HttpResponseBadRequest("Location with id " + id + " does not exist. Cannot update.")
    location = locations[0]

    if request.method == "POST":
        updateData = location.__dict__
        updateFiles = {"picture":location.picture}

        # Set fields the form/request doesn't have set
        if 'description' in request.POST:
            updateData['description'] = request.POST['description']

        if 'lot_type' in request.POST:
            updateData['lot_type'] = request.POST['lot_type']

        if 'picture' in request.FILES:
            updateFiles['picture'] = request.FILES['picture']

		#TODO Must also remember to delete the files from disk
        if 'picture-clear' in request.POST:
            updateFiles['picture'] = None
            updateData['picture-clear'] = request.POST['picture-clear']

        form = AddLocation(data=updateData, files=updateFiles, instance=location)
        if form.is_valid():
            location = form.save()
            return HttpResponseRedirect("/location/" + str(location.id))

        return render(request, "update.html", {"form":form, "id":id})
    else:
        form = AddLocation(instance=location)

        return render(request, "update.html",{"form":form, "id":id}) # Adds on the address, latitude, and longitude