def summary_csv(request): class HttpResponseAccepted(HttpResponse): status_code = 202 if request.method == "GET": if SmSession.objects.get().calculating_summary_csv: return HttpResponseAccepted() elif not DailyControls.objects.all().count() or is_simulation_running(): return HttpResponseBadRequest() elif not os.path.isfile(workspace_path(scenario_filename() + '/' + SUMMARY_FILE_NAME)): return HttpResponseNotFound() else: return HttpResponse() if request.method == "POST": csv_generator = SummaryCSVGenerator() csv_generator.start() # starts a new thread return HttpResponseAccepted() else: return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
def results_context(request): context = {} if not request.is_ajax() and ('results/' in request.path or 'setup/' in request.path): # results specific context session = SmSession.objects.get() context.update({'simulation_has_started': session.simulation_has_started, 'outputs_exist': outputs_exist(), 'results_progress': iteration_progress() * 100,}) try: version = ResultsVersion.objects.all().first().__str__() # singleton doesn't always work on this model (legacy) except: version = "No version available" context.update({ 'is_simulation_running': is_simulation_running(), 'is_simulation_stopped': is_simulation_stopped(), 'iterations_completed': iterations_complete(), 'version_number': version }) context.update(excluded_headers()) return context