def load_form(xform, instance=None, extensions=[], preload_data={}): form = XFormParser(StringReader(xform)).parse() if instance != None: XFormParser.loadXmlInstance(form, StringReader(instance)) customhandlers.attach_handlers(form, preload_data, extensions) form.initialize(instance == None) return form
def load_form(xform, instance=None, extensions=[], session_data={}, api_auth=None): form = XFormParser(StringReader(xform)).parse() if instance != None: XFormParser.loadXmlInstance(form, StringReader(instance)) # retrieve preloaders out of session_data (for backwards compatibility) customhandlers.attach_handlers(form, extensions, session_data.get('preloaders', {})) form.initialize(instance == None, CCInstances(session_data, api_auth)) return form
def load_form( xform, instance=None, extensions=None, session_data=None, api_auth=None, form_context=None, uses_sql_backend=False ): """Returns an org.javarosa.core.model.FormDef Parameters ---------- xform : string String representation of an xform form_context : dictionary A hash that contains optional context for the form. Supported parameters are: 'all_case_ids' and 'case_model'. The XFormPlayer uses the context to avoid making redundant calls to CommcareHQ. """ extensions = extensions or [] session_data = session_data or {} is_editing = session_data.get("is_editing", False) form = XFormParser(StringReader(xform)).parse() if instance is not None: XFormParser(None).loadXmlInstance(form, StringReader(instance)) # retrieve preloaders out of session_data (for backwards compatibility) customhandlers.attach_handlers( form, extensions, context=session_data.get("function_context", {}), preload_data=session_data.get("preloaders", {}), ) try: session_data.get("additional_filters", {}).update( {"use_cache": "true", "hsph_hack": session_data.get("case_id", None)} ) form.initialize( instance is None, is_editing, CCInstances(session_data, api_auth, form_context=form_context, uses_sqlite=uses_sql_backend), ) except CaseNotFound: # Touchforms repeatedly makes a call to HQ to get all the case ids in its universe. We can optimize # this by caching that call to HQ. However, when someone adds a case to that case list, we want to ensure # that that case appears in the universe of cases. Therefore we first attempt to use the cached version # of the case id list, and in the event that we cannot find a case, we try again, but do not use the cache. session_data.get("additional_filters", {}).update({"use_cache": "false"}) form.initialize( instance is None, is_editing, CCInstances(session_data, api_auth, form_context=form_context, uses_sqlite=uses_sql_backend), ) return form
def load_form(xform, instance=None, extensions=None, session_data=None, api_auth=None, form_context=None, uses_sql_backend=False): """Returns an org.javarosa.core.model.FormDef Parameters ---------- xform : string String representation of an xform form_context : dictionary A hash that contains optional context for the form. Supported parameters are: 'all_case_ids' and 'case_model'. The XFormPlayer uses the context to avoid making redundant calls to CommcareHQ. """ extensions = extensions or [] session_data = session_data or {} is_editing = session_data.get("is_editing", False) form = XFormParser(StringReader(xform)).parse() if instance is not None: XFormParser(None).loadXmlInstance(form, StringReader(instance)) # retrieve preloaders out of session_data (for backwards compatibility) customhandlers.attach_handlers( form, extensions, context=session_data.get('function_context', {}), preload_data=session_data.get('preloaders', {}) ) try: session_data.get('additional_filters', {}).update({ 'use_cache': 'true', 'hsph_hack': session_data.get('case_id', None) }) form.initialize(instance is None, is_editing, CCInstances(session_data, api_auth, form_context=form_context, uses_sqlite=uses_sql_backend)) except CaseNotFound: # Touchforms repeatedly makes a call to HQ to get all the case ids in its universe. We can optimize # this by caching that call to HQ. However, when someone adds a case to that case list, we want to ensure # that that case appears in the universe of cases. Therefore we first attempt to use the cached version # of the case id list, and in the event that we cannot find a case, we try again, but do not use the cache. session_data.get('additional_filters', {}).update({'use_cache': 'false'}) form.initialize(instance is None, is_editing, CCInstances(session_data, api_auth, form_context=form_context, uses_sqlite=uses_sql_backend)) return form