Provides a process for downloading files generated by celery tasks asynchronously.
Currently this includes templates that use a bootstrap2 modal and progress bar along with jquery to poll for the result but feel free to override those with your own.
Useful for excel or PDF exports.
pip install
from the repo. not on pypi, yet.
INSTALLED_APPS = (
...
django_celery_downloader
...
)
django-celery
The demo_app
in the source is a useful example, but here are the basics.
Let's assume you have already created a celery task to create a report:
build_report
Create a view to trigger the task and render the content of the modal by
extending StartExportView
:
from my_project.app.tasks import build_report
from django_celery_downloader.views import StartExportView
class ReportExcelModalView(StartExportView):
export_method = build_report ## the task to run
download_url_name = "download_report"
def get_task_params(self):
return self.kwargs['rows']
If you want to use the built-in bootstrap2 modal helper, include the following on the page you want to trigger the download from:
<a
class='djangoAsyncDownloadModal-link btn btn-success'
href="{% url report_modal 5 %}">
Click here to open the modal
</a>
{% include "django_celery_downloader/modal_helper.html" %}
Or, if you're not using a modal, simply include a link to your
DownloadExportView
as described below and override the wait_task.html
template.
Your modal/page will just hang around and show a loading bar until you task
completes. Once it's ready, the modal will display a download button that will
link to another view you have to create that extends DownloadExportView
:
from django_celery_downloader.views import DownloadExportView
class ReportExcelDownloadView(DownloadExportView):
mimetype = 'text/csv'
extension = "csv"
def get_filename(self):
return "My_Fancy_Report"
- this serves the file through django, it might make sense to use a redirect to ensure that this gets served with another server in some cases
- it would be cool to include other helper templates for bootstrap3 and standalone pages
MIT License