1
2 from django.http import HttpResponse
3 from madrona.features.views import get_object_for_viewing
4 from madrona.analysistools.models import Analysis
5 from madrona.common import default_mimetypes as mimetypes
6 from django.utils import simplejson
7 from django.shortcuts import render_to_response
8
9 from django.views.decorators.cache import never_cache
10
11 @never_cache
12 -def progress(request, uid):
13 instance = get_object_for_viewing(request, uid)
14 if isinstance(instance, HttpResponse):
15 return instance
16
17 if issubclass(instance.__class__, Analysis):
18 p = instance.progress
19 progress = {
20 'uid': instance.uid,
21 'complete': p[0],
22 'total': p[1],
23 'html': instance.status_html,
24 'error': 0
25 }
26 if 'error' in instance.status_html.lower():
27 progress['error'] = 1
28 res = HttpResponse(simplejson.dumps(progress))
29 res['Content-Type'] = mimetypes.JSON
30 return res
31
32 return HttpResponse("%s is not an analysis!" % (instance), status=500)
33
35 instance = get_object_for_viewing(request, uid)
36 if isinstance(instance, HttpResponse):
37 return instance
38
39 if issubclass(instance.__class__, Analysis):
40 p = instance.progress
41 progress = {
42 'complete': p[0],
43 'total': p[1],
44 'done': p[1] == p[0],
45 'uid': instance.uid,
46 'name': instance.name,
47 'html': instance.status_html
48 }
49 return render_to_response('analysis/progress.html', {'progress': progress})
50
51 return HttpResponse("%s is not an analysis!" % (instance), status=500)
52