Admin compatibility for changes in Django >= 1.1.
[htsworkflow.git] / htsworkflow / frontend / bcmagic / utils.py
1 from htsworkflow.frontend import settings
2
3 import ftplib
4 import socket
5 import StringIO
6
7
8 def print_zpl(zpl_text, host=settings.BCPRINTER_PRINTER1_HOST):
9     """
10     Sends zpl_text to printer
11     """
12     ftp = ftplib.FTP(host=host, user='blank', passwd='')
13     ftp.login()
14     ftp.storlines("STOR printme.txt", StringIO.StringIO(zpl_text))
15     ftp.quit()
16     
17
18 def print_zpl_socket(zpl_text, host=settings.BCPRINTER_PRINTER1_HOST, port=settings.BCPRINTER_PRINTER1_PORT):
19     """
20     Sends zpl_text to printer via a socket
21     """
22     s = socket.socket()
23     # PORT 9100 is default for Zebra tabletop/desktop printers
24     # PORT 6101 is default for Zebra mobile printers
25     s.connect((host, port))
26     s.sendall(zpl_text)
27     s.close()
28
29 def report_error(message):
30     """
31     Return a dictionary with a command to display 'message'
32     """
33     return {'mode': 'Error', 'status': message}
34     
35
36 def redirect_to_url(url):
37     """
38     Return a bcm dictionary with a command to redirect to 'url'
39     """
40     return {'mode': 'redirect', 'url': url}
41     
42
43 def autofill(field, value):
44     """
45     Return a bcm dictionary with a command to automatically fill the
46     corresponding "field" with "value"
47     """
48     return {'mode': 'autofill', 'field': field, 'value': value}