Created
December 2, 2015 15:09
-
-
Save igniteflow/82de4c30550857050af0 to your computer and use it in GitHub Desktop.
Django scribble for when you want to simulate a job progress checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.cache import cache | |
# inside get() or your view function | |
cache_key = 'dummy-csv-export-status' | |
dummy_data = cache.get(cache_key) | |
if not dummy_data: | |
dummy_data = ['ready'] + ['processing' for i in range(9)] | |
cache.set(cache_key, dummy_data) | |
if request.is_ajax(): | |
context_data = json.dumps({'status': dummy_data.pop()}) | |
cache.set(cache_key, dummy_data) | |
return HttpResponse( | |
context_data, | |
content_type='application/json' | |
) | |
else: | |
return HttpResponseForbidden() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment