def export_data(req, domain): """ Download all data for a couchdbkit model """ try: export_tag = json.loads(req.GET.get("export_tag", "null") or "null") except ValueError: return HttpResponseBadRequest() group, users = util.get_group_params(domain, **json_request(req.GET)) include_errors = string_to_boolean(req.GET.get("include_errors", False)) kwargs = { "format": req.GET.get("format", Format.XLS_2007), "previous_export_id": req.GET.get("previous_export", None), "filename": export_tag, "use_cache": string_to_boolean(req.GET.get("use_cache", "True")), "max_column_size": int(req.GET.get("max_column_size", 2000)), "separator": req.GET.get("separator", "|") } user_filter, _ = UserTypeFilter.get_user_filter(req) if user_filter: filtered_users = users_matching_filter(domain, user_filter) def _ufilter(user): try: return user['form']['meta']['userID'] in filtered_users except KeyError: return False filter = _ufilter else: filter = SerializableFunction(util.group_filter, group=group) errors_filter = instances if not include_errors else None kwargs['filter'] = couchexport.util.intersect_functions( filter, errors_filter) if kwargs['format'] == 'raw': resp = export_raw_data([domain, export_tag], filename=export_tag) else: try: resp = export_data_shared([domain, export_tag], **kwargs) except CouchExportException as e: return HttpResponseBadRequest(e) if resp: return resp else: messages.error( req, "Sorry, there was no data found for the tag '%s'." % export_tag) next = req.GET.get("next", "") if not next: next = export.ExcelExportReport.get_url(domain=domain) return HttpResponseRedirect(next)
def export_data(req, domain): """ Download all data for a couchdbkit model """ try: export_tag = json.loads(req.GET.get("export_tag", "null") or "null") except ValueError: return HttpResponseBadRequest() group, users = util.get_group_params(domain, **json_request(req.GET)) include_errors = string_to_boolean(req.GET.get("include_errors", False)) kwargs = { "format": req.GET.get("format", Format.XLS_2007), "previous_export_id": req.GET.get("previous_export", None), "filename": export_tag, "use_cache": string_to_boolean(req.GET.get("use_cache", "True")), "max_column_size": int(req.GET.get("max_column_size", 2000)), "separator": req.GET.get("separator", "|"), } user_filter, _ = UserTypeFilter.get_user_filter(req) if user_filter: filtered_users = users_matching_filter(domain, user_filter) def _ufilter(user): try: return user["form"]["meta"]["userID"] in filtered_users except KeyError: return False filter = _ufilter else: filter = SerializableFunction(util.group_filter, group=group) errors_filter = instances if not include_errors else None kwargs["filter"] = couchexport.util.intersect_functions(filter, errors_filter) if kwargs["format"] == "raw": resp = export_raw_data([domain, export_tag], filename=export_tag) else: try: resp = export_data_shared([domain, export_tag], **kwargs) except CouchExportException as e: return HttpResponseBadRequest(e) if resp: return resp else: messages.error(req, "Sorry, there was no data found for the tag '%s'." % export_tag) next = req.GET.get("next", "") if not next: next = export.ExcelExportReport.get_url(domain=domain) return HttpResponseRedirect(next)
def export_data(req, domain): """ Download all data for a couchdbkit model """ try: export_tag = json.loads(req.GET.get("export_tag", "null") or "null") except ValueError: return HttpResponseBadRequest() group, users = util.get_group_params(domain, **json_request(req.GET)) include_errors = string_to_boolean(req.GET.get("include_errors", False)) kwargs = {"format": req.GET.get("format", Format.XLS_2007), "previous_export_id": req.GET.get("previous_export", None), "filename": export_tag, "use_cache": string_to_boolean(req.GET.get("use_cache", "True")), "max_column_size": int(req.GET.get("max_column_size", 2000)), "separator": req.GET.get("separator", "|")} user_filter, _ = FilterUsersField.get_user_filter(req) if user_filter: users_matching_filter = map(lambda x: x.get('user_id'), get_all_users_by_domain(domain, user_filter=user_filter, simplified=True)) def _ufilter(user): try: return user['form']['meta']['userID'] in users_matching_filter except KeyError: return False filter = _ufilter else: filter = SerializableFunction(util.group_filter, group=group) errors_filter = instances if not include_errors else None kwargs['filter'] = couchexport.util.intersect_functions(filter, errors_filter) if kwargs['format'] == 'raw': resp = export_raw_data([domain, export_tag], filename=export_tag) else: try: resp = export_data_shared([domain,export_tag], **kwargs) except UnsupportedExportFormat as e: return HttpResponseBadRequest(e) if resp: return resp else: messages.error(req, "Sorry, there was no data found for the tag '%s'." % export_tag) next = req.GET.get("next", "") if not next: next = export.ExcelExportReport.get_url(domain) return HttpResponseRedirect(next)