--- /dev/null
+from htsworkflow.frontend.labels.models import LabelContent, LabelTemplate, LabelPrinter
+from htsworkflow.frontend.inventory.models import PrinterTemplate
+from htsworkflow.frontend.bcmagic.utils import print_zpl_socket
+from django.template import Context, Template
+from django.contrib import admin
+
+class LabelContentOptions(admin.ModelAdmin):
+ save_as = True
+ save_on_top = True
+ search_fields = (
+ 'title',
+ 'subtitle',
+ 'text',
+ 'barcode',
+ 'creator',
+ )
+ list_display = ('title','subtitle','text','barcode','template','creator')
+ list_filter = ('template','creator',)
+ fieldsets = (
+ (None, {
+ 'fields': (('title','subtitle','text','barcode'),
+ ('template','creator'))
+
+ }),
+ )
+ actions = ['action_print_labels']
+
+ def action_print_labels(self, request, queryset):
+ """
+ Django action which prints labels for the selected set of labels from the
+ Django Admin interface.
+ """
+
+ zpl_list = []
+ #Iterate over selected labels to print
+ for label in queryset.all():
+
+ template_used = LabelTemplate.objects.get(name=label.template.name)
+ # ZPL Template
+ t = Template(template_used.ZPL_code)
+
+ # Django Template Context
+ c = Context({'label': label})
+
+ # Send rendered template to the printer that the template
+ # object has been attached to in the database.
+ zpl_list.append(t.render(c))
+
+ print_zpl_socket(zpl_list, host=template_used.printer.ip_address)
+
+ self.message_user(request, "%s labels printed." % (len(queryset)))
+
+ action_print_labels.short_description = "Print Selected Labels"
+
+class LabelTemplateOptions(admin.ModelAdmin):
+ save_as = True
+ save_on_top = True
+ list_display = ('name', 'printer', 'ZPL_code')
+
+class LabelPrinterOptions(admin.ModelAdmin):
+ list_display = ('name', 'ip_address', 'labels')
+
+admin.site.register(LabelContent, LabelContentOptions)
+admin.site.register(LabelTemplate, LabelTemplateOptions)
+admin.site.register(LabelPrinter, LabelPrinterOptions)
+
--- /dev/null
+from django.db import models
+
+class LabelPrinter(models.Model):
+ """
+ Barcode Printer Information
+ """
+ name = models.CharField(max_length=256)
+ model = models.CharField(max_length=64, default='ZM400')
+ ip_address = models.IPAddressField()
+ labels = models.CharField(max_length=200)
+ notes = models.TextField(null=True, blank=True)
+
+ def __unicode__(self):
+ return u'%s: %s' % (self.name, self.labels)
+
+class LabelTemplate(models.Model):
+ """
+ Maps templates to printer to use
+ """
+ name = models.CharField(max_length=200)
+ description = models.TextField(null=True, blank=True)
+ printer = models.ForeignKey(LabelPrinter)
+
+ ZPL_code = models.TextField('template')
+
+ def __unicode__(self):
+ return '%s %s' % (self.name, self.printer.name)
+
+class LabelContent(models.Model):
+ title = models.CharField(max_length=200, null=True, blank=True)
+ subtitle = models.CharField(max_length=200, null=True, blank=True)
+ text = models.CharField(max_length=200, null=True, blank=True)
+ barcode = models.CharField(max_length=200, null=True, blank=True)
+ template = models.ForeignKey(LabelTemplate)
+ creator = models.CharField(max_length=200)
--- /dev/null
+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+
--- /dev/null
+# Create your views here.
<th scope="row"><a href="/admin/experiments/flowcell/">Flowcells</a></th>
<td><a href="/admin/experiments/flowcell/add/" class="addlink">{% trans 'Add' %}</a></td>
</tr>
+</table></div>
+
+<div class='module'>
+<table>
+<caption>Label Printing</caption>
+<tr>
+<th scope="row"><a href="/admin/labels/labelcontent/">Label Contents</a></th>
+<td><a href="/admin/labels/labelcontent/add/" class="addlink">{% trans 'Add' %}</a></td>
+</tr>
+<tr>
+<th scope="row"><a href="/admin/labels/labeltemplate/">Label Templates</a></th>
+<td><a href="/admin/labels/labeltemplate/add/" class="addlink">{% trans 'Add' %}</a></td>
+</tr>
</table></div><BR>
{% if app_list %}
'htsworkflow.frontend.reports',
'htsworkflow.frontend.inventory',
'htsworkflow.frontend.bcmagic',
+ 'htsworkflow.frontend.labels',
'django.contrib.databrowse',
)