1 from htsworkflow.frontend.inventory.models import Item, LongTermStorage
2 from htsworkflow.frontend.experiments.models import FlowCell
4 from django.core.exceptions import ObjectDoesNotExist
5 from django.http import HttpResponse
8 def link_flowcell_and_device(request, flowcell, serial):
10 Updates database records of a flowcell being archived on a device with a particular serial #
12 assert flowcell is not None
13 assert serial is not None
15 ###########################################
16 # Retrieve Storage Device
18 sd = Item.objects.get(barcode_id=serial)
19 except ObjectDoesNotExist, e:
20 msg = "Item with barcode_id of %s not found." % (serial)
21 raise ObjectDoesNotExist(msg)
23 ###########################################
26 fc = FlowCell.objects.get(flowcell_id=flowcell)
27 except ObjectDoesNotExist, e:
28 msg = "FlowCell with flowcell_id of %s not found." % (flowcell)
29 raise ObjectDoesNotExist(msg)
31 ###########################################
32 # Retrieve or create LongTermStorage Object
33 count = fc.longtermstorage_set.count()
36 msg = "There really should only be one longtermstorage object per flowcell"
39 # lts already attached to flowcell
40 lts = fc.longtermstorage_set.all()[0]
42 lts = LongTermStorage()
45 # Need a primary keey before linking to storage devices
49 ############################################
50 # Link Storage to Flowcell
52 # Add a link to this storage device if it is not already linked.
53 if sd not in lts.storage_devices.values():
54 lts.storage_devices.add(sd)
56 ###########################################
57 # Add Library Links to LTS
59 if fc.lane_1_library not in lts.storage_devices.values():
60 lts.libraries.add(fc.lane_1_library)
62 if fc.lane_2_library not in lts.storage_devices.values():
63 lts.libraries.add(fc.lane_2_library)
65 if fc.lane_3_library not in lts.storage_devices.values():
66 lts.libraries.add(fc.lane_3_library)
68 if fc.lane_4_library not in lts.storage_devices.values():
69 lts.libraries.add(fc.lane_4_library)
72 if fc.lane_5_library not in lts.storage_devices.values():
73 lts.libraries.add(fc.lane_5_library)
75 if fc.lane_6_library not in lts.storage_devices.values():
76 lts.libraries.add(fc.lane_6_library)
78 if fc.lane_7_library not in lts.storage_devices.values():
79 lts.libraries.add(fc.lane_7_library)
81 if fc.lane_8_library not in lts.storage_devices.values():
82 lts.libraries.add(fc.lane_8_library)
87 return HttpResponse("Success")