Initial port to python3
[htsworkflow.git] / htsworkflow / frontend / experiments / experiments.py
old mode 100755 (executable)
new mode 100644 (file)
index 3cdbc7b..b9d1966
@@ -2,13 +2,14 @@
 from datetime import datetime, timedelta
 try:
     import json
-except ImportError, e:
+except ImportError as e:
     import simplejson as json
 
 import os
 import re
 
 from django.contrib.auth.decorators import login_required
+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
@@ -28,7 +29,7 @@ def flowcell_information(flowcell_id):
     """
     try:
         fc = FlowCell.objects.get(flowcell_id__startswith=flowcell_id)
-    except FlowCell.DoesNotExist, e:
+    except FlowCell.DoesNotExist as e:
         return None
 
     lane_set = {}
@@ -43,7 +44,7 @@ def flowcell_information(flowcell_id):
             'library_name': lane.library.library_name,
             'library_id': lane.library.id,
             'library_species': lane.library.library_species.scientific_name,
-            'pM': unicode(lane.pM),
+            'pM': str(lane.pM),
             'read_length': lane.flowcell.read_length,
             'status_code': lane.status,
             'status': LANE_STATUS_MAP[lane.status]
@@ -78,6 +79,7 @@ def flowcell_information(flowcell_id):
 
     return info
 
+@csrf_exempt
 def flowcell_json(request, fc_id):
     """
     Return a JSON blob containing enough information to generate a config file.
@@ -117,6 +119,7 @@ def lanes_for(username=None):
                         'affiliations': affiliations_list})
     return result
 
+@csrf_exempt
 def lanes_for_json(request, username):
     """
     Format lanes for a user
@@ -125,7 +128,7 @@ def lanes_for_json(request, username):
 
     try:
         result = lanes_for(username)
-    except ObjectDoesNotExist, e:
+    except ObjectDoesNotExist as e:
         raise Http404
 
     #convert query set to python structure
@@ -147,22 +150,22 @@ def updStatus(request):
       user = request.user
 
     #Check access permission
-    if not (user.is_superuser and settings.ALLOWED_IPS.has_key(ClIP)):
+    if not (user.is_superuser and ClIP in settings.ALLOWED_IPS):
         return HttpResponse("%s access denied from %s." % (user, ClIP))
 
     # ~~~~~~Parameters for the job ~~~~
-    if request.REQUEST.has_key('fcid'):
+    if 'fcid' in request.REQUEST:
       fcid = request.REQUEST['fcid']
     else:
       return HttpResponse('missing fcid')
 
-    if request.REQUEST.has_key('runf'):
+    if 'runf' in request.REQUEST:
       runfolder = request.REQUEST['runf']
     else:
       return HttpResponse('missing runf')
 
 
-    if request.REQUEST.has_key('updst'):
+    if 'updst' in request.REQUEST:
       UpdatedStatus = request.REQUEST['updst']
     else:
       return HttpResponse('missing status')
@@ -178,7 +181,7 @@ def updStatus(request):
       #if there's a message update that too
       mytimestamp = datetime.now().__str__()
       mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
-      if request.REQUEST.has_key('msg'):
+      if 'msg' in request.REQUEST:
         rec.run_note += ", "+request.REQUEST['msg']+" ("+mytimestamp+")"
       else :
         if UpdatedStatus == '1':
@@ -227,7 +230,7 @@ def generateConfile(request,fcid):
 def getConfile(req):
     granted = False
     ClIP = req.META['REMOTE_ADDR']
-    if (settings.ALLOWED_IPS.has_key(ClIP)):  granted = True
+    if (ClIP in settings.ALLOWED_IPS):  granted = True
 
     if not granted: return HttpResponse("access denied. IP: "+ClIP)
 
@@ -235,9 +238,9 @@ def getConfile(req):
     cnfgfile = 'Nothing found'
     runfolder = 'unknown'
     request = req.REQUEST
-    if request.has_key('fcid'):
+    if 'fcid' in request:
       fcid = request['fcid']
-      if request.has_key('runf'):
+      if 'runf' in request:
         runfolder = request['runf']
         try:
           rec = DataRun.objects.get(run_folder=runfolder) #,flowcell_id=fcid)
@@ -261,14 +264,14 @@ def getConfile(req):
 def getLaneLibs(req):
     granted = False
     ClIP = req.META['REMOTE_ADDR']
-    if (settings.ALLOWED_IPS.has_key(ClIP)):  granted = True
+    if (ClIP in settings.ALLOWED_IPS):  granted = True
 
     if not granted: return HttpResponse("access denied.")
 
     request = req.REQUEST
     fcid = 'none'
     outputfile = ''
-    if request.has_key('fcid'):
+    if 'fcid' in request:
       fcid = request['fcid']
       try:
         rec = FlowCell.objects.get(flowcell_id=fcid)