def prepare_form_multimedia(self, in_data): """Gets the download_id for the multimedia zip and sends it to the exportDownloadService in download_export.ng.js to begin polling for the zip file download. """ try: filter_form_data, export_specs = self._get_form_data_and_specs(in_data) filter_form = FilterFormExportDownloadForm( self.domain_object, self.timezone, filter_form_data ) if not filter_form.is_valid(): raise ExportFormValidationException( _("Please check that you've submitted all required filters.") ) download = DownloadBase() export_object = self.get_export_schema(self.domain, export_specs[0]['export_id']) task_kwargs = filter_form.get_multimedia_task_kwargs( export_object, download.download_id ) from corehq.apps.reports.tasks import build_form_multimedia_zip download.set_task(build_form_multimedia_zip.delay(**task_kwargs)) except Exception as e: return format_angular_error(e) return format_angular_success({ 'download_id': download.download_id, })
def update_emailed_export_data(self, in_data): group_id = in_data["component"]["groupId"] relevant_group = filter(lambda g: g.get_id, self.emailed_export_groups)[0] indexes = map(lambda x: x[0].index, relevant_group.all_exports) place_index = indexes.index(in_data["component"]["index"]) rebuild_export_task.delay(group_id, place_index) return format_angular_success({})
def prepare_custom_export(self, in_data): """Uses the current exports download framework (with some nasty filters) to return the current download id to POLL for the download status. :param in_data: dict passed by the angular js controller. :return: { 'success': True, 'download_id': '<some uuid>', } """ try: export_filter, export_specs = self._process_filters_and_specs(in_data) if len(export_specs) > 1: download = self._get_bulk_download_task(export_specs, export_filter) else: max_column_size = int(in_data.get('max_column_size', 2000)) download = self._get_download_task( export_specs, export_filter, max_column_size ) except ExportAsyncException as e: return format_angular_error(e.message) except Exception as e: return format_angular_error( e.message, log_error=True, exception=e, ) return format_angular_success({ 'download_id': download.download_id, })
def get_app_data_drilldown_values(self, in_data): try: rmi_helper = ApplicationDataRMIHelper(self.domain) response = rmi_helper.get_case_rmi_response() except Exception as e: return format_angular_error( _("Problem getting Create Export Form: {}").format(e.message), log_error=True, exception=e ) return format_angular_success(response)
def get_app_data_drilldown_values(self, in_data): if self.is_deid: raise Http404() try: rmi_helper = ApplicationDataRMIHelper(self.domain) response = rmi_helper.get_form_rmi_response() except Exception as e: return format_angular_error(_("Problem getting Create Export Form: {} {}").format(e.__class__, e)) return format_angular_success(response)
def get_group_options(self, in_data): """Returns list of groups for the group filters :param in_data: dict passed by the angular js controller. :return: { 'success': True, 'groups': [<..list of groups..>], } """ groups = map(lambda g: {"id": g._id, "text": g.name}, Group.get_reporting_groups(self.domain)) return format_angular_success({"groups": groups})
def has_multimedia(self, in_data): """Checks to see if this form export has multimedia available to export """ try: size_hash = get_attachment_size_by_domain_app_id_xmlns(self.domain) export_object = self.get_export_schema(self.domain, self.export_id) hash_key = (export_object.app_id, export_object.xmlns if hasattr(export_object, "xmlns") else "") has_multimedia = hash_key in size_hash except Exception as e: return format_angular_error(e.message) return format_angular_success({"hasMultimedia": has_multimedia})
def submit_app_data_drilldown_form(self, in_data): if self.is_deid: raise Http404() try: form_data = in_data["formData"] except KeyError: return format_angular_error(_("The form's data was not correctly formatted.")) try: create_url = self.get_create_export_url(form_data) except ExportFormValidationException: return format_angular_error(_("The form did not validate.")) except Exception as e: return format_angular_error(_("Problem getting link to custom export form: {}").format(e)) return format_angular_success({"url": create_url})
def prepare_custom_export(self, in_data): """Uses the current exports download framework (with some nasty filters) to return the current download id to POLL for the download status. :param in_data: dict passed by the angular js controller. :return: { 'success': True, 'download_id': '<some uuid>', } """ try: download = self._get_download_task(in_data) except ExportAsyncException as e: return format_angular_error(e.message) except Exception as e: return format_angular_error(e.message, log_error=True, exception=e) return format_angular_success({"download_id": download.download_id})
def get_exports_list(self, in_data): """Called by the ANGULAR.JS controller ListExports controller in exports/list_exports.ng.js on initialization of that controller. :param in_data: dict passed by the angular js controller. :return: { 'success': True, 'exports': map(self.fmt_export_data, self.get_saved_exports()), } """ try: saved_exports = self.get_saved_exports() if self.is_deid: saved_exports = filter(lambda x: x.is_safe, saved_exports) saved_exports = map(self.fmt_export_data, saved_exports) except Exception as e: return format_angular_error(_("Issue fetching list of exports: {}").format(e), log_error=True, exception=e) return format_angular_success({"exports": saved_exports})