def edit_place(request, slug=None): template_name = 'editplace' user = request.user if request.method == 'POST': posta = request.POST.copy() place = get_object_or_404(Place, slug=slug) form = PlaceForm(posta, instance=place) if form.is_valid(): place = form.save(commit=False) place.lat = float(request.POST.get("lat", "0")) place.lon = float(request.POST.get("lon", "0")) place.author = user place.save() if request.FILES.get('photo', ''): photo = MPhoto() photo.name = request.REQUEST['name'] photo.image = request.FILES['photo'] photo.user = user photo.def_img = True photo.place = place photo.save() return HttpResponseRedirect(reverse("edit_places")) else: return render_to_response('places/edit_place.html', locals(), context_instance=RequestContext(request)) else: place = get_object_or_404(Place, slug=slug) form = PlaceForm(instance=place) return render_to_response('places/edit_place.html', locals(), context_instance=RequestContext(request))
def edit_place(request, slug=None): template_name='editplace' user = request.user if request.method == 'POST': posta=request.POST.copy() place = get_object_or_404(Place, slug=slug) form = PlaceForm(posta, instance=place) if form.is_valid(): place = form.save(commit=False) place.lat = float(request.POST.get("lat","0")) place.lon = float(request.POST.get("lon","0")) place.author = user place.save() if request.FILES.get('photo',''): photo = MPhoto() photo.name = request.REQUEST['name'] photo.image = request.FILES['photo'] photo.user= user photo.def_img = True photo.place = place photo.save() return HttpResponseRedirect(reverse("edit_places")) else: return render_to_response('places/edit_place.html', locals(), context_instance=RequestContext(request)) else: place = get_object_or_404(Place, slug=slug) form = PlaceForm(instance=place) return render_to_response('places/edit_place.html', locals(), context_instance=RequestContext(request))
def addPhoto(request, slug=''): template_name='addphoto' place = get_object_or_404(Place, slug=slug) if request.method == 'POST': # If the form has been submitted... if request.FILES.get('image',''): photo = MPhoto() photo.name = request.REQUEST['name'] photo.image = request.FILES['image'] photo.user= request.user photo.place = place photo.save() return HttpResponseRedirect(place.get_absolute_url()) # Redirect after POST else: return render_to_response('addphoto.html', locals(), context_instance=RequestContext(request) )
def addPhoto(request, slug=''): template_name = 'addphoto' place = get_object_or_404(Place, slug=slug) if request.method == 'POST': # If the form has been submitted... if request.FILES.get('image', ''): photo = MPhoto() photo.name = request.REQUEST['name'] photo.image = request.FILES['image'] photo.user = request.user photo.place = place photo.save() return HttpResponseRedirect( place.get_absolute_url()) # Redirect after POST else: return render_to_response('addphoto.html', locals(), context_instance=RequestContext(request))