Rename HttpResponse parameter mimetype to content_type
[htsworkflow.git] / htsworkflow / frontend / experiments / experiments.py
index 1ccba526adb75272273985c0095db2361e09d40f..e9bb3151a23330b72f80c7773ab052795abec178 100644 (file)
@@ -9,11 +9,12 @@ import os
 import re
 
 from django.contrib.auth.decorators import login_required
-from django.contrib.csrf.middleware import csrf_exempt
+from django.views.decorators.csrf import csrf_exempt
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.mail import send_mail, mail_admins
 from django.http import HttpResponse, Http404
 from django.conf import settings
+from django.utils import timezone
 
 from htsworkflow.frontend.auth import require_api_key
 from htsworkflow.frontend.experiments.models import \
@@ -92,7 +93,7 @@ def flowcell_json(request, fc_id):
         raise Http404
 
     fc_json = json.dumps(fc_dict)
-    return HttpResponse(fc_json, mimetype = 'application/json')
+    return HttpResponse(fc_json, content_type = 'application/json')
 
 def lanes_for(username=None):
     """
@@ -134,7 +135,7 @@ def lanes_for_json(request, username):
     #convert query set to python structure
 
     result_json = json.dumps(result)
-    return HttpResponse(result_json, mimetype='application/json')
+    return HttpResponse(result_json, content_type='application/json')
 
 
 def updStatus(request):
@@ -179,7 +180,7 @@ def updStatus(request):
       rec.run_status = UpdatedStatus
 
       #if there's a message update that too
-      mytimestamp = datetime.now().__str__()
+      mytimestamp = timezone.now().__str__()
       mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
       if request.REQUEST.has_key('msg'):
         rec.run_note += ", "+request.REQUEST['msg']+" ("+mytimestamp+")"
@@ -259,7 +260,7 @@ def getConfile(req):
         except ObjectDoesNotExist:
           cnfgfile = 'Entry not found for RunFolder = '+runfolder
 
-    return HttpResponse(cnfgfile, mimetype='text/plain')
+    return HttpResponse(cnfgfile, content_type='text/plain')
 
 def getLaneLibs(req):
     granted = False
@@ -300,23 +301,18 @@ def getLaneLibs(req):
         outputfile = 'Flowcell entry not found for: '+fcid
     else: outputfile = 'Missing input: flowcell id'
 
-    return HttpResponse(outputfile, mimetype='text/plain')
+    return HttpResponse(outputfile, content_type='text/plain')
 
 def estimateFlowcellDuration(flowcell):
     """
     Attempt to estimate how long it will take to run a flowcell
 
     """
-    # (3600 seconds * 1.5 hours per cycle )
-    sequencing_seconds_per_cycle= 3600 * 1.5
-    # 800 is a rough guess
-    pipeline_seconds_per_cycle = 800
-
     cycles = flowcell.read_length
     if flowcell.paired_end:
         cycles *= 2
-    sequencing_time = timedelta(0, cycles * sequencing_seconds_per_cycle)
-    analysis_time = timedelta(0, cycles * pipeline_seconds_per_cycle)
+    sequencing_time = timedelta(0, cycles * flowcell.flowcell_model.per_cycle_time)
+    analysis_time = timedelta(0, flowcell.flowcell_model.fixed_time)
     estimate_mid = sequencing_time + analysis_time
 
     return estimate_mid
@@ -325,7 +321,7 @@ def estimateFlowcellTimeRemaining(flowcell):
     estimate_mid = estimateFlowcellDuration(flowcell)
 
     # offset for how long we've been running
-    running_time = datetime.now() - flowcell.run_date
+    running_time = timezone.now() - flowcell.run_date
     estimate_mid -= running_time
 
     return estimate_mid