def setUp(self): super().setUp() delete_all_users() self.domain_obj = create_domain(self.domain) enable_usercase(self.domain) with trap_extra_setup(ConnectionError): self.es = get_es_new() initialize_index_and_mapping(self.es, CASE_SEARCH_INDEX_INFO) username = normalize_username("mobile_worker_1", self.domain) self.mobile_worker = CommCareUser.create(self.domain, username, "123", None, None) sync_user_cases(self.mobile_worker) self.checkin_case = CaseFactory(self.domain).create_case( case_type="checkin", owner_id=self.mobile_worker.get_id, update={"username": self.mobile_worker.raw_username}, ) send_to_elasticsearch( "case_search", transform_case_for_elasticsearch(self.checkin_case.to_json())) self.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index) self.case_accessor = CaseAccessors(self.domain)
def edit_form_actions(request, domain, app_id, form_unique_id): app = get_app(domain, app_id) form = app.get_form(form_unique_id) module = form.get_module() old_load_from_form = form.actions.load_from_form form.actions = FormActions.wrap(json.loads(request.POST['actions'])) add_properties_to_data_dictionary(domain, module.case_type, list(form.actions.update_case.update.keys())) if old_load_from_form: form.actions.load_from_form = old_load_from_form for condition in (form.actions.open_case.condition, form.actions.close_case.condition): if isinstance(condition.answer, six.string_types): soft_assert_type_text(condition.answer) condition.answer = condition.answer.strip('"\'') form.requires = request.POST.get('requires', form.requires) if actions_use_usercase(form.actions): if not is_usercase_in_use(domain): enable_usercase(domain) add_properties_to_data_dictionary(domain, USERCASE_TYPE, list(form.actions.usercase_update.update.keys())) response_json = {} app.save(response_json) response_json['propertiesMap'] = get_all_case_properties(app) response_json['usercasePropertiesMap'] = get_usercase_properties(app) return json_response(response_json)
def edit_form_actions(request, domain, app_id, form_unique_id): app = get_app(domain, app_id) form = app.get_form(form_unique_id) module = form.get_module() old_load_from_form = form.actions.load_from_form form.actions = FormActions.wrap(json.loads(request.POST['actions'])) add_properties_to_data_dictionary( domain, module.case_type, list(form.actions.update_case.update.keys())) if old_load_from_form: form.actions.load_from_form = old_load_from_form for condition in (form.actions.open_case.condition, form.actions.close_case.condition): if isinstance(condition.answer, six.string_types): soft_assert_type_text(condition.answer) condition.answer = condition.answer.strip('"\'') form.requires = request.POST.get('requires', form.requires) if actions_use_usercase(form.actions): if not is_usercase_in_use(domain): enable_usercase(domain) add_properties_to_data_dictionary( domain, USERCASE_TYPE, list(form.actions.usercase_update.update.keys())) response_json = {} app.save(response_json) response_json['propertiesMap'] = get_all_case_properties(app) response_json['usercasePropertiesMap'] = get_usercase_properties(app) return json_response(response_json)
def setUpClass(cls): super().setUpClass() delete_all_users() cls.domain_obj = create_domain(cls.domain) enable_usercase(cls.domain) cls.mobile_worker = CommCareUser.create(cls.domain, "username", "p@ssword123", None, None) cls.user_id = cls.mobile_worker.user_id
def edit_advanced_form_actions(request, domain, app_id, module_id, form_id): app = get_app(domain, app_id) form = app.get_module(module_id).get_form(form_id) json_loads = json.loads(request.POST.get('actions')) actions = AdvancedFormActions.wrap(json_loads) form.actions = actions if advanced_actions_use_usercase(form.actions) and not is_usercase_in_use(domain): enable_usercase(domain) response_json = {} app.save(response_json) response_json['propertiesMap'] = get_all_case_properties(app) return json_response(response_json)
def edit_advanced_form_actions(request, domain, app_id, module_id, form_id): app = get_app(domain, app_id) form = app.get_module(module_id).get_form(form_id) json_loads = json.loads(request.POST.get('actions')) actions = AdvancedFormActions.wrap(json_loads) form.actions = actions for action in actions.load_update_cases: add_properties_to_data_dictionary(domain, action.case_type, action.case_properties.keys()) if advanced_actions_use_usercase(form.actions) and not is_usercase_in_use(domain): enable_usercase(domain) response_json = {} app.save(response_json) response_json['propertiesMap'] = get_all_case_properties(app) return json_response(response_json)
def setUp(self): super().setUp() delete_all_users() self.domain_obj = create_domain(self.domain) enable_usercase(self.domain) with trap_extra_setup(ConnectionError): self.es = get_es_new() initialize_index_and_mapping(self.es, CASE_SEARCH_INDEX_INFO) username = normalize_username("mobile_worker_1", self.domain) self.mobile_worker = CommCareUser.create(self.domain, username, "123", None, None) sync_usercases(self.mobile_worker, self.domain)
def edit_form_actions(request, domain, app_id, module_id, form_id): app = get_app(domain, app_id) form = app.get_module(module_id).get_form(form_id) form.actions = FormActions.wrap(json.loads(request.POST['actions'])) for condition in (form.actions.open_case.condition, form.actions.close_case.condition): if isinstance(condition.answer, basestring): condition.answer = condition.answer.strip('"\'') form.requires = request.POST.get('requires', form.requires) if actions_use_usercase(form.actions) and not is_usercase_in_use(domain): enable_usercase(domain) response_json = {} app.save(response_json) response_json['propertiesMap'] = get_all_case_properties(app) response_json['usercasePropertiesMap'] = get_usercase_properties(app) return json_response(response_json)
def edit_advanced_form_actions(request, domain, app_id, form_unique_id): app = get_app(domain, app_id) form = app.get_form(form_unique_id) json_loads = json.loads(request.POST.get('actions')) actions = AdvancedFormActions.wrap(json_loads) if form.form_type == "shadow_form": form.extra_actions = actions else: form.actions = actions for action in actions.load_update_cases: add_properties_to_data_dictionary(domain, action.case_type, list(action.case_properties.keys())) if advanced_actions_use_usercase(actions) and not is_usercase_in_use(domain): enable_usercase(domain) response_json = {} app.save(response_json) response_json['propertiesMap'] = get_all_case_properties(app) return JsonResponse(response_json)
def edit_form_actions(request, domain, app_id, module_id, form_id): app = get_app(domain, app_id) form = app.get_module(module_id).get_form(form_id) old_load_from_form = form.actions.load_from_form form.actions = FormActions.wrap(json.loads(request.POST['actions'])) if old_load_from_form: form.actions.load_from_form = old_load_from_form for condition in (form.actions.open_case.condition, form.actions.close_case.condition): if isinstance(condition.answer, basestring): condition.answer = condition.answer.strip('"\'') form.requires = request.POST.get('requires', form.requires) if actions_use_usercase(form.actions) and not is_usercase_in_use(domain): enable_usercase(domain) response_json = {} app.save(response_json) response_json['propertiesMap'] = get_all_case_properties(app) response_json['usercasePropertiesMap'] = get_usercase_properties(app) return json_response(response_json)