def get_filtered_data_for_parsed_params(domain, parsed_params): # this code path has multiple forks: # 0. if status isn't set (which cory doesn't think is possible) it defaults to filtering by # status "active". otherwise it will set status to be "active" or "deleted" depending # on what's passed in. # 1. if status is set, but nothing else is, it will return all forms in apps of that status # 2. if status and app_id are set, but nothing else, it will return all forms in that app # 3. if status and app_id and module_id are set, it will return all forms in that module if # the module is valid, otherwise it falls back to the app # 4. if status, app_id, module_id, and xmlns are set (which cory doesn't think is possible) # it returns that form. deleted = parsed_params.status == PARAM_VALUE_STATUS_DELETED _assert = soft_assert(to='@'.join(['czue', 'dimagi.com'])) if parsed_params.module is not None and parsed_params.get_module_int() is None: # todo: remove anytime in 2016 _assert(False, "module set but not a valid number!") return get_form_details_for_app(domain, parsed_params.app_id, deleted=deleted) elif parsed_params.most_granular_filter == 'xmlns': # todo: remove anytime in 2016 _assert(False, "got to form ID even though this shouldn't be possible") return get_form_details_for_app_and_xmlns( domain, parsed_params.app_id, parsed_params.xmlns, deleted=deleted) elif parsed_params.most_granular_filter == 'module': return get_form_details_for_app_and_module( domain, parsed_params.app_id, parsed_params.get_module_int(), deleted=deleted ) elif parsed_params.most_granular_filter == 'app_id': return get_form_details_for_app(domain, parsed_params.app_id, deleted=deleted) elif parsed_params.most_granular_filter == 'status': return get_all_form_details(domain, deleted=deleted) else: # todo: remove anytime in 2016 _assert(False, 'most granular filter was a surprising value ({}).'.format( parsed_params.most_granular_filter)) return get_all_form_details(domain)
def get_filtered_data_for_parsed_params(domain, parsed_params): # this code path has multiple forks: # 1. if status is set, but nothing else is, it will return all forms in apps of that status # 2. if status and app_id are set, but nothing else, it will return all forms in that app # 3. if status and app_id and module_id are set, it will return all forms in that module if # the module is valid, otherwise it falls back to the app deleted = parsed_params.status == PARAM_VALUE_STATUS_DELETED if parsed_params.most_granular_filter == 'module': return get_form_details_for_app_and_module( domain, parsed_params.app_id, parsed_params.get_module_int(), deleted=deleted ) elif parsed_params.most_granular_filter == 'app_id': return get_form_details_for_app(domain, parsed_params.app_id, deleted=deleted) elif parsed_params.most_granular_filter == 'status': return get_all_form_details(domain, deleted=deleted)
def get_filtered_data_for_parsed_params(domain, parsed_params): # this code path has multiple forks: # 1. if status is set, but nothing else is, it will return all forms in apps of that status # 2. if status and app_id are set, but nothing else, it will return all forms in that app # 3. if status and app_id and module_id are set, it will return all forms in that module if # the module is valid, otherwise it falls back to the app deleted = parsed_params.status == PARAM_VALUE_STATUS_DELETED if parsed_params.most_granular_filter == 'module': return get_form_details_for_app_and_module( domain, parsed_params.app_id, parsed_params.get_module_int(), deleted=deleted ) elif parsed_params.most_granular_filter == 'app_id': return get_form_details_for_app(domain, parsed_params.app_id, deleted=deleted) elif parsed_params.most_granular_filter == 'status': return get_all_form_details(domain, deleted=deleted)
def _get_filtered_data(self, filter_results): """ Returns the raw form data based on the current filter selection. """ if not filter_results: if self._application_forms: return get_all_form_details(self.domain) else: return [] parsed_params = FormsByApplicationFilterParams(filter_results) if parsed_params.xmlns: return get_form_details_for_app_and_xmlns( self.domain, parsed_params.app_id, parsed_params.xmlns, deleted=parsed_params.status == PARAM_VALUE_STATUS_DELETED, ) else: if not self._application_forms: return [] return self.get_filtered_data_for_parsed_params( self.domain, parsed_params)
def _get_filtered_data(self, filter_results): """ Returns the raw form data based on the current filter selection. """ if not filter_results: if self._application_forms: return get_all_form_details(self.domain) else: return [] parsed_params = FormsByApplicationFilterParams(filter_results) if parsed_params.xmlns: return get_form_details_for_app_and_xmlns( self.domain, parsed_params.app_id, parsed_params.xmlns, deleted=parsed_params.status == PARAM_VALUE_STATUS_DELETED, ) else: if not self._application_forms: return [] return self.get_filtered_data_for_parsed_params( self.domain, parsed_params )
def test_get_all_form_details_deleted(self): details = get_all_form_details(self.domain, deleted=True) self.assertEqual(1, len(details)) self._assert_form_details_match(2, details[0])
def test_get_all_form_details_active(self): details = get_all_form_details(self.domain, deleted=False) self.assertEqual(2, len(details)) for i, detail in enumerate(details): self._assert_form_details_match(i, detail)
def test_get_all_form_details(self): app_structures = get_all_form_details(self.domain) self.assertEqual(3, len(app_structures)) for i, details in enumerate(app_structures): self._assert_form_details_match(i, details)
def test_get_all_form_details_no_data(self): self.assertEqual([], get_all_form_details('missing'))
def _application_forms_info(self): """ This is the data used for creating the drilldown_map. This returns the following type of structure: { 'app_id': { 'app': { 'names': [<foo>] or '<foo>', 'id': '<foo>', 'langs': [<foo>] }, 'is_user_registration': (True or False), 'is_deleted': (True or False), 'modules' : [ { 'module': { 'names': [<foo>] or '<foo>', 'id': index, 'forms': [ { 'form': { 'names': [<foo>] or '<foo>', 'xmlns': <xmlns> } ] } }, {...} ] }, 'next_app_id': {...}, } """ data = get_all_form_details(self.domain) default_module = lambda num: {'module': None, 'forms': []} app_forms = {} for app_structure in data: index_offset = 1 if app_structure.is_user_registration else 0 app_id = app_structure.app.id if not app_id in app_forms: app_forms[app_id] = { 'app': app_structure.app, 'is_user_registration': app_structure.is_user_registration, 'is_deleted': app_structure.is_deleted, 'modules': [] } module_id = app_structure.module.id + index_offset new_modules = module_id - len(app_forms[app_id]['modules']) + 1 if new_modules > 0: # takes care of filler modules (modules in the app with no form submissions. # these 'filler modules' are eventually ignored when rendering the drilldown map. app_forms[app_id]['modules'].extend([default_module(module_id - m) for m in range(0, new_modules)]) if not app_structure.is_user_registration: app_forms[app_id]['modules'][module_id]['module'] = app_structure.module app_forms[app_id]['modules'][module_id]['forms'].append({ 'form': app_structure.form, 'xmlns': app_structure.xmlns, }) return app_forms
def test_get_all_form_details_deleted(self): details = get_all_form_details(self.domain, deleted=True) self.assertEqual(1, len(details)) self._assert_form_details_match(2, details[0])
def test_get_all_form_details_active(self): details = get_all_form_details(self.domain, deleted=False) self.assertEqual(2, len(details)) for i, detail in enumerate(details): self._assert_form_details_match(i, detail)
def test_get_all_form_details(self): app_structures = get_all_form_details(self.domain) self.assertEqual(3, len(app_structures)) for i, details in enumerate(app_structures): self._assert_form_details_match(i, details)
def test_get_all_form_details_no_data(self): self.assertEqual([], get_all_form_details('missing'))
def _application_forms_info(self): """ This is the data used for creating the drilldown_map. This returns the following type of structure: { 'app_id': { 'app': { 'names': [<foo>] or '<foo>', 'id': '<foo>', 'langs': [<foo>] }, 'is_user_registration': (True or False), 'is_deleted': (True or False), 'modules' : [ { 'module': { 'names': [<foo>] or '<foo>', 'id': index, 'forms': [ { 'form': { 'names': [<foo>] or '<foo>', 'xmlns': <xmlns> } ] } }, {...} ] }, 'next_app_id': {...}, } """ data = get_all_form_details(self.domain) default_module = lambda num: {'module': None, 'forms': []} app_forms = {} for app_structure in data: index_offset = 1 if app_structure.is_user_registration else 0 app_id = app_structure.app.id if not app_id in app_forms: app_forms[app_id] = { 'app': app_structure.app, 'is_user_registration': app_structure.is_user_registration, 'is_deleted': app_structure.is_deleted, 'modules': [] } module_id = app_structure.module.id + index_offset new_modules = module_id - len(app_forms[app_id]['modules']) + 1 if new_modules > 0: # takes care of filler modules (modules in the app with no form submissions. # these 'filler modules' are eventually ignored when rendering the drilldown map. app_forms[app_id]['modules'].extend([default_module(module_id - m) for m in range(0, new_modules)]) if not app_structure.is_user_registration: app_forms[app_id]['modules'][module_id]['module'] = app_structure.module app_forms[app_id]['modules'][module_id]['forms'].append({ 'form': app_structure.form, 'xmlns': app_structure.xmlns, }) return app_forms