def get_data_element(name, dict): elem = safe_element(name) for k, v in dict.items(): sub_el = safe_element("data", v) sub_el.attrib = {"key": k} elem.append(sub_el) return elem
def get_data_element(name, dict): elem = safe_element(name) for k, v in dict.items(): sub_el = safe_element("data", v) sub_el.attrib = {"key": k} elem.append(sub_el) return elem
def get_data_element(name, dict): elem = safe_element(name) # sorted for deterministic unit tests for k, v in sorted(dict.items()): sub_el = safe_element("data", v) sub_el.attrib = {"key": k} elem.append(sub_el) return elem
def get_data_element(name, dict): elem = safe_element(name) # sorted for deterministic unit tests for k, v in sorted(dict.items()): sub_el = safe_element("data", v) sub_el.attrib = {"key": k} elem.append(sub_el) return elem
def get_registration_element(restore_user): root = safe_element("Registration") root.attrib = {"xmlns": USER_REGISTRATION_XMLNS} root.append(safe_element("username", restore_user.username)) root.append(safe_element("password", restore_user.password)) root.append(safe_element("uuid", restore_user.user_id)) root.append(safe_element("date", date_to_xml_string(restore_user.date_joined))) root.append(get_data_element('user_data', restore_user.user_session_data)) return root
def get_registration_element(user): root = safe_element("Registration") root.attrib = {"xmlns": USER_REGISTRATION_XMLNS} root.append(safe_element("username", user.username)) root.append(safe_element("password", user.password)) root.append(safe_element("uuid", user.user_id)) root.append(safe_element("date", date_to_xml_string(user.date_joined))) root.append(get_data_element('user_data', user.user_session_data)) return root
def get_registration_element_for_case(case): root = safe_element("Registration") root.attrib = {"xmlns": USER_REGISTRATION_XMLNS} root.append(safe_element("username", case.name)) root.append(safe_element("password", "")) root.append(safe_element("uuid", case.case_id)) root.append(safe_element("date", date_to_xml_string(case.opened_on))) root.append(get_data_element('user_data', {})) return root
def get_registration_element_for_case(case): root = safe_element("Registration") root.attrib = {"xmlns": USER_REGISTRATION_XMLNS} root.append(safe_element("username", case.name)) root.append(safe_element("password", "")) root.append(safe_element("uuid", case.case_id)) root.append(safe_element("date", date_to_xml_string(case.opened_on))) root.append(get_data_element('user_data', {})) return root
def get_registration_element_for_case(restore_user, case_id, username): if not username: username = '' root = safe_element("Registration") root.attrib = {"xmlns": USER_REGISTRATION_XMLNS} root.append(safe_element("username", username)) root.append(safe_element("password", "")) root.append(safe_element("uuid", case_id)) root.append(safe_element("date", date_to_xml_string(restore_user.date_joined))) root.append(get_data_element('user_data', restore_user.user_session_data)) return root
def fixture(self): """For a list of cases, return a fixture with all case properties <results id="case"> <case case_id="" case_type="" owner_id="" status=""> <case_name/> <date_opened/> <last_modified/> <case_property /> <index> <a12345 case_type="" relationship="" /> </index> <attachment> <a12345 /> </attachment> </case> <case> ... </case> </results> https://github.com/dimagi/commcare/wiki/casedb https://github.com/dimagi/commcare/wiki/fixtures """ element = safe_element("results") element.attrib = {'id': self.id} for case in self.cases: element.append(get_casedb_element(case)) return ElementTree.tostring(element, encoding="utf-8")
def fixture(self): """For a list of cases, return a fixture with all case properties <results id="case"> <case case_id="" case_type="" owner_id="" status=""> <case_name/> <date_opened/> <last_modified/> <case_property /> <index> <a12345 case_type="" relationship="" /> </index> <attachment> <a12345 /> </attachment> </case> <case> ... </case> </results> https://github.com/dimagi/commcare/wiki/casedb https://github.com/dimagi/commcare/wiki/fixtures """ element = safe_element("results") element.attrib = {'id': self.id} for case in self.cases: element.append(get_casedb_element(case)) return ElementTree.tostring(element, encoding="utf-8")
def get_sync_element(restore_id=None): elem = safe_element("Sync") elem.attrib = {"xmlns": SYNC_XMLNS} if restore_id is not None: elem.append(safe_element("restore_id", restore_id)) return elem
def get_progress_element(done=0, total=0, retry_after=0): elem = safe_element("progress") elem.set('done', str(done)) elem.set('total', str(total)) elem.set('retry-after', str(retry_after)) return elem
def get_sync_element(restore_id): elem = safe_element("Sync") elem.attrib = {"xmlns": SYNC_XMLNS} elem.append(safe_element("restore_id", restore_id)) return elem
def get_progress_element(done=0, total=0, retry_after=0): elem = safe_element("progress") elem.set('done', str(done)) elem.set('total', str(total)) elem.set('retry-after', str(retry_after)) return elem
def get_sync_element(restore_id=None): elem = safe_element("Sync") elem.set("xmlns", SYNC_XMLNS) if restore_id is not None: elem.append(safe_element("restore_id", restore_id)) return elem