def filter_cases(request, domain, app_id, module_id): app = Application.get(app_id) module = app.get_module(module_id) delegation = request.GET.get('task-list') == 'true' auth_cookie = request.COOKIES.get('sessionid') xpath = SuiteGenerator(app).get_filter_xpath(module, delegation=delegation) # touchforms doesn't like this to be escaped xpath = HTMLParser.HTMLParser().unescape(xpath) if delegation: case_type = DELEGATION_STUB_CASE_TYPE else: case_type = module.case_type if xpath: # if we need to do a custom filter, send it to touchforms for processing additional_filters = { "properties/case_type": case_type, "footprint": True } result = touchforms_api.filter_cases(domain, request.couch_user, xpath, additional_filters, auth=DjangoAuth(auth_cookie)) if result.get('status', None) == 'error': return HttpResponseServerError( result.get("message", _("Something went wrong filtering your cases."))) case_ids = result.get("cases", []) else: # otherwise just use our built in api with the defaults case_ids = [ res.id for res in get_filtered_cases(domain, status=CASE_STATUS_OPEN, case_type=case_type, user_id=request.couch_user._id, footprint=True, ids_only=True) ] cases = [CommCareCase.get(id) for id in case_ids] # refilter these because we might have accidentally included footprint cases # in the results from touchforms. this is a little hacky but the easiest # (quick) workaround. should be revisted when we optimize the case list. cases = filter(lambda c: c.type == case_type, cases) cases = [c.get_json() for c in cases if c] parents = [] if delegation: for case in cases: parent_id = case['indices']['parent']['case_id'] parents.append(CommCareCase.get(parent_id)) return json_response({'cases': cases, 'parents': parents}) else: return json_response(cases)
def filter_cases(request, domain, app_id, module_id): app = Application.get(app_id) module = app.get_module(module_id) delegation = request.GET.get('task-list') == 'true' auth_cookie = request.COOKIES.get('sessionid') xpath = SuiteGenerator(app).get_filter_xpath(module, delegation=delegation) # touchforms doesn't like this to be escaped xpath = HTMLParser.HTMLParser().unescape(xpath) if delegation: case_type = DELEGATION_STUB_CASE_TYPE else: case_type = module.case_type if xpath: # if we need to do a custom filter, send it to touchforms for processing additional_filters = { "properties/case_type": case_type, "footprint": True } result = touchforms_api.filter_cases(domain, request.couch_user, xpath, additional_filters, auth=DjangoAuth(auth_cookie)) if result.get('status', None) == 'error': return HttpResponseServerError( result.get("message", _("Something went wrong filtering your cases."))) case_ids = result.get("cases", []) else: # otherwise just use our built in api with the defaults case_ids = [res.id for res in get_filtered_cases( domain, status=CASE_STATUS_OPEN, case_type=case_type, user_id=request.couch_user._id, ids_only=True )] cases = [CommCareCase.wrap(doc) for doc in iter_docs(CommCareCase.get_db(), case_ids)] # refilter these because we might have accidentally included footprint cases # in the results from touchforms. this is a little hacky but the easiest # (quick) workaround. should be revisted when we optimize the case list. cases = filter(lambda c: c.type == case_type, cases) cases = [c.get_json(lite=True) for c in cases if c] parents = [] if delegation: for case in cases: parent_id = case['indices']['parent']['case_id'] parents.append(CommCareCase.get(parent_id)) return json_response({ 'cases': cases, 'parents': parents }) else: return json_response(cases)
def filter_cases(request, domain, app_id, module_id): app = Application.get(app_id) module = app.get_module(module_id) auth_cookie = request.COOKIES.get('sessionid') details = module.details xpath_parts = [] for detail in details: if detail.filter_xpath_2(): xpath_parts.append(detail.filter_xpath_2()) xpath = "".join(xpath_parts) # touchforms doesn't like this to be escaped xpath = HTMLParser.HTMLParser().unescape(xpath) additional_filters = {"properties/case_type": module.case_type } result = touchforms_api.filter_cases(domain, request.couch_user, xpath, additional_filters, auth=DjangoAuth(auth_cookie)) case_ids = result.get("cases", []) cases = [CommCareCase.get(id) for id in case_ids] cases = [c.get_json() for c in cases if c] return json_response(cases)
def filter_cases(request, domain, app_id, module_id): app = Application.get(app_id) module = app.get_module(module_id) delegation = request.GET.get('task-list') == 'true' auth_cookie = request.COOKIES.get('sessionid') xpath = SuiteGenerator(app).get_filter_xpath(module, delegation=delegation) # touchforms doesn't like this to be escaped xpath = HTMLParser.HTMLParser().unescape(xpath) if delegation: case_type = DELEGATION_STUB_CASE_TYPE else: case_type = module.case_type additional_filters = { "properties/case_type": case_type, "footprint": True } result = touchforms_api.filter_cases(domain, request.couch_user, xpath, additional_filters, auth=DjangoAuth(auth_cookie)) if result.get('status', None) == 'error': return HttpResponseServerError( result.get("message", _("Something went wrong filtering your cases."))) case_ids = result.get("cases", []) cases = [CommCareCase.get(id) for id in case_ids] cases = [c.get_json() for c in cases if c] parents = [] if delegation: for case in cases: parent_id = case['indices']['parent']['case_id'] parents.append(CommCareCase.get(parent_id)) return json_response({ 'cases': cases, 'parents': parents }) else: return json_response(cases)