def paging(request): # what to show query = request.POST if request.method == "POST" else request.GET search_key = query.get("sSearch", "") show_all = query.get("show", "inbox") == "all" if search_key: if config.LUCENE_ENABLED: return lucene_search(request, search_key, show_all) view_name = "couchlog/all_by_msg" if show_all else "couchlog/inbox_by_msg" search = True else: view_name = "couchlog/all_by_date" if show_all else "couchlog/inbox_by_date" search = False def wrapper_func(row): """ Given a row of the view, get out an exception record """ error = ExceptionRecord.wrap(row["doc"]) return _record_to_json(error) paginator = CouchPaginator(view_name, wrapper_func, search=search, view_args={"include_docs": True}, database=ExceptionRecord.get_db()) # get our previous start/end keys if necessary # NOTE: we don't actually do anything with these yet, but we should for # better pagination down the road. using the "skip" parameter is not # super efficient. startkey = query.get("startkey", None) if startkey: startkey = json.loads(startkey) endkey = query.get("endkey", None) if endkey: endkey = json.loads(endkey) total_records = _couchlog_count() return paginator.get_ajax_response(request, extras={"startkey": startkey, "endkey": endkey, "iTotalRecords": total_records})
def paging_identified(request): """ Paging view, used by datatables url """ def wrapper_func(row): """ Given a row of the view, get out a json representation of a patient row """ patient = CPatient.wrap(row["doc"]) return [patient.get_id, patient.formatted_id, patient.first_name, patient.last_name, patient.gender, patient.birthdate.strftime("%Y-%m-%d") if patient.birthdate else "", patient.current_clinic_display] paginator = CouchPaginator(VIEW_PATIENT_BY_LAST_NAME, wrapper_func, search=True, search_preprocessor=lambda x: x.lower(), view_args={"include_docs": True}) return paginator.get_ajax_response(request)
def paging(request): """ Paging view, used by datatables url """ def wrapper_func(row): """ Given a row of the view, get out a json representation of a patient row """ patient = CPatient.wrap(row["doc"]) return [patient.get_id, patient.formatted_id, patient.gender, patient.birthdate.strftime("%Y-%m-%d") if patient.birthdate else "", patient.current_clinic_display] def id_formatter(id): """Strips any non-digits before processing the id""" return "".join(re.findall("\d+", id)) paginator = CouchPaginator(VIEW_PATIENT_BY_BHOMA_ID, wrapper_func, search=True, search_preprocessor=id_formatter, view_args={"include_docs": True}) return paginator.get_ajax_response(request)