def multi_point_path(request): points = Point.objects.all() middle_points = [] if request.method != 'POST': form = PointForm(extra=0) else: extra_point_number = request.POST.get('extra_points_count') form = PointForm(request.POST, extra=extra_point_number) if form.is_valid(): middle_points.append( Point.objects.get(name=form['begin_point'].value())) for extra_point in range(int(extra_point_number)): try: middle_points.append( Point.objects.get(name=form['extra_points_{ep}'.format( ep=extra_point)].value())) except: # ToDo: Inform user about invalid input in case input is not empty # print(form['extra_points_{ep}'.format(ep=extra_point)].value()) pass context = { 'form': form, 'points': points, 'middlePoints': middle_points, } return render(request, 'map/multi_point_path.html', context)
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 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 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 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))
from points.forms import PointForm form = PointForm() def ol_media(request): '''provides the media for an olwidget for maps data being dyn-ajax ''' string = form.media.render() return { 'points_form_media': string, } def GAK(request): ''' Provides settings.GOOGLE_API_KEY as GAK ''' from django.conf import settings GAK = settings.GOOGLE_API_KEY return {'GAK': GAK}
def create(self, request): p = PointForm(request.POST) p.save()