summaryrefslogtreecommitdiff
path: root/addons/base_import/models.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2012-08-14 14:07:37 +0200
committerXavier Morel <xmo@openerp.com>2012-08-14 14:07:37 +0200
commit84ea769476468a46ee3ef19f388dff080b93b4ce (patch)
tree06cd55f91c227c5edb9f239677dd100ef6578837 /addons/base_import/models.py
parente3192430a94586a75a770c0c46bcbad9e960fb4b (diff)
[IMP] add information to _match_headers
bzr revid: xmo@openerp.com-20120814120737-0zuxqyjhnnx1aye3
Diffstat (limited to 'addons/base_import/models.py')
-rw-r--r--addons/base_import/models.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/addons/base_import/models.py b/addons/base_import/models.py
index 754467ed1c2..07a3439419d 100644
--- a/addons/base_import/models.py
+++ b/addons/base_import/models.py
@@ -24,6 +24,7 @@ class ir_import(orm.TransientModel):
'res_model': fields.char('Model', size=64),
'file': fields.binary('File'),
'file_name': fields.char('File Name', size=None),
+ 'file_mime': fields.char('File Type', size=None),
}
def get_fields(self, cr, uid, model, context=None,
@@ -174,19 +175,20 @@ class ir_import(orm.TransientModel):
Will consume the first line of the ``rows`` iterator.
- Returns either None (no title) or a dict mapping cell indices
+ Returns a pair of (None, None) if headers were not requested
+ or the list of headers and a dict mapping cell indices
to key paths in the ``fields`` tree
:param Iterator rows:
:param dict fields:
:param dict options:
- :rtype: None | dict(int: list(str))
+ :rtype: (None, None) | (list(str), dict(int: list(str)))
"""
if not options.get('headers'):
- return None
+ return None, None
headers = next(rows)
- return dict(
+ return headers, dict(
(index, [field['name'] for field in self._match_header(header, fields, options)] or None)
for index, header in enumerate(headers)
)
@@ -196,13 +198,16 @@ class ir_import(orm.TransientModel):
fields-matching between the import's file data and the model's
columns.
+ If the headers are not requested (not options.headers),
+ ``matches`` and ``headers`` are both ``False``.
+
:param id: identifier of the import
:param int count: number of preview lines to generate
:param options: format-specific options.
CSV: {encoding, quote, separator, headers}
:type options: {str, str, str, bool}
- :returns: {fields, matches, preview} | {error, preview}
- :rtype: {dict(str: dict(...)), dict(int, list(str)), list(list(str))} | {str, str}
+ :returns: {fields, matches, headers, preview} | {error, preview}
+ :rtype: {dict(str: dict(...)), dict(int, list(str)), list(str), list(list(str))} | {str, str}
"""
(record,) = self.browse(cr, uid, [id], context=context)
fields = self.get_fields(cr, uid, record.res_model, context=context)
@@ -210,13 +215,14 @@ class ir_import(orm.TransientModel):
try:
rows = self._read_csv(record, options)
- match = self._match_headers(rows, fields, options)
+ headers, matches = self._match_headers(rows, fields, options)
# Match should have consumed the first row (iif headers), get
# the ``count`` next rows for preview
preview = itertools.islice(rows, count)
return {
'fields': fields,
- 'matches': match,
+ 'matches': matches or False,
+ 'headers': headers or False,
'preview': list(preview),
}
except (TypeError, UnicodeDecodeError), e: