def play_remote(request, session_id=None, playsettings=None): if not session_id: playsettings = playsettings if playsettings is not None else request.POST xform = playsettings.get('xform') try: tmp_file_handle, tmp_file_path = tempfile.mkstemp() tmp_file = os.fdopen(tmp_file_handle, 'w') tmp_file.write(xform.encode('utf-8')) tmp_file.close() new_form = XForm.from_file(tmp_file_path, str(file)) notice = "Created form: %s " % file except Exception, e: logging.error("Problem creating xform from %s: %s" % (file, e)) success = False notice = "Problem creating xform from %s: %s" % (file, e) raise e session = PlaySession( next=playsettings.get('next'), abort=playsettings.get('abort'), input_mode=playsettings.get('input_mode'), preloader_data=json.loads(playsettings.get('data')), xform_id=new_form.id, saved_instance=playsettings.get('instance') ) session.save() params = '&'.join(['%s=%s' % (x[0],x[1]) for x in request.GET.items()]) return HttpResponseRedirect("%s?%s" % (reverse('xform_play_remote', args=[session._id]), params))
def play_remote(request, session_id=None, playsettings=None): if not session_id: playsettings = playsettings if playsettings is not None else request.POST xform = playsettings.get('xform') try: tmp_file_handle, tmp_file_path = tempfile.mkstemp() tmp_file = os.fdopen(tmp_file_handle, 'w') tmp_file.write(xform.encode('utf-8')) tmp_file.close() new_form = XForm.from_file(tmp_file_path, str(file)) notice = "Created form: %s " % file except Exception, e: logging.error("Problem creating xform from %s: %s" % (file, e)) success = False notice = "Problem creating xform from %s: %s" % (file, e) raise e session = PlaySession(next=playsettings.get('next'), abort=playsettings.get('abort'), input_mode=playsettings.get('input_mode'), preloader_data=json.loads( playsettings.get('data')), xform_id=new_form.id, saved_instance=playsettings.get('instance')) session.save() params = '&'.join( ['%s=%s' % (x[0], x[1]) for x in request.GET.items()]) return HttpResponseRedirect( "%s?%s" % (reverse('xform_play_remote', args=[session._id]), params))
def get_remote_instance(request, session_id): session = PlaySession.get(session_id) response = HttpResponse(mimetype='application/xml') response.write(session.get_instance()) return response
notice = "Problem creating xform from %s: %s" % (file, e) raise e session = PlaySession( next=playsettings.get('next'), abort=playsettings.get('abort'), input_mode=playsettings.get('input_mode'), preloader_data=json.loads(playsettings.get('data')), xform_id=new_form.id, saved_instance=playsettings.get('instance') ) session.save() params = '&'.join(['%s=%s' % (x[0],x[1]) for x in request.GET.items()]) return HttpResponseRedirect("%s?%s" % (reverse('xform_play_remote', args=[session._id]), params)) session = PlaySession.get(session_id) def onsubmit(xform, instance_xml): xform.delete() # keep the session/attachment around for later access. # TODO: possibly consider auto-deleting these at some point session.put_attachment(instance_xml, "form.xml", "text/xml", len(instance_xml)) # use & if the url already has a ? url = "%s?session_id=%s" % (session.next, session_id) \ if "?" not in session.next \ else "%s&session_id=%s" % (session.next, session_id) return HttpResponseRedirect(url) def onabort(xform): xform.delete() session.delete() return HttpResponseRedirect(session.abort if session.abort else session.next) return enter_form(request,
raise e session = PlaySession(next=playsettings.get('next'), abort=playsettings.get('abort'), input_mode=playsettings.get('input_mode'), preloader_data=json.loads( playsettings.get('data')), xform_id=new_form.id, saved_instance=playsettings.get('instance')) session.save() params = '&'.join( ['%s=%s' % (x[0], x[1]) for x in request.GET.items()]) return HttpResponseRedirect( "%s?%s" % (reverse('xform_play_remote', args=[session._id]), params)) session = PlaySession.get(session_id) def onsubmit(xform, instance_xml): xform.delete() # keep the session/attachment around for later access. # TODO: possibly consider auto-deleting these at some point session.put_attachment(instance_xml, "form.xml", "text/xml", len(instance_xml)) # use & if the url already has a ? url = "%s?session_id=%s" % (session.next, session_id) \ if "?" not in session.next \ else "%s&session_id=%s" % (session.next, session_id) return HttpResponseRedirect(url) def onabort(xform): xform.delete()