Beispiel #1
0
 def poll_custom_export_download(self, in_data):
     """Polls celery to see how the export download task is going.
     :param in_data: dict passed by the  angular js controller.
     :return: final response: {
         'success': True,
         'dropbox_url': '<url>',
         'download_url: '<url>',
         <task info>
     }
     """
     try:
         download_id = in_data["download_id"]
     except KeyError:
         return format_angular_error(_("Requires a download id"))
     try:
         context = get_download_context(download_id, check_state=True)
     except TaskFailedError:
         return format_angular_error(
             _("Download Task Failed to Start. It seems that the server " "might be under maintenance.")
         )
     if context.get("is_ready", False):
         context.update(
             {
                 "dropbox_url": reverse("dropbox_upload", args=(download_id,)),
                 "download_url": "{}?get_file".format(reverse("retrieve_download", args=(download_id,))),
             }
         )
     context["is_poll_successful"] = True
     return context
Beispiel #2
0
 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,
     })
Beispiel #3
0
 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})
Beispiel #4
0
 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})
Beispiel #5
0
 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,
     })
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 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})
Beispiel #9
0
 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})