Adding barcode magic commands:
[htsworkflow.git] / samplebc / samples / bcm_cmds.py
1 from samplebc.bcmagic.utils import report_error, redirect_to_url, autofill
2 from samplebc.samples.models import Sample, Container, Freezer
3
4 from django.core.exceptions import ObjectDoesNotExist
5
6 def cmd_move_sample(keyword, text, bcm_mode):
7     """
8     FIXME: should live in samples/bcm_cmds.py when this becomes a generic loader
9     """
10     
11     # If we received anything other than a sample or container
12     if keyword not in ['s', 'cntr']:
13         return report_error('Keyword "%s" not valid in "%s" bcm_mode' % (keyword, bcm_mode))
14
15     # Sample received
16     if keyword == 's':
17         sampleid = text.split('|')[1]
18         try:
19             sample = Sample.objects.get(sampleid=sampleid)
20         except ObjectDoesNotExist:
21             return report_error('Sample (%s) does not exist!' % (sampleid))
22         
23         return autofill('id_sampleid', sampleid)
24     
25     # Container received
26     elif keyword == 'cntr':
27         cntr_uuid = text.split('|')[1]
28     
29         try:
30             container = Container.objects.get(uuid=cntr_uuid)
31         except ObjectDoesNotExist, e:
32             return report_error('Container (%s) does not exist!' % (cntr_uuid))
33             
34         return autofill('id_container_id', cntr_uuid)
35     
36     return report_error('The should not happen error occured from cmd_sample_move')