2323#
2424##############################################################################
2525import time
26- import base64
2726
2827import cups
2928from threading import Thread
3231from openerp import pooler
3332from openerp .osv import orm , fields
3433from openerp .tools .translate import _
35- from openerp .addons .base_calendar import base_calendar
3634
3735
38- #
39- # Printers
40- #
4136class printing_printer (orm .Model ):
37+ """
38+ Printers
39+ """
4240 _name = "printing.printer"
4341 _description = "Printer"
4442
4543 _columns = {
46- 'name' : fields .char ('Name' ,size = 64 ,required = True ,select = "1" ),
47- 'system_name' : fields .char ('System Name' ,size = 64 ,required = True ,select = "1" ),
48- 'default' :fields .boolean ('Default Printer' , readonly = True ),
49- 'status' : fields .selection ([('unavailable' ,'Unavailable' ),('printing' ,'Printing' ),('unknown' ,'Unknown' ),('available' ,'Available' ),('error' ,'Error' ),('server-error' ,'Server Error' )], 'Status' , required = True , readonly = True ),
50- 'status_message' : fields .char ('Status Message' , size = 500 , readonly = True ),
51- 'model' : fields .char ('Model' , size = 500 , readonly = True ),
52- 'location' : fields .char ('Location' , size = 500 , readonly = True ),
53- 'uri' : fields .char ('URI' , size = 500 , readonly = True ),
44+ 'name' : fields .char (
45+ 'Name' ,
46+ size = 64 ,
47+ required = True ,
48+ select = "1" ),
49+ 'system_name' : fields .char (
50+ 'System Name' ,
51+ size = 64 ,
52+ required = True ,
53+ select = "1" ),
54+ 'default' : fields .boolean (
55+ 'Default Printer' ,
56+ readonly = True ),
57+ 'status' : fields .selection (
58+ [('unavailable' , 'Unavailable' ),
59+ ('printing' , 'Printing' ),
60+ ('unknown' , 'Unknown' ),
61+ ('available' , 'Available' ),
62+ ('error' , 'Error' ),
63+ ('server-error' , 'Server Error' )],
64+ 'Status' , required = True , readonly = True ),
65+ 'status_message' : fields .char (
66+ 'Status Message' ,
67+ size = 500 ,
68+ readonly = True ),
69+ 'model' : fields .char (
70+ 'Model' ,
71+ size = 500 ,
72+ readonly = True ),
73+ 'location' : fields .char (
74+ 'Location' ,
75+ size = 500 ,
76+ readonly = True ),
77+ 'uri' : fields .char (
78+ 'URI' ,
79+ size = 500 ,
80+ readonly = True ),
5481 }
5582
5683 _order = "name"
@@ -78,9 +105,9 @@ def update_printers_status(self, db_name, uid, context=None):
78105 server_error = True
79106
80107 mapping = {
81- 3 : 'available' ,
82- 4 : 'printing' ,
83- 5 : 'error'
108+ 3 : 'available' ,
109+ 4 : 'printing' ,
110+ 5 : 'error'
84111 }
85112
86113 if context is None :
@@ -96,7 +123,7 @@ def update_printers_status(self, db_name, uid, context=None):
96123 status = 'server-error'
97124 elif printer .system_name in printers :
98125 info = printers [printer .system_name ]
99- status = mapping .get ( info ['printer-state' ], 'unknown' )
126+ status = mapping .get (info ['printer-state' ], 'unknown' )
100127 vals = {
101128 'model' : info .get ('printer-make-and-model' , False ),
102129 'location' : info .get ('printer-location' , False ),
@@ -117,7 +144,6 @@ def update_printers_status(self, db_name, uid, context=None):
117144 self .updating = False
118145 self .last_update = time .time ()
119146
120-
121147 def start_printer_update (self , cr , uid , context ):
122148 self .lock .acquire ()
123149 if self .updating :
@@ -140,7 +166,7 @@ def update(self, cr, uid, context=None):
140166 if not last_update or now - last_update > 10 :
141167 self .start_printer_update (cr , uid , context )
142168 # Wait up to five seconds for printer status update
143- for x in range (0 ,5 ):
169+ for x in range (0 , 5 ):
144170 time .sleep (1 )
145171 self .lock .acquire ()
146172 updating = self .updating
@@ -149,28 +175,32 @@ def update(self, cr, uid, context=None):
149175 break
150176 return True
151177
152- def search (self , cr , uid , args , offset = 0 , limit = None , order = None , context = None , count = False ):
178+ def search (self , cr , uid , args , offset = 0 , limit = None , order = None ,
179+ context = None , count = False ):
153180 self .update (cr , uid , context )
154- return super (printing_printer ,self ).search (cr , uid , args , offset , limit , order , context , count )
181+ return super (printing_printer , self
182+ ).search (cr , uid , args , offset ,
183+ limit , order , context , count )
155184
156185 def read (self , cr , uid , ids , fields = None , context = None , load = '_classic_read' ):
157186 self .update (cr , uid , context )
158- return super (printing_printer ,self ).read (cr , uid , ids , fields , context , load )
187+ return super (printing_printer , self
188+ ).read (cr , uid , ids , fields , context , load )
159189
160190 def browse (self , cr , uid , ids , context = None ):
161191 self .update (cr , uid , context )
162- return super (printing_printer ,self ).browse (cr , uid , ids , context )
192+ return super (printing_printer , self ).browse (cr , uid , ids , context )
163193
164194 def set_default (self , cr , uid , ids , context ):
165195 if not ids :
166196 return
167- default_ids = self .search (cr , uid ,[('default' ,'=' ,True )])
168- self .write (cr , uid , default_ids , {'default' :False }, context )
169- self .write (cr , uid , ids [0 ], {'default' :True }, context )
197+ default_ids = self .search (cr , uid , [('default' , '=' , True )])
198+ self .write (cr , uid , default_ids , {'default' : False }, context )
199+ self .write (cr , uid , ids [0 ], {'default' : True }, context )
170200 return True
171201
172- def get_default (self ,cr ,uid ,context ):
173- printer_ids = self .search (cr , uid ,[('default' ,'=' ,True )])
202+ def get_default (self , cr , uid , context ):
203+ printer_ids = self .search (cr , uid , [('default' , '=' , True )])
174204 if printer_ids :
175205 return printer_ids [0 ]
176206 return False
@@ -182,11 +212,12 @@ def get_default(self,cr,uid,context):
182212
183213def _available_action_types (self , cr , uid , context = None ):
184214 return [
185- ('server' ,_ ('Send to Printer' )),
186- ('client' ,_ ('Send to Client' )),
187- ('user_default' ,_ ("Use user's defaults" )),
215+ ('server' , _ ('Send to Printer' )),
216+ ('client' , _ ('Send to Client' )),
217+ ('user_default' , _ ("Use user's defaults" )),
188218 ]
189219
220+
190221class printing_action (orm .Model ):
191222 _name = 'printing.action'
192223 _description = 'Print Job Action'
@@ -195,5 +226,3 @@ class printing_action(orm.Model):
195226 'name' : fields .char ('Name' , size = 256 , required = True ),
196227 'type' : fields .selection (_available_action_types , 'Type' , required = True ),
197228 }
198-
199- # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
0 commit comments