Merge lp:~agilebg/server-env-tools/binary_field_pep8 into lp:~akretion-team/server-env-tools/server-env-tools

Proposed by Lorenzo Battistini
Status: Merged
Merged at revision: 18
Proposed branch: lp:~agilebg/server-env-tools/binary_field_pep8
Merge into: lp:~akretion-team/server-env-tools/server-env-tools
Diff against target: 134 lines (+23/-21)
3 files modified
binary_field/__init__.py (+1/-1)
binary_field/__openerp__.py (+6/-9)
binary_field/fields.py (+16/-11)
To merge this branch: bzr merge lp:~agilebg/server-env-tools/binary_field_pep8
Reviewer Review Type Date Requested Status
Akretion Team Pending
Review via email: mp+223935@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'binary_field/__init__.py'
--- binary_field/__init__.py 2014-05-01 21:58:16 +0000
+++ binary_field/__init__.py 2014-06-20 14:15:36 +0000
@@ -1,7 +1,7 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2###############################################################################2###############################################################################
3#3#
4# Module for OpenERP 4# Module for OpenERP
5# Copyright (C) 2013 Akretion (http://www.akretion.com).5# Copyright (C) 2013 Akretion (http://www.akretion.com).
6# @author Sébastien BEAU <sebastien.beau@akretion.com>6# @author Sébastien BEAU <sebastien.beau@akretion.com>
7#7#
88
=== modified file 'binary_field/__openerp__.py'
--- binary_field/__openerp__.py 2014-06-08 21:45:23 +0000
+++ binary_field/__openerp__.py 2014-06-20 14:15:36 +0000
@@ -1,7 +1,7 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2###############################################################################2###############################################################################
3#3#
4# Module for OpenERP 4# Module for OpenERP
5# Copyright (C) 2013 Akretion (http://www.akretion.com).5# Copyright (C) 2013 Akretion (http://www.akretion.com).
6# @author Sébastien BEAU <sebastien.beau@akretion.com>6# @author Sébastien BEAU <sebastien.beau@akretion.com>
7#7#
@@ -33,13 +33,14 @@
33- ImageRezise33- ImageRezise
3434
35All of this fields will be store on the file system by default and not in the35All of this fields will be store on the file system by default and not in the
36database. If you want to store it on an other support (database, S3, ftp, SFTP...)36database. If you want to store it on an other support (database, S3, ftp,
37Then you should create your own 'storage class' and use your custom 'storage 37SFTP...)
38Then you should create your own 'storage class' and use your custom 'storage
38class' instead39class' instead
3940
40The default Storage class will store the field on the file system and build 41The default Storage class will store the field on the file system and build
41the path like that42the path like that
42 43
43 BASE_LOCATION/DB_NAME/MODEL-FIELD/XXX/YYYYY44 BASE_LOCATION/DB_NAME/MODEL-FIELD/XXX/YYYYY
4445
45with46with
@@ -75,7 +76,3 @@
75 'installable': True,76 'installable': True,
76 'application': True,77 'application': True,
77}78}
78
79
80
81
8279
=== modified file 'binary_field/fields.py'
--- binary_field/fields.py 2014-06-08 21:45:23 +0000
+++ binary_field/fields.py 2014-06-20 14:15:36 +0000
@@ -40,7 +40,8 @@
40 if config and config.get('field_key'):40 if config and config.get('field_key'):
41 self.field_key = config['field_key']41 self.field_key = config['field_key']
42 else:42 else:
43 self.field_key = ("%s-%s" % (record._name, field_name)).replace('.', '')43 self.field_key = (
44 "%s-%s" % (record._name, field_name)).replace('.', '')
44 if config and config.get('base_location'):45 if config and config.get('base_location'):
45 self.base_location = config['base_location']46 self.base_location = config['base_location']
46 else:47 else:
@@ -103,8 +104,8 @@
103 self.config = config104 self.config = config
104 super(BinaryField, self).__init__(**new_kwargs)105 super(BinaryField, self).__init__(**new_kwargs)
105106
106 #No postprocess are needed107 # No postprocess are needed
107 #we already take care of bin_size option in the context108 # we already take care of bin_size option in the context
108 def postprocess(self, cr, uid, obj, field, value=None, context=None):109 def postprocess(self, cr, uid, obj, field, value=None, context=None):
109 return value110 return value
110111
@@ -126,7 +127,8 @@
126 res = storage.update(binary_uid, value)127 res = storage.update(binary_uid, value)
127 else:128 else:
128 res = storage.add(value)129 res = storage.add(value)
129 vals = self._prepare_binary_meta(cr, uid, field_name, res, context=context)130 vals = self._prepare_binary_meta(
131 cr, uid, field_name, res, context=context)
130 record.write(vals)132 record.write(vals)
131 return True133 return True
132134
@@ -137,8 +139,10 @@
137 config=self.config)139 config=self.config)
138 binary_uid = record['%s_uid' % field_name]140 binary_uid = record['%s_uid' % field_name]
139 if binary_uid:141 if binary_uid:
140 #Compatibility with existing binary field142 # Compatibility with existing binary field
141 if context.get('bin_size_%s' % field_name, context.get('bin_size')):143 if context.get(
144 'bin_size_%s' % field_name, context.get('bin_size')
145 ):
142 size = record['%s_file_size' % field_name]146 size = record['%s_file_size' % field_name]
143 result[record.id] = tools.human_size(long(size))147 result[record.id] = tools.human_size(long(size))
144 else:148 else:
@@ -194,8 +198,8 @@
194 if not isinstance(ids, (list, tuple)):198 if not isinstance(ids, (list, tuple)):
195 ids = [ids]199 ids = [ids]
196 for record_id in ids:200 for record_id in ids:
197 _logger.debug('Refreshing Image Cache from the field %s of object %s '201 _logger.debug('Refreshing Image Cache from the field %s of object '
198 'id : %s' % (field_name, obj._name, record_id))202 '%s id : %s' % (field_name, obj._name, record_id))
199 field = obj._columns[field_name]203 field = obj._columns[field_name]
200 record = obj.browse(cr, uid, record_id, context=context)204 record = obj.browse(cr, uid, record_id, context=context)
201 original_image = record[field.related_field]205 original_image = record[field.related_field]
@@ -237,10 +241,11 @@
237 '%s_uid' % field:241 '%s_uid' % field:
238 fields.char('%s UID' % self._columns[field].string),242 fields.char('%s UID' % self._columns[field].string),
239 '%s_file_size' % field:243 '%s_file_size' % field:
240 fields.integer('%s File Size' % self._columns[field].string),244 fields.integer(
245 '%s File Size' % self._columns[field].string),
241 })246 })
242247
243 #Inject the store invalidation function for ImageResize248 # Inject the store invalidation function for ImageResize
244 if isinstance(self._columns[field], ImageResizeField):249 if isinstance(self._columns[field], ImageResizeField):
245 self._columns[field].store = {250 self._columns[field].store = {
246 self._name: (251 self._name: (
@@ -261,7 +266,7 @@
261 # Hack for passing the field_key in the full path266 # Hack for passing the field_key in the full path
262 # For now I prefer to use this hack and to reuse267 # For now I prefer to use this hack and to reuse
263 # the ir.attachment code268 # the ir.attachment code
264 # An alternative way will to copy/paste and 269 # An alternative way will to copy/paste and
265 # adapt the ir.attachment code270 # adapt the ir.attachment code
266 if isinstance(location, tuple):271 if isinstance(location, tuple):
267 base_location, field_key = location272 base_location, field_key = location

Subscribers

People subscribed via source and target branches