1 from htsworkflow.frontend.labels.models import LabelContent, LabelTemplate, LabelPrinter
2 from htsworkflow.frontend.inventory.models import PrinterTemplate
3 from htsworkflow.frontend.bcmagic.utils import print_zpl_socket
4 from django.template import Context, Template
5 from django.contrib import admin
7 class LabelContentOptions(admin.ModelAdmin):
17 list_display = ('title','subtitle','text','barcode','template','creator')
18 list_filter = ('template','creator',)
21 'fields': (('title','subtitle','text','barcode'),
22 ('template','creator'))
26 actions = ['action_print_labels']
28 def action_print_labels(self, request, queryset):
30 Django action which prints labels for the selected set of labels from the
31 Django Admin interface.
35 #Iterate over selected labels to print
36 for label in queryset.all():
38 template_used = LabelTemplate.objects.get(name=label.template.name)
40 t = Template(template_used.ZPL_code)
42 # Django Template Context
43 c = Context({'label': label})
45 # Send rendered template to the printer that the template
46 # object has been attached to in the database.
47 zpl_list.append(t.render(c))
49 print_zpl_socket(zpl_list, host=template_used.printer.ip_address)
51 self.message_user(request, "%s labels printed." % (len(queryset)))
53 action_print_labels.short_description = "Print Selected Labels"
55 class LabelTemplateOptions(admin.ModelAdmin):
58 list_display = ('name', 'printer', 'ZPL_code')
60 class LabelPrinterOptions(admin.ModelAdmin):
61 list_display = ('name', 'ip_address', 'labels')
63 admin.site.register(LabelContent, LabelContentOptions)
64 admin.site.register(LabelTemplate, LabelTemplateOptions)
65 admin.site.register(LabelPrinter, LabelPrinterOptions)