Initial port to python3
[htsworkflow.git] / htsworkflow / frontend / analysis / main.py
index b5217dc3b41a7e6f2b1778ecf53cf61fbff29b52..71d711d72dca7e9dac47806e9b3e4635d842d123 100644 (file)
@@ -1,30 +1,33 @@
 # some core functions of analysis manager module
-from django.http import HttpResponse
+
 from datetime import datetime
 from string import *
 import re
-from htsworkflow.frontend import settings
-from htsworkflow.frontend.analysis.models import Task, Project
+
+from django.conf import settings
 from django.core.exceptions import ObjectDoesNotExist
+from django.http import HttpResponse
+
+from htsworkflow.frontend.analysis.models import Task, Project
 
 def updStatus(request):
     ClIP = request.META['REMOTE_ADDR']
     #Check client access permission                                                                                                                                       
     granted = False
-    if (settings.ALLOWED_ANALYS_IPS.has_key(ClIP)):  granted = True
+    if (ClIP in settings.ALLOWED_ANALYS_IPS):  granted = True
     if not granted: return HttpResponse("access denied.")
 
     output=''
     taskid=-1;
     # Check required param
-    if request.has_key('taskid'): taskid = request['taskid']
+    if 'taskid' in request: taskid = request['taskid']
     else:  return HttpResponse('missing param task id')
 
     try:
       rec = Task.objects.get(id=taskid)
       mytimestamp = datetime.now().__str__()
       mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
-      if request.has_key('msg'):
+      if 'msg' in request:
         rec.task_status += ", "+request['msg']+" ("+mytimestamp+")"
       else :
         rec.task_status = "Registered ("+mytimestamp+")"
@@ -40,13 +43,13 @@ def getProjects(request):
     ClIP = request.META['REMOTE_ADDR']
     #Check client access permission 
     granted = False
-    if (settings.ALLOWED_ANALYS_IPS.has_key(ClIP)):  granted = True
+    if (ClIP in settings.ALLOWED_ANALYS_IPS):  granted = True
     if not granted: return HttpResponse("access denied.")
 
     outputfile = ''
     
     All=False
-    if (request.has_key('mode')):
+    if ('mode' in request):
       if request['mode']=='all':
         All=True
 
@@ -67,9 +70,9 @@ def getProjects(request):
           if (t.apply_calc == 'QuEST' or t.apply_calc == 'WingPeaks' or t.apply_calc == 'MACS'):
             outputfile += '\n<PeakCalling TaskId="'+t.id.__str__()+'" Name="'+t.task_name+'" Caller="'+t.apply_calc+'" Genome="'+t.subject1.library_species.use_genome_build+'">'
             if t.subject1:
-              outputfile += '\n<Signal Library="'+t.subject1.library_id+'"/>'
+              outputfile += '\n<Signal Library="'+t.subject1.id+'"/>'
               if t.subject2:
-                outputfile += '\n<Background Library="'+t.subject2.library_id+'"/>'
+                outputfile += '\n<Background Library="'+t.subject2.id+'"/>'
               else:
                 outputfile += '\n<Err>Background Library Missing</Err>'
             else:
@@ -80,9 +83,9 @@ def getProjects(request):
           if (t.apply_calc == 'Methylseq'):
             outputfile += '\n<Methylseq TaskId="'+t.id.__str__()+'" Name="'+t.task_name+'" Genome="'+t.subject1.library_species.use_genome_build+'">'
             if t.subject1:
-              outputfile += '\n<Hpa2 Library="'+t.subject1.library_id+'"/>'
+              outputfile += '\n<Hpa2 Library="'+t.subject1.id+'"/>'
               if t.subject2:
-                outputfile += '\n<Msp1 Library="'+t.subject2.library_id+'"/>'
+                outputfile += '\n<Msp1 Library="'+t.subject2.id+'"/>'
               else:
                 outputfile += '\n<Err>Msp1 Library Missing</Err>'
             else:
@@ -91,16 +94,16 @@ def getProjects(request):
             outputfile += '\n</Methylseq>' 
 
           if (t.apply_calc == 'ProfileReads' or t.apply_calc == 'qPCR'):
-            outputfile += '\n<'+t.apply_calc+' TaskId="'+t.id.__str__()+'" Name="'+t.task_name+'" Genome="'+t.subject1.library_species.use_genome_build+'" Library="'+t.subject1.library_id+'"/>'
+            outputfile += '\n<'+t.apply_calc+' TaskId="'+t.id.__str__()+'" Name="'+t.task_name+'" Genome="'+t.subject1.library_species.use_genome_build+'" Library="'+t.subject1.id+'"/>'
 
           if (t.apply_calc == 'CompareLibs'):
             outputfile += '\n<CompareLibraries TaskId="'+t.id.__str__()+'" TF="'+t.task_name+'" Genome="'+t.subject1.library_species.use_genome_build+'">'
             if t.subject1:
-              outputfile += '\n<Library Library="'+t.subject1.library_id+'"/>'
+              outputfile += '\n<Library Library="'+t.subject1.id+'"/>'
             else:
               outputfile += '\n<Err>Library Missing</Err>'
             if t.subject2:
-              outputfile += '\n<Library Library="'+t.subject2.library_id+'"/>'
+              outputfile += '\n<Library Library="'+t.subject2.id+'"/>'
             else:
               outputfile += '\n<Err>Library Missing</Err>'
             outputfile += '\n<params>'+t.task_params.__str__()+'</params>'