3 from django.db import models
4 from django.db.models.signals import pre_save
6 from htsworkflow.frontend.samples.models import Library
7 from htsworkflow.frontend.experiments.models import FlowCell
12 except ImportError, e:
13 # Some systems are using python 2.4, which doesn't have uuid
15 logging.warning('Real uuid is not available, initializing fake uuid module')
21 def _assign_uuid(sender, instance, **kwargs):
23 Assigns a UUID to model on save
25 print 'Entered _assign_uuid'
26 if instance.uuid is None or len(instance.uuid) != 32:
27 instance.uuid = uuid.uuid1().hex
30 class Vendor(models.Model):
31 name = models.CharField(max_length=256)
32 url = models.URLField(blank=True, null=True)
34 def __unicode__(self):
35 return u"%s" % (self.name)
38 class Location(models.Model):
40 name = models.CharField(max_length=256, unique=True)
41 location_description = models.TextField()
43 uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation")
45 notes = models.TextField(blank=True, null=True)
47 def __unicode__(self):
48 if len(self.location_description) > 16:
49 return u"%s: %s" % (self.name, self.location_description[0:16]+u"...")
51 return u"%s: %s" % (self.name, self.location_description)
53 pre_save.connect(_assign_uuid, sender=Location)
55 class ItemInfo(models.Model):
56 model_id = models.CharField(max_length=256, blank=True, null=True)
57 part_number = models.CharField(max_length=256, blank=True, null=True)
58 lot_number = models.CharField(max_length=256, blank=True, null=True)
60 url = models.URLField(blank=True, null=True)
62 qty_purchased = models.IntegerField(default=1)
64 vendor = models.ForeignKey(Vendor)
65 purchase_date = models.DateField(blank=True, null=True)
66 warranty_months = models.IntegerField(blank=True, null=True)
68 notes = models.TextField(blank=True, null=True)
70 def __unicode__(self):
73 name += u"model:%s " % (self.model_id)
75 name += u"part:%s " % (self.part_number)
77 name += u"lot:%s " % (self.lot_number)
79 return u"%s: %s" % (name, self.purchase_date)
82 class ItemType(models.Model):
84 name = models.CharField(max_length=64, unique=True)
85 description = models.TextField(blank=True, null=True)
87 def __unicode__(self):
88 return u"%s" % (self.name)
90 class ItemStatus(models.Model):
91 name = models.CharField(max_length=64, unique=True)
92 notes = models.TextField(blank=True, null=True)
94 def __unicode__(self):
97 class Item(models.Model):
99 item_type = models.ForeignKey(ItemType)
101 #Automatically assigned uuid; used for barcode if one is not provided in
103 uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation")
105 # field for existing barcodes; used instead of uuid if provided
106 barcode_id = models.CharField(max_length=256, blank=True, null=True)
107 force_use_uuid = models.BooleanField(default=False)
109 item_info = models.ForeignKey(ItemInfo)
111 location = models.ForeignKey(Location)
113 status = models.ForeignKey(ItemStatus, blank=True, null=True)
115 creation_date = models.DateTimeField(auto_now_add=True)
116 modified_date = models.DateTimeField(auto_now=True)
118 notes = models.TextField(blank=True, null=True)
120 def __unicode__(self):
121 if self.barcode_id is None or len(self.barcode_id) == 0:
122 return u"invu|%s" % (self.uuid)
124 return u"invb|%s" % (self.barcode_id)
126 pre_save.connect(_assign_uuid, sender=Item)
129 class LongTermStorage(models.Model):
131 flowcell = models.ForeignKey(FlowCell)
132 libraries = models.ManyToManyField(Library)
134 storage_devices = models.ManyToManyField(Item)
136 def __unicode__(self):
137 return u"%s: %s" % (str(self.flowcell), ', '.join([ str(s) for s in self.storage_devices.iterator() ]))