[FIX] Use the tempfile.mktemp function to get a temporary file name

bzr revid: stephane@tinyerp.com-20081210224448-e67bod15r9x1edap
This commit is contained in:
Stephane Wirtel 2008-12-10 23:44:48 +01:00
parent 3b6af7246b
commit 4fbf6e249a
1 changed files with 8 additions and 5 deletions

View File

@ -124,20 +124,23 @@ class auction_catalog(report_rml):
lnum.appendChild(doc.createTextNode(escape(cat['lot_num'])))
infos.appendChild(lnum)
dest = os.path.join('/tmp/pdf_catalog/',str(cwid),str(cat['obj_desc'])+'.jpg')
if cat['image']:
import random
import tempfile
limg = doc.createElement('photo_small')
file_name = '/tmp/image_%d.jpg' % (random.randint(1,1000),)
fp = file(file_name,'wb+')
file_name = tempfile.mktemp(prefix='openerp_auction_', suffix='.jpg')
fp = file(file_name, 'w')
content = base64.decodestring(cat['image'])
fp.write(content)
fp.close()
fp = file(file_name,'r')
size = photo_shadow.convert_catalog(fp, '/tmp/test.jpg',110)
fp = file('/tmp/test.jpg')
test_file_name = tempfile.mktemp(prefix='openerp_auction_test_', suffix='.jpg')
size = photo_shadow.convert_catalog(fp, test_file_name,110)
fp = file(test_file_name)
file_data = fp.read()
test_data = base64.encodestring(file_data)
fp.close()
limg.appendChild(doc.createTextNode(test_data))
infos.appendChild(limg)