1 from django.db import models
2 from django.db.models import signals
3 from django.contrib.auth.models import User, Group
5 from samplebc import settings
8 #AUDIT_TYPES = [('Create', 'Create'),
9 # ('Update', 'Update'),
10 # ('Delete', 'Delete')]
12 EXP_TYPES = [('RNASeq', 'RNASeq'),
13 ('ChIPSeq','ChIPSeq'),
14 ('DeNovoSeq','DeNovoSeq'),
15 ('MethylSeq','MethylSeq')]
17 FREEZER_BUILDINGS = [('Kerckhoff', 'Kerckhoff')]
21 class Owner(models.Model):
22 name = models.CharField(max_length=32)
24 def __unicode__(self):
25 return u'%s' % (self.name)
28 class Freezer(models.Model):
29 name = models.CharField(max_length=256)
30 building = models.CharField(max_length=256, choices=FREEZER_BUILDINGS,
31 default=FREEZER_BUILDINGS[0][0])
32 loc_desc = models.CharField(max_length=256, blank=True, null=True)
33 temperature = models.FloatField(help_text='Celsius')
35 notes = models.TextField(blank=True, null=True)
37 uuid = models.CharField(max_length=32, unique=True)
39 def __unicode__(self):
40 return u'%s (%s; %sC)' % (self.name, self.building, self.temperature)
43 def get_absolute_url(self):
44 return ('samplebc.samples.views.freezer_summary', [str(self.uuid)])
47 class SampleType(models.Model):
48 name = models.CharField(max_length=256)
50 def __unicode__(self):
51 return u'%s' % (self.name)
54 class Container(models.Model):
55 name = models.CharField(max_length=256, unique=True)
56 sample_type = models.ManyToManyField(SampleType)
57 max_items = models.IntegerField()
58 freezer = models.ForeignKey(Freezer)
60 notes = models.TextField(blank=True, null=True)
62 uuid = models.CharField(max_length=32, unique=True)
64 def __unicode__(self):
65 return u'%s (spc: %s)' % (self.name, self.space_available())
68 def get_absolute_url(self):
69 return ('samplebc.samples.views.container_summary', [str(self.uuid)])
71 def space_available(self):
73 returns the space available for the container
75 return (self.max_items - self.sample_set.count())
78 class Sample(models.Model):
79 name = models.CharField(max_length=256, unique=True)
80 #sampleid = models.CharField(max_length=64, unique=True)
81 sampleid = models.CharField(max_length=64, unique=True)
82 sample_type = models.ForeignKey(SampleType)
83 owner = models.ForeignKey(Owner)
85 description = models.TextField()
87 # Concentration in ng/ul
88 concentration = models.FloatField(help_text='ng/ul', blank=True, null=True)
89 volume = models.FloatField(help_text='ul', blank=True, null=True)
90 container = models.ForeignKey(Container, blank=True, null=True)
92 def __unicode__(self):
93 return u's|%s|%s' % (self.sampleid, self.owner.name)
96 def get_absolute_url(self):
97 return ('samplebc.samples.views.sample_summary', [str(self.sampleid)])
99 def assign_sample_id(sender, instance, **kwargs):
101 print 'Instance ID: %s' % (instance.id)
102 if instance.sampleid is None or len(instance.sampleid) == 0:
103 instance.sampleid = settings.HTSW_SAMPLE_ID_TEMPLATE % (instance.id)
106 signals.post_save.connect(assign_sample_id, sender=Sample)