def process_document_uploads(personalisation_data, service, simulated, template_id): file_keys = [k for k, v in (personalisation_data or {}).items() if isinstance(v, dict) and "file" in v] if not file_keys: return personalisation_data personalisation_data = personalisation_data.copy() check_service_has_permission(UPLOAD_DOCUMENT, authenticated_service.permissions) for key in file_keys: if simulated: personalisation_data[key] = document_download_client.get_upload_url(service.id) + "/test-document" else: try: personalisation_data[key] = document_download_client.upload_document(service.id, personalisation_data[key]) except DocumentDownloadError as e: raise BadRequestError(message=e.message, status_code=e.status_code) if not simulated: save_stats_for_attachments( [v for k, v in personalisation_data.items() if k in file_keys], service.id, template_id, ) return personalisation_data
def process_document_uploads(personalisation_data, service, simulated=False): file_keys = [ k for k, v in (personalisation_data or {}).items() if isinstance(v, dict) and 'file' in v ] if not file_keys: return personalisation_data personalisation_data = personalisation_data.copy() check_service_has_permission(UPLOAD_DOCUMENT, authenticated_service.permissions) for key in file_keys: if simulated: personalisation_data[ key] = document_download_client.get_upload_url( service.id) + '/test-document' else: try: personalisation_data[ key] = document_download_client.upload_document( service.id, personalisation_data[key]['file']) except DocumentDownloadError as e: raise BadRequestError(message=e.message, status_code=e.status_code) return personalisation_data
def process_document_uploads(personalisation_data, service, simulated=False): """ Returns modified personalisation dict and a count of document uploads. If there are no document uploads, returns a count of `None` rather than `0`. """ file_keys = [ k for k, v in (personalisation_data or {}).items() if isinstance(v, dict) and 'file' in v ] if not file_keys: return personalisation_data, None personalisation_data = personalisation_data.copy() check_if_service_can_send_files_by_email( service_contact_link=authenticated_service.contact_link, service_id=authenticated_service.id) for key in file_keys: if simulated: personalisation_data[ key] = document_download_client.get_upload_url( service.id) + '/test-document' else: try: personalisation_data[ key] = document_download_client.upload_document( service.id, personalisation_data[key]['file']) except DocumentDownloadError as e: raise BadRequestError(message=e.message, status_code=e.status_code) return personalisation_data, len(file_keys)