Sample ID now generated partially base on primary key of sample.
authorBrandon King <kingb@caltech.edu>
Fri, 22 May 2009 23:10:33 +0000 (23:10 +0000)
committerBrandon King <kingb@caltech.edu>
Fri, 22 May 2009 23:10:33 +0000 (23:10 +0000)
 * No longer random as per ticket:137.
 * FIXME: need a way to set the starting number of the autoincrement.
Added a socket based printer function.

samplebc/samples/models.py
samplebc/samples/views.py
samplebc/settings.py

index 86ed323a2a6387d35657577186569cf60afd8f90..7670f491048d2bd915370f7014f4cb8b1becf9a6 100644 (file)
@@ -2,6 +2,9 @@ from django.db import models
 from django.db.models import signals
 from django.contrib.auth.models import User, Group
 
+from samplebc import settings
+
+
 #AUDIT_TYPES = [('Create', 'Create'),
 #               ('Update', 'Update'),
 #               ('Delete', 'Delete')]
@@ -49,7 +52,7 @@ class SampleType(models.Model):
 
 
 class Container(models.Model):
-    name = models.CharField(max_length=256)
+    name = models.CharField(max_length=256, unique=True)
     sample_type = models.ManyToManyField(SampleType)
     max_items = models.IntegerField()
     freezer = models.ForeignKey(Freezer)
@@ -73,7 +76,8 @@ class Container(models.Model):
 
 
 class Sample(models.Model):
-    name = models.CharField(max_length=256)
+    name = models.CharField(max_length=256, unique=True)
+    #sampleid = models.CharField(max_length=64, unique=True)
     sampleid = models.CharField(max_length=64, unique=True)
     sample_type = models.ForeignKey(SampleType)
     owner = models.ForeignKey(Owner)
@@ -92,3 +96,12 @@ class Sample(models.Model):
     def get_absolute_url(self):
         return ('samplebc.samples.views.sample_summary', [str(self.sampleid)])
 
+def assign_sample_id(sender, instance, **kwargs):
+
+    print 'Instance ID: %s' % (instance.id)    
+    if instance.sampleid is None or len(instance.sampleid) == 0:
+        instance.sampleid = settings.HTSW_SAMPLE_ID_TEMPLATE % (instance.id)
+        instance.save()
+        
+signals.post_save.connect(assign_sample_id, sender=Sample)
+
index 2d3825c0e4afa493fb52f59d14483fdc430ab482..677fedb38a10a208ad5b3226d08ce2e46377de99 100644 (file)
@@ -22,6 +22,7 @@ from reversion import revision
 
 import random
 import ftplib
+import socket
 import StringIO
 
 
@@ -37,7 +38,17 @@ def print_zpl(zpl_text):
     ftp.login()
     ftp.storlines("STOR printme.txt", StringIO.StringIO(zpl_text))
     ftp.quit()
-
+    
+def print_zpl_socket(zpl_text):
+    """
+    Sends zpl_text to printer via a socket
+    """
+    s = socket.socket()
+    # PORT 9100 is default for Zebra tabletop/desktop printers
+    # PORT 6101 is default for Zebra mobile printers
+    s.connect((settings.PRINTER_HOST, settings.PRINTER_PORT))
+    s.sendall(zpl_text)
+    s.close()
 
 def __center_line(line, width):
     spaces_to_add = width - len(line)
@@ -498,7 +509,7 @@ def sample_add(request):
             s_obj = form.save(commit=False)
             
             # Add sample ID
-            s_obj.sampleid = get_sampleid()
+            #s_obj.sampleid = get_sampleid()
             
             # If the user wants us to assign a container.
             if form.cleaned_data['assign_container']:
index bed4831c5394e518e3efef67cec05c9ef0fb239d..eb8d99ec81d0bddc67c90615ac3429237c552e01 100644 (file)
@@ -85,7 +85,8 @@ INSTALLED_APPS = (
     'django.contrib.admin',
     'reversion',
     'samplebc.samples',
-    'samplebc.bcmagic'
+    'samplebc.bcmagic',
+#    'samplebc.bcprinter'
 )
 
 FIXTURE_DIRS = (
@@ -97,3 +98,7 @@ FIXTURE_DIRS = (
 # App Specific Settings
 
 HTSW_ST_APPNAME = 'HTSW-SampleTracker'
+
+
+HTSW_SAMPLE_ID_TEMPLATE = '%08d'
+