code: def calc_run(request):
      
      hazard_job_id = request.POST.get('hazard_job_id')
  
      if hazard_job_id:
          hazard_job_id = int(hazard_job_id)
          candidates = ("job_risk.ini", "job.ini")
      else:
          candidates = ("job_hazard.ini", "job_haz.ini", "job.ini")
      result = safely_call(_prepare_job, (request, candidates))
      if result.tb_str:
          return HttpResponse(json.dumps(result.tb_str.splitlines()),
                              content_type=JSON, status=500)
      inifiles = result.get()
      if not inifiles:
          msg = 'Could not find any file of the form %s' % str(candidates)
          logging.error(msg)
          return HttpResponse(content=json.dumps([msg]), content_type=JSON,
                              status=500)
  
      user = utils.get_user(request)
      try:
          job_id, pid = submit_job(inifiles[0], user, hazard_job_id)
      except Exception as exc:  # no job created, for instance missing .xml file
          # get the exception message
          exc_msg = str(exc)
          logging.error(exc_msg)
          response_data = exc_msg.splitlines()
          status = 500
      else:
          response_data = dict(job_id=job_id, status='created', pid=pid)
          status = 200
      return HttpResponse(content=json.dumps(response_data), content_type=JSON,
                          status=status)
docs: Run a calculation.
  
      :param request:
          a `django.http.HttpRequest` object.
          If the request has the attribute `hazard_job_id`, the results of the
          specified hazard calculations will be re-used as input by the risk
          calculation.
          The request also needs to contain the files needed to perform the
          calculation. They can be uploaded as separate files, or zipped
          together.