1 from django.db import models
2 from django.db.models.signals import pre_save
4 from htsworkflow.frontend.samples.models import Library
5 from htsworkflow.frontend.experiments.models import FlowCell
10 def _assign_uuid(sender, instance, **kwargs):
12 Assigns a UUID to model on save
14 print 'Entered _assign_uuid'
15 if instance.uuid is None or len(instance.uuid) != 32:
16 instance.uuid = uuid.uuid1().hex
19 class Vendor(models.Model):
20 name = models.CharField(max_length=256)
21 url = models.URLField(blank=True, null=True)
23 def __unicode__(self):
24 return u"%s" % (self.name)
27 class Location(models.Model):
29 name = models.CharField(max_length=256, unique=True)
30 location_description = models.TextField()
32 uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation")
34 notes = models.TextField(blank=True, null=True)
36 def __unicode__(self):
37 if len(self.location_description) > 16:
38 return u"%s: %s" % (self.name, self.location_description[0:16]+u"...")
40 return u"%s: %s" % (self.name, self.location_description)
42 pre_save.connect(_assign_uuid, sender=Location)
44 class ItemInfo(models.Model):
45 model_id = models.CharField(max_length=256, blank=True, null=True)
46 part_number = models.CharField(max_length=256, blank=True, null=True)
47 lot_number = models.CharField(max_length=256, blank=True, null=True)
49 url = models.URLField(blank=True, null=True)
51 qty_purchased = models.IntegerField(default=1)
53 vendor = models.ForeignKey(Vendor)
54 purchase_date = models.DateField(blank=True, null=True)
55 warranty_months = models.IntegerField(blank=True, null=True)
57 notes = models.TextField(blank=True, null=True)
59 def __unicode__(self):
62 name += u"model:%s " % (self.model_id)
64 name += u"part:%s " % (self.part_number)
66 name += u"lot:%s " % (self.lot_number)
68 return u"%s: %s" % (name, self.purchase_date)
71 class ItemType(models.Model):
73 name = models.CharField(max_length=64, unique=True)
74 description = models.TextField(blank=True, null=True)
76 def __unicode__(self):
77 return u"%s" % (self.name)
79 class ItemStatus(models.Model):
80 name = models.CharField(max_length=64, unique=True)
81 notes = models.TextField(blank=True, null=True)
83 def __unicode__(self):
86 class Item(models.Model):
88 item_type = models.ForeignKey(ItemType)
90 #Automatically assigned uuid; used for barcode if one is not provided in
92 uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation")
94 # field for existing barcodes; used instead of uuid if provided
95 barcode_id = models.CharField(max_length=256, blank=True, null=True)
96 force_use_uuid = models.BooleanField(default=False)
98 item_info = models.ForeignKey(ItemInfo)
100 location = models.ForeignKey(Location)
102 status = models.ForeignKey(ItemStatus, blank=True, null=True)
104 creation_date = models.DateTimeField(auto_now_add=True)
105 modified_date = models.DateTimeField(auto_now=True)
107 notes = models.TextField(blank=True, null=True)
109 def __unicode__(self):
110 if self.barcode_id is None or len(self.barcode_id) == 0:
111 return u"invu|%s" % (self.uuid)
113 return u"invb|%s" % (self.barcode_id)
115 pre_save.connect(_assign_uuid, sender=Item)
118 class LongTermStorage(models.Model):
120 flowcell = models.ForeignKey(FlowCell)
121 libraries = models.ManyToManyField(Library)
123 storage_devices = models.ManyToManyField(Item)
125 def __unicode__(self):
126 return u"%s: %s" % (str(self.flowcell), ', '.join([ str(s) for s in self.storage_devices.iterator() ]))