def tasks( request ): """Show pending/successful/failed tasks; UI for dismissing tasks. """ # add start datetime to tasks list celery_tasks = session_tasks_list(request) for task in celery_tasks: task['startd'] = datetime.strptime(task['start'], settings.TIMESTAMP_FORMAT) if request.method == 'POST': form = TaskDismissForm(request.POST, celery_tasks=celery_tasks) if form.is_valid(): for task in celery_tasks: fieldname = 'dismiss_%s' % task['task_id'] if (fieldname in form.cleaned_data.keys()) and form.cleaned_data[fieldname]: dismiss_session_task(request, task['task_id']) # redirect redirect_uri = form.cleaned_data['next'] if not redirect_uri: redirect_uri = reverse('webui-index') return HttpResponseRedirect(redirect_uri) else: data = { 'next': request.GET.get('next',None), } form = TaskDismissForm(data, celery_tasks=celery_tasks) dismissable_tasks = [1 for task in celery_tasks if task['dismissable']] return render_to_response( 'webui/tasks.html', {'form': form, 'celery_tasks': celery_tasks, 'dismissable_tasks': dismissable_tasks, 'hide_celery_tasks': True,}, context_instance=RequestContext(request, processors=[]) )
def task_dismiss( request, task_id ): dismiss_session_task(request, task_id) data = {'status':'ok'} return HttpResponse(json.dumps(data), content_type="application/json")