convert to print_function, and start adding unicode_literals future as well
[htsworkflow.git] / inventory / models.py
index 7534c8addd82006169c95570cf750434f2cd2608..1e8509600336bb38a8797fbf097e431b48f13ffc 100644 (file)
@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function
 import logging
 
 from django.db import models
-from django.db.models.signals import pre_save
+from django.db.models.signals import pre_save, post_init
 
 from samples.models import Library
 from experiments.models import FlowCell
@@ -13,23 +13,25 @@ LOGGER = logging.getLogger(__name__)
 
 try:
     import uuid
-except ImportError, e:
+except ImportError as e:
     # Some systems are using python 2.4, which doesn't have uuid
     # this is a stub
     LOGGER.warning('Real uuid is not available, initializing fake uuid module')
+
     class uuid:
         def uuid1(self):
             self.hex = None
             return self
 
+
 def _assign_uuid(sender, instance, **kwargs):
     """
     Assigns a UUID to model on save
     """
-    #print 'Entered _assign_uuid'
     if instance.uuid is None or len(instance.uuid) != 32:
         instance.uuid = uuid.uuid1().hex
 
+
 def _switch_default(sender, instance, **kwargs):
     """
     When new instance has default == True, uncheck all other defaults
@@ -55,7 +57,10 @@ class Location(models.Model):
     name = models.CharField(max_length=256, unique=True)
     location_description = models.TextField()
 
-    uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation", editable=False)
+    uuid = models.CharField(max_length=32,
+                            blank=True,
+                            help_text="Leave blank for automatic UUID generation",
+                            editable=False)
 
     notes = models.TextField(blank=True, null=True)
 
@@ -65,7 +70,7 @@ class Location(models.Model):
         else:
             return u"%s: %s" % (self.name, self.location_description)
 
-pre_save.connect(_assign_uuid, sender=Location)
+post_init.connect(_assign_uuid, sender=Location)
 
 
 class ItemInfo(models.Model):
@@ -106,6 +111,7 @@ class ItemType(models.Model):
     def __unicode__(self):
         return u"%s" % (self.name)
 
+
 class ItemStatus(models.Model):
     name = models.CharField(max_length=64, unique=True)
     notes = models.TextField(blank=True, null=True)
@@ -118,12 +124,15 @@ class ItemStatus(models.Model):
 
 
 class Item(models.Model):
-
     item_type = models.ForeignKey(ItemType)
 
     #Automatically assigned uuid; used for barcode if one is not provided in
     # barcode_id
-    uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation", unique=True, editable=False)
+    uuid = models.CharField(max_length=32,
+                            blank=True,
+                            help_text="Leave blank for automatic UUID generation",
+                            unique=True,
+                            editable=False)
 
     # field for existing barcodes; used instead of uuid if provided
     barcode_id = models.CharField(max_length=256, blank=True, null=True)
@@ -149,7 +158,7 @@ class Item(models.Model):
     def get_absolute_url(self):
         return '/inventory/%s/' % (self.uuid)
 
-pre_save.connect(_assign_uuid, sender=Item)
+post_init.connect(_assign_uuid, sender=Item)
 
 
 class PrinterTemplate(models.Model):
@@ -173,7 +182,6 @@ pre_save.connect(_switch_default, sender=PrinterTemplate)
 
 
 class LongTermStorage(models.Model):
-
     flowcell = models.ForeignKey(FlowCell)
     libraries = models.ManyToManyField(Library)
 
@@ -183,15 +191,13 @@ class LongTermStorage(models.Model):
     modified_date = models.DateTimeField(auto_now=True)
 
     def __unicode__(self):
-        return u"%s: %s" % (str(self.flowcell), ', '.join([ str(s) for s in self.storage_devices.iterator() ]))
+        return u"%s: %s" % (str(self.flowcell), ', '.join([str(s) for s in self.storage_devices.iterator()]))
 
     class Meta:
         verbose_name_plural = "Long Term Storage"
 
 
-
 class ReagentBase(models.Model):
-
     reagent = models.ManyToManyField(Item)
 
     creation_date = models.DateTimeField(auto_now_add=True)
@@ -208,7 +214,7 @@ class ReagentFlowcell(ReagentBase):
     flowcell = models.ForeignKey(FlowCell)
 
     def __unicode__(self):
-        return u"%s: %s" % (str(self.flowcell), ', '.join([ str(s) for s in self.reagent.iterator() ]))
+        return u"%s: %s" % (str(self.flowcell), ', '.join([str(s) for s in self.reagent.iterator()]))
 
 
 class ReagentLibrary(ReagentBase):
@@ -218,4 +224,4 @@ class ReagentLibrary(ReagentBase):
     library = models.ForeignKey(Library)
 
     def __unicode__(self):
-        return u"%s: %s" % (str(self.library), ', '.join([ str(s) for s in self.reagent.iterator() ]))
+        return u"%s: %s" % (str(self.library), ', '.join([str(s) for s in self.reagent.iterator()]))