def prepare_form_multimedia(request, domain): """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. """ form_or_case = request.POST.get('form_or_case') sms_export = json.loads(request.POST.get('sms_export')) permissions = ExportsPermissionsManager(form_or_case, domain, request.couch_user) permissions.access_download_export_or_404() view_helper = DownloadExportViewHelper.get(request, domain, form_or_case, sms_export) filter_form_data = json.loads(request.POST.get('form_data')) export_specs = json.loads(request.POST.get('exports')) try: filter_form = view_helper.get_filter_form(filter_form_data) except ExportFormValidationException: return JsonResponse({ 'error': _("Please check that you've submitted all required filters."), }) download = DownloadBase() export_object = view_helper.get_export(export_specs[0]['export_id']) task_kwargs = filter_form.get_multimedia_task_kwargs( export_object, download.download_id, filter_form_data) from corehq.apps.reports.tasks import build_form_multimedia_zip download.set_task(build_form_multimedia_zip.delay(**task_kwargs)) return JsonResponse({ 'success': True, 'download_id': download.download_id, })
def prepare_form_multimedia(request, domain): """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. """ form_or_case = request.POST.get('form_or_case') sms_export = json.loads(request.POST.get('sms_export')) permissions = ExportsPermissionsManager(form_or_case, domain, request.couch_user) permissions.access_download_export_or_404() view_helper = DownloadExportViewHelper.get(request, domain, form_or_case, sms_export) filter_form_data = json.loads(request.POST.get('form_data')) export_specs = json.loads(request.POST.get('exports')) try: filter_form = view_helper.get_filter_form(filter_form_data) except ExportFormValidationException: return json_response({ 'error': _("Please check that you've submitted all required filters."), }) download = DownloadBase() export_object = view_helper.get_export(export_specs[0]['export_id']) task_kwargs = filter_form.get_multimedia_task_kwargs(export_object, download.download_id, filter_form_data) from corehq.apps.reports.tasks import build_form_multimedia_zip download.set_task(build_form_multimedia_zip.delay(**task_kwargs)) return json_response({ 'success': True, 'download_id': download.download_id, })
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 prepare_form_multimedia(request, domain): """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. """ form_or_case = request.POST.get('form_or_case') sms_export = json.loads(request.POST.get('sms_export')) permissions = ExportsPermissionsManager(form_or_case, domain, request.couch_user) permissions.access_download_export_or_404() view_helper = DownloadExportViewHelper.get(request, domain, form_or_case, sms_export) filter_form_data = json.loads(request.POST.get('form_data')) export_specs = json.loads(request.POST.get('exports')) try: filter_form = view_helper.get_filter_form(filter_form_data) except ExportFormValidationException: return json_response({ 'error': _("Please check that you've submitted all required filters."), }) export = view_helper.get_export(export_specs[0]['export_id']) datespan = filter_form.cleaned_data['date_range'] user_types = filter_form.get_es_user_types(filter_form_data) if media_export_is_too_big(domain, export.app_id, export.xmlns, datespan, user_types): return json_response({ 'success': False, 'error': _("This is too many files to export at once. " "Please modify your filters to select fewer forms."), }) download = DownloadBase() download.set_task( build_form_multimedia_zip.delay( domain=domain, export_id=export.get_id, datespan=datespan, user_types=user_types, download_id=download.download_id, owner_id=request.couch_user.get_id, )) return json_response({ 'success': True, 'download_id': download.download_id, })