def createform1(request, medical_record_number): logging.debug("createform1 invoked") # this code path is when the user's POSTed to us if request.method == 'POST': # set up the form object form = FormDateTimeForm(request.POST) # if the form is valid, do this stuff if form.is_valid(): logging.debug("Form is valid") # this grabs the specific patient record based on the url (from urls.py) patient = Patient.all().filter('medical_record_number =', medical_record_number).get() # pull out the data from the form date_of_visit = form.cleaned_data['date_of_visit'] start_time = form.cleaned_data['start_time'] end_time = form.cleaned_data['end_time'] #TODO: figure out how to ensure uniqueness # create a Form object with that data formobject = Form(date_of_visit = date_of_visit, start_time_of_visit = start_time, end_time_of_visit = end_time, patient = patient) # save the object to the datastore formobject.put() logging.debug("Saved form to the datastore") # this calls the template createform2.html and passes the form object and the new form we're going to use #return render_to_response(request, "createform2.html", # { "formobject" : formobject } #) return HttpResponseRedirect("/dorkdoc/patient/" + medical_record_number + "/form/create/step2/" + str(formobject.key())) else: logging.debug("Form isn't valid!") # this code path is when the user GETs this URL else: # create a blank form object form = FormDateTimeForm() # this passes the form data to the create form 1 template return render_to_response(request, 'createform1.html', { 'medical_record_number' : medical_record_number, 'form' : form } )