~angelmoya/product-extra-addons/nan_product_pack

« back to all changes in this revision

Viewing changes to product_images_olbs/product_images.py

  • Committer: Benoit Guillot
  • Date: 2012-08-10 14:18:59 UTC
  • mfrom: (60.1.3 product-extra-addons)
  • Revision ID: benoit.guillot@akretion.com.br-20120810141859-x2h4fsxlxm1odm7m
[MERGE] 

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import base64, urllib
21
21
from tools.translate import _
22
22
import os
23
 
import netsvc
 
23
 
 
24
import logging
 
25
_logger = logging.getLogger(__name__)
24
26
 
25
27
#TODO find a good solution in order to roll back changed done on file system
26
28
#TODO add the posibility to move from a store system to an other (example : moving existing image on database to file system)
30
32
    _name = "product.images"
31
33
    _description = __doc__
32
34
    _table = "product_images"
33
 
    
 
35
 
34
36
    def unlink(self, cr, uid, ids, context=None):
35
37
        if isinstance(ids, (int, long)):
36
38
            ids = [ids]
95
97
            with open(filename , 'rb') as f:
96
98
                img = base64.b64encode(f.read())
97
99
        else:
98
 
            full_path = self._image_path(cr, uid, image, context=context)
 
100
            try:
 
101
                if isinstance(image.product_id.default_code, bool):
 
102
                    _logger.debug('product not completely setup, no image available')
 
103
                    full_path = False
 
104
                else:
 
105
                    full_path = self._image_path(cr, uid, image, context=context)
 
106
            except Exception, e:
 
107
                _logger.error("Can not find the path for image %s: %s", id, e, exc_info=True)
 
108
                return False
99
109
            if full_path:
100
110
                if os.path.exists(full_path):
101
111
                    try:
102
112
                        with open(full_path, 'rb') as f:
103
113
                            img = base64.b64encode(f.read())
104
114
                    except Exception, e:
105
 
                        logger = netsvc.Logger()
106
 
                        logger.notifyChannel('product_images', netsvc.LOG_ERROR, "Can not open the image %s, error : %s" %(full_path, e))
 
115
                        _logger.error("Can not open the image %s, error : %s", full_path, e, exc_info=True)
107
116
                        return False
108
117
                else:
109
 
                    logger = netsvc.Logger()
110
 
                    logger.notifyChannel('product_images', netsvc.LOG_ERROR, "The image %s doesn't exist " %full_path)
 
118
                    _logger.error("The image %s doesn't exist ", full_path)
111
119
                    return False
112
120
            else:
113
121
                img = image.file_db_store