Improved debugging output.
[htsworkflow.git] / htsworkflow / frontend / inventory / views.py
index aa106961c7580ec69690d24ebf7952fad2ef32d4..19bcb0b0d85d228ff28a953e9a539dcc63cfbdee 100644 (file)
@@ -11,6 +11,10 @@ def link_flowcell_and_device(request, flowcell, serial):
     """
     assert flowcell is not None
     assert serial is not None
+    
+    LTS_UPDATED = False
+    SD_UPDATED = False
+    LIBRARY_UPDATED = False
         
     ###########################################
     # Retrieve Storage Device
@@ -44,44 +48,70 @@ def link_flowcell_and_device(request, flowcell, serial):
         lts.flowcell = fc
         # Need a primary keey before linking to storage devices
         lts.save()
+        LTS_UPDATED = True
         
         
     ############################################
     # Link Storage to Flowcell
     
     # Add a link to this storage device if it is not already linked.
-    if sd not in lts.storage_devices.values():
+    if sd not in lts.storage_devices.all():
         lts.storage_devices.add(sd)
+        SD_UPDATED = True
     
     ###########################################
     # Add Library Links to LTS
     
-    if fc.lane_1_library not in lts.storage_devices.values():
+    if fc.lane_1_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_1_library)
+        LIBRARY_UPDATED = True
+        print 1
     
-    if fc.lane_2_library not in lts.storage_devices.values():
+    if fc.lane_2_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_2_library)
+        LIBRARY_UPDATED = True
+        print 2
     
-    if fc.lane_3_library not in lts.storage_devices.values():
+    if fc.lane_3_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_3_library)
+        LIBRARY_UPDATED = True
+        print 3
     
-    if fc.lane_4_library not in lts.storage_devices.values():
+    if fc.lane_4_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_4_library)
+        LIBRARY_UPDATED = True
+        print 4
     
     
-    if fc.lane_5_library not in lts.storage_devices.values():
+    if fc.lane_5_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_5_library)
+        LIBRARY_UPDATED = True
+        print 5
     
-    if fc.lane_6_library not in lts.storage_devices.values():
+    if fc.lane_6_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_6_library)
+        LIBRARY_UPDATED = True
+        print 6
     
-    if fc.lane_7_library not in lts.storage_devices.values():
+    if fc.lane_7_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_7_library)
+        LIBRARY_UPDATED = True
+        print 7
     
-    if fc.lane_8_library not in lts.storage_devices.values():
+    if fc.lane_8_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_8_library)
+        LIBRARY_UPDATED = True
+        print 8
         
     # Save Changes
     lts.save()
     
-    return HttpResponse("Success")
\ No newline at end of file
+    msg = ['Success:']
+    if LTS_UPDATED or SD_UPDATED or LIBRARY_UPDATED:
+        msg.append('  LongTermStorage (LTS) Created: %s' % (LTS_UPDATED))
+        msg.append('   Storage Device Linked to LTS: %s' % (SD_UPDATED))
+        msg.append('       Libraries updated in LTS: %s' % (LIBRARY_UPDATED))
+    else:
+        msg.append('  No Updates Needed.')
+    
+    return HttpResponse('\n'.join(msg))
\ No newline at end of file