Merge lp:~therp-nl/openerp-web/7.0_lp1261322_better_report_name into lp:openerp-web/7.0

Proposed by Ronald Portier (Therp)
Status: Needs review
Proposed branch: lp:~therp-nl/openerp-web/7.0_lp1261322_better_report_name
Merge into: lp:openerp-web/7.0
Diff against target: 37 lines (+17/-9)
1 file modified
addons/web/controllers/main.py (+17/-9)
To merge this branch: bzr merge lp:~therp-nl/openerp-web/7.0_lp1261322_better_report_name
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+220777@code.launchpad.net

Description of the change

Make sure printed reports have sensible filenames.

Fixes lp1261322.

To post a comment you must log in.

Unmerged revisions

4187. By Ronald Portier (Therp)

[ENH] Make filename for print download dependent on object name.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'addons/web/controllers/main.py'
--- addons/web/controllers/main.py 2014-02-21 11:58:55 +0000
+++ addons/web/controllers/main.py 2014-05-23 09:52:23 +0000
@@ -1751,16 +1751,24 @@
1751 report = zlib.decompress(report)1751 report = zlib.decompress(report)
1752 report_mimetype = self.TYPES_MAPPING.get(1752 report_mimetype = self.TYPES_MAPPING.get(
1753 report_struct['format'], 'octet-stream')1753 report_struct['format'], 'octet-stream')
1754 file_name = action.get('name', 'report')1754 file_name = action['report_name']
1755 if 'name' not in action:1755 # Try to get current object model and their ids from context
1756 reports = req.session.model('ir.actions.report.xml')1756 if 'context' in action:
1757 res_id = reports.search([('report_name', '=', action['report_name']),],1757 action_context = action['context']
1758 0, False, False, context)1758 if (action_context.get('active_model')
1759 if len(res_id) > 0:1759 and action_context['active_ids']):
1760 file_name = reports.read(res_id[0], ['name'], context)['name']1760 # Use built-in ORM method to get data from DB
1761 else:1761 m = req.session.model(action_context['active_model'])
1762 file_name = action['report_name']1762 r = m.name_get(action_context['active_ids'], context)
1763 # Parse result to create a better filename
1764 item_names = [item[1] or str(item[0]) for item in r]
1765 if action.get('name'):
1766 item_names.insert(0, action['name'])
1767 file_name = '-'.join(item_names)
1763 file_name = '%s.%s' % (file_name, report_struct['format'])1768 file_name = '%s.%s' % (file_name, report_struct['format'])
1769 # Create safe filename
1770 p = re.compile('[/:(")<>|?*]|(\\\)')
1771 file_name = p.sub('_', file_name)
17641772
1765 return req.make_response(report,1773 return req.make_response(report,
1766 headers=[1774 headers=[