def change(request, id): ''' Change the data for a single Point() obj ''' try: point = Point.objects.get(id=id) except: return HttpResponseNotFound() if request.method == 'POST' and point.owner == request.user: form = PointForm(request.POST, instance=point) if form.is_valid(): form.save() try: return HttpResponseRedirect(point.content_object.get_absolute_url()) except: return HttpResponseRedirect(point.get_absolute_url()) elif point.owner == request.user: form = PointForm( instance=point) context = {'point':point, 'form':form, } return render_to_response('points/change.html', context,\ context_instance=RequestContext(request) ) else: return HttpResponseNotFound()
def update(self, request, id): point = Point.objects.get(id=id) # ?? will this work? p = PointForm(request.PUT, instance=point) p.save() return p
def add(request, app_label, model_name, id): '''add a point to a content_object POST the point and the zoom. The owner is request.user and the related obj is received from the url. ''' try: ct = ContentType.objects.get(\ app_label = app_label, model = model_name) obj = ct.get_object_for_this_type( id=id ) except: return HttpResponseNotFound() if request.method == 'POST': request.POST.update( {'owner':request.user.id, 'object_id':id,\ 'content_type':ct.id, 'content_obj':obj,} ) form = PointForm(request.POST) if form.is_valid(): form.save() #try: # return HttpResponseRedirect(request.META['HTTP_REFERER']) #except: try: return HttpResponseRedirect(obj.get_absolute_url()) except: return HttpResponseRedirect(reverse('points_list')) else: form = PointForm() context = {'form':form, 'object':obj, 'content_type':ct, } context.update(locals()) return render_to_response('points/add.html', context,\ context_instance = RequestContext(request))
def add(request, app_label, model_name, id): """add a point to a content_object POST the point and the zoom. The owner is request.user and the related obj is received from the url. """ try: ct = ContentType.objects.get(app_label=app_label, model=model_name) obj = ct.get_object_for_this_type(id=id) except: return HttpResponseNotFound() if request.method == "POST": request.POST.update({"owner": request.user.id, "object_id": id, "content_type": ct.id, "content_obj": obj}) form = PointForm(request.POST) if form.is_valid(): form.save() # try: # return HttpResponseRedirect(request.META['HTTP_REFERER']) # except: try: return HttpResponseRedirect(obj.get_absolute_url()) except: return HttpResponseRedirect(reverse("points_list")) else: form = PointForm() context = {"form": form, "object": obj, "content_type": ct} context.update(locals()) return render_to_response("points/add.html", context, context_instance=RequestContext(request))
def change(request, id): """ Change the data for a single Point() obj """ try: point = Point.objects.get(id=id) except: return HttpResponseNotFound() if request.method == "POST" and point.owner == request.user: form = PointForm(request.POST, instance=point) if form.is_valid(): form.save() return HttpResponseRedirect(point.get_absolute_url()) elif point.owner == request.user: form = PointForm(instance=point) context = {"point": point, "form": form} return render_to_response("points/change.html", context, context_instance=RequestContext(request)) else: return HttpResponseNotFound()
def create(self, request): p = PointForm(request.POST) p.save()