Adding barcode magic commands:
[htsworkflow.git] / samplebc / samples / bcm_cmds.py
diff --git a/samplebc/samples/bcm_cmds.py b/samplebc/samples/bcm_cmds.py
new file mode 100644 (file)
index 0000000..e3996a0
--- /dev/null
@@ -0,0 +1,36 @@
+from samplebc.bcmagic.utils import report_error, redirect_to_url, autofill
+from samplebc.samples.models import Sample, Container, Freezer
+
+from django.core.exceptions import ObjectDoesNotExist
+
+def cmd_move_sample(keyword, text, bcm_mode):
+    """
+    FIXME: should live in samples/bcm_cmds.py when this becomes a generic loader
+    """
+    
+    # If we received anything other than a sample or container
+    if keyword not in ['s', 'cntr']:
+        return report_error('Keyword "%s" not valid in "%s" bcm_mode' % (keyword, bcm_mode))
+
+    # Sample received
+    if keyword == 's':
+        sampleid = text.split('|')[1]
+        try:
+            sample = Sample.objects.get(sampleid=sampleid)
+        except ObjectDoesNotExist:
+            return report_error('Sample (%s) does not exist!' % (sampleid))
+        
+        return autofill('id_sampleid', sampleid)
+    
+    # Container received
+    elif keyword == 'cntr':
+        cntr_uuid = text.split('|')[1]
+    
+        try:
+            container = Container.objects.get(uuid=cntr_uuid)
+        except ObjectDoesNotExist, e:
+            return report_error('Container (%s) does not exist!' % (cntr_uuid))
+            
+        return autofill('id_container_id', cntr_uuid)
+    
+    return report_error('The should not happen error occured from cmd_sample_move')
\ No newline at end of file