Add a custom (inherited) user object named HTSUser to the samples table.
[htsworkflow.git] / htsworkflow / frontend / samples / models.py
index 26d718576d9c45905b9544d733087099d3ec20a3..4c5df1c1cb11d51101ab471a07fa8ddeebfa88e4 100644 (file)
@@ -1,6 +1,6 @@
 import urlparse
 from django.db import models
-from django.contrib.auth.models import User
+from django.contrib.auth.models import User, UserManager
 from htsworkflow.frontend import settings
 from htsworkflow.frontend.reports.libinfopar import *
 
@@ -102,6 +102,8 @@ class Affiliation(models.Model):
   name = models.CharField(max_length=256, db_index=True, verbose_name='Name')
   contact = models.CharField(max_length=256, null=True, blank=True,verbose_name='Lab Name')  
   email = models.EmailField(null=True,blank=True)
+  users = models.ManyToManyField('HTSUser', null=True)
+  users.admin_order_field = "username"
   
   def __unicode__(self):
     str = unicode(self.name)
@@ -109,10 +111,20 @@ class Affiliation(models.Model):
       str += u' ('+self.contact+u')' 
     return str
 
+  def Users(self):
+      users = self.users.all().order_by('username')
+      return ", ".join([unicode(a) for a in users ])
+
   class Meta:
     ordering = ["name","contact"]
     unique_together = (("name", "contact"),)
 
+class LibraryType(models.Model):
+  name = models.CharField(max_length=255, unique=True)
+
+  def __unicode__(self):
+    return unicode(self.name)
+
 class Library(models.Model):
   id = models.AutoField(primary_key=True)
   library_id = models.CharField(max_length=30, db_index=True, unique=True)
@@ -120,8 +132,8 @@ class Library(models.Model):
   library_species = models.ForeignKey(Species)
   # new field 2008 Mar 5, alter table samples_library add column "hidden" NOT NULL default 0;
   hidden = models.BooleanField()
-  cell_line = models.ForeignKey(Cellline, null=True)
-  condition = models.ForeignKey(Condition, null=True)
+  cell_line = models.ForeignKey(Cellline, blank=True, null=True, verbose_name="Background")
+  condition = models.ForeignKey(Condition, blank=True, null=True)
   antibody = models.ForeignKey(Antibody,blank=True,null=True)
   # New field Aug/25/08. SQL: alter table fctracker_library add column "lib_affiliation" varchar(256)  NULL;
   affiliations = models.ManyToManyField(Affiliation,related_name='library_affiliations',null=True)
@@ -132,6 +144,7 @@ class Library(models.Model):
   REPLICATE_NUM = ((1,1),(2,2),(3,3),(4,4))
   replicate =  models.PositiveSmallIntegerField(choices=REPLICATE_NUM,default=1) 
   experiment_type = models.ForeignKey(ExperimentType)
+  library_type = models.ForeignKey(LibraryType, blank=True, null=True)
   creation_date = models.DateField(blank=True, null=True)
   made_for = models.CharField(max_length=50, blank=True, 
       verbose_name='ChIP/DNA/RNA Made By')
@@ -183,6 +196,15 @@ class Library(models.Model):
     for t in affs:
         ar.append(t.__unicode__())
     return '%s' % (", ".join(ar))
+    
+  def is_archived(self):
+    """
+    returns True if archived else False
+    """
+    if self.longtermstorage_set.count() > 0:
+        return True
+    else:
+        return False
 
   def libtags(self):
     affs = self.tags.all().order_by('tag_name')
@@ -237,4 +259,14 @@ class Library(models.Model):
 
   @models.permalink
   def get_absolute_url(self):
-    return ('htsworkflow.frontend.samples.views.library_to_flowcells', [str(self.id)])
+    return ('htsworkflow.frontend.samples.views.library_to_flowcells', [str(self.library_id)])
+
+class HTSUser(User):
+    """
+    Provide some site-specific customization for the django user class
+    """
+    #objects = UserManager()
+
+    class Meta:
+        ordering = ['username']
+