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)
46 model_url = models.URLField(blank=True, null=True)
48 qty_purchased = models.IntegerField(default=1)
50 vendor = models.ForeignKey(Vendor)
51 purchase_date = models.DateField(blank=True, null=True)
52 warranty_months = models.IntegerField(blank=True, null=True)
54 def __unicode__(self):
55 return u"%s: %s" % (self.model_id, self.purchase_date)
58 class ItemType(models.Model):
60 name = models.CharField(max_length=64, unique=True)
61 description = models.TextField(blank=True, null=True)
63 def __unicode__(self):
64 return u"%s" % (self.name)
67 class Item(models.Model):
69 item_type = models.ForeignKey(ItemType)
71 #Automatically assigned uuid; used for barcode if one is not provided in
73 uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation")
75 # field for existing barcodes; used instead of uuid if provided
76 barcode_id = models.CharField(max_length=256, blank=True, null=True)
77 force_use_uuid = models.BooleanField(default=False)
79 item_info = models.ForeignKey(ItemInfo)
81 location = models.ForeignKey(Location)
83 creation_date = models.DateTimeField(auto_now_add=True)
84 modified_date = models.DateTimeField(auto_now=True)
86 notes = models.TextField(blank=True, null=True)
88 def __unicode__(self):
89 if self.barcode_id is None or len(self.barcode_id) == 0:
90 return u"invu|%s" % (self.uuid)
92 return u"invb|%s" % (self.barcode_id)
94 pre_save.connect(_assign_uuid, sender=Item)
97 class LongTermStorage(models.Model):
99 flowcell = models.ForeignKey(FlowCell)
100 libraries = models.ManyToManyField(Library)
102 storage_devices = models.ManyToManyField(Item)
104 def __unicode__(self):
105 return u"%s: %s" % (str(self.flowcell), ', '.join([ str(s) for s in self.storage_devices.iterator() ]))