def get_point(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = PointForm(request.POST) # check whether it's valid: if form.is_valid(): # process the data in form.cleaned_data as required # ... # redirect to a new URL: return HttpResponseRedirect('/') # if a GET (or any other method) we'll create a blank form else: form = PointForm() return render(request, 'point_form.html', {'form': form})
def add_point(request): """ Get the form to add a point """ data = {'success': False} rendered = None form = PointForm(request.POST or None, request.FILES if request.POST else None) if request.method == 'POST': point = form.save(commit=False) point.user = request.user point.save() photoForm = PhotoForm(request.POST, request.FILES) photo = photoForm.save(commit=False) photo.point = point photo.save() else: rendered = render_to_string('points/add_point_form.html', {'form': form}, RequestContext(request)) data = {'success': True, 'html': rendered} return HttpResponse(simplejson.dumps(data))