1
1
#########################################################################
2
2
# Copyright (C) 2009 Sharoon Thomas, Open Labs Business solutions #
4
# This program is free software: you can redistribute it and/or modify #
5
# it under the terms of the GNU General Public License as published by #
6
# the Free Software Foundation, either version 3 of the License, or #
4
#This program is free software: you can redistribute it and/or modify #
5
#it under the terms of the GNU General Public License as published by #
6
#the Free Software Foundation, either version 3 of the License, or #
7
7
#(at your option) any later version. #
9
# This program is distributed in the hope that it will be useful, #
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12
# GNU General Public License for more details. #
9
#This program is distributed in the hope that it will be useful, #
10
#but WITHOUT ANY WARRANTY; without even the implied warranty of #
11
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12
#GNU General Public License for more details. #
14
# You should have received a copy of the GNU General Public License #
15
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
14
#You should have received a copy of the GNU General Public License #
15
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
16
16
#########################################################################
17
from openerp.osv import osv, fields
22
class product_images(osv.Model):
17
from osv import osv, fields
20
class product_images(osv.osv):
23
21
"Products Image gallery"
24
22
_name = "product.images"
25
23
_description = __doc__
26
24
_table = "product_images"
28
26
def get_image(self, cr, uid, id):
29
27
each = self.read(cr, uid, id, ['link', 'filename', 'image'])
32
30
(filename, header) = urllib.urlretrieve(each['filename'])
33
f = open(filename, 'rb')
31
f = open(filename , 'rb')
34
32
img = base64.encodestring(f.read())
39
37
img = each['image']
42
40
def _get_image(self, cr, uid, ids, field_name, arg, context={}):
45
43
res[each] = self.get_image(cr, uid, each)
49
'name': fields.char('Image Title', size=100, required=True),
50
'link': fields.boolean('Link?',
51
help="""Images can be linked from files on your
52
file system or remote (Preferred)"""),
53
'image': fields.binary('Image', filters='*.png,*.jpg,*.gif'),
54
'filename': fields.char('File Location', size=250),
55
'preview': fields.function(_get_image, type="binary", method=True),
56
'comments': fields.text('Comments'),
57
'product_id': fields.many2one('product.product', 'Product')
47
'name':fields.char('Image Title', size=100, required=True),
48
'link':fields.boolean('Link?', help="Images can be linked from files on your file system or remote (Preferred)"),
49
'image':fields.binary('Image', filters='*.png,*.jpg,*.gif'),
50
'filename':fields.char('File Location', size=250),
51
'preview':fields.function(_get_image, type="binary", method=True),
52
'comments':fields.text('Comments'),
53
'product_id':fields.many2one('product.product', 'Product')
61
57
'link': lambda *a: True,