1 from __future__ import unicode_literals
3 from django.conf import settings
7 from six.moves import StringIO
10 def print_zpl(zpl_text, host=None):
12 Sends zpl_text to printer
15 host = settings.BCPRINTER_PRINTER1_HOST
16 ftp = ftplib.FTP(host=host, user='blank', passwd='')
18 ftp.storlines("STOR printme.txt", StringIO.StringIO(zpl_text))
22 def print_zpl_socket(zpl_text, host=None, port=None):
24 Sends zpl_text to printer via a socket
26 if zpl_text is a list of zpl_texts, it will print each one
31 host=settings.BCPRINTER_PRINTER1_HOST
33 port=settings.BCPRINTER_PRINTER1_PORT
35 # Process anyway if zpl_text is a list.
36 if type(zpl_text) is list:
37 zpl_text = '\n'.join(zpl_text)
40 # PORT 9100 is default for Zebra tabletop/desktop printers
41 # PORT 6101 is default for Zebra mobile printers
42 s.connect((host, port))
47 def report_error(message):
49 Return a dictionary with a command to display 'message'
51 return {'mode': 'Error', 'status': message}
54 def redirect_to_url(url):
56 Return a bcm dictionary with a command to redirect to 'url'
58 return {'mode': 'redirect', 'url': url}
61 def autofill(field, value):
63 Return a bcm dictionary with a command to automatically fill the
64 corresponding "field" with "value"
66 return {'mode': 'autofill', 'field': field, 'value': value}