docs: def calc_result(request, result_id):
      """
      Download a specific result, by ``result_id``.
  
      The common abstracted functionality for getting hazard or risk results.
  
      :param request:
          `django.http.HttpRequest` object. Can contain a `export_type` GET
          param (the default is 'xml' if no param is specified).
      :param result_id:
          The id of the requested artifact.
      :returns:
          If the requested ``result_id`` is not available in the format
          designated by the `export_type`.
  
          Otherwise, return a `django.http.HttpResponse` containing the content
          of the requested artifact.
  
      Parameters for the GET request can include an `export_type`, such as 'xml',
      'geojson', 'csv', etc.
      """
      # If the result for the requested ID doesn't exist, OR
      # the job which it is related too is not complete,
      # throw back a 404.
      try:
          job_id, job_status, job_user, datadir, ds_key = logs.dbcmd(
              'get_result', result_id)
          if not utils.user_has_permission(request, job_user):
              return HttpResponseForbidden()
      except dbapi.NotFound:
          return HttpResponseNotFound()
  
      etype = request.GET.get('export_type')
      export_type = etype or DEFAULT_EXPORT_TYPE
  
      tmpdir = tempfile.mkdtemp()
      try:
          exported = core.export_from_db(
              (ds_key, export_type), job_id, datadir, tmpdir)
      except DataStoreExportError as exc:
          # TODO: there should be a better error page
          return HttpResponse(content='%s: %s' % (exc.__class__.__name__, exc),
                              content_type='text/plain', status=500)
      if not exported:
          # Throw back a 404 if the exact export parameters are not supported
          return HttpResponseNotFound(
              'Nothing to export for export_type=%s, %s' % (export_type, ds_key))
      elif len(exported) > 1:
          # Building an archive so that there can be a single file download
          archname = ds_key + '-' + export_type + '.zip'
          zipfiles(exported, os.path.join(tmpdir, archname))
          exported = os.path.join(tmpdir, archname)
      else:  # single file
          exported = exported[0]
  
      content_type = EXPORT_CONTENT_TYPE_MAP.get(
          export_type, DEFAULT_CONTENT_TYPE)
  
      fname = 'output-%s-%s' % (result_id, os.path.basename(exported))
      stream = FileWrapper(open(exported, 'rb'))  # 'b' is needed on Windows
      stream.close = lambda: (
          FileWrapper.close(stream), shutil.rmtree(tmpdir))
      response = FileResponse(stream, content_type=content_type)
      response['Content-Disposition'] = (
          'attachment; filename=%s' % os.path.basename(fname))
      response['Content-Length'] = str(os.path.getsize(exported))
      return response