Merge lp:~therp-nl/ocb-web/7.0_lp1261332_better_report_name into lp:ocb-web

Proposed by Ronald Portier (Therp)
Status: Merged
Merged at revision: 4197
Proposed branch: lp:~therp-nl/ocb-web/7.0_lp1261332_better_report_name
Merge into: lp:ocb-web
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/ocb-web/7.0_lp1261332_better_report_name
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp Approve
Lara (Therp) (community) test Approve
Yann Papouin Approve
Pedro Manuel Baeza code review and test Approve
Review via email: mp+219901@code.launchpad.net

Description of the change

Port 6.1 proposal to 7.0.

Please ignore the typo in the branchname (1261332 instead of 126322).

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

It works perfectly, and it's a very needed feature.

Thanks for bringing to 7.0.

A non-blocking question is PEP8 issue on l.22.

Regards.

review: Approve (code review and test)
4197. By Ronald Portier (Therp)

[PEP] Slight modification to satisfy pep8 in code generating report filename.

Revision history for this message
Ronald Portier (Therp) (rportier1962) wrote :

Thanks Pedro for the review.

I corrected the pep8 issue (and a trailing whitespace two lines before).

Regards,

Revision history for this message
Yann Papouin (yann-papouin) wrote :

Thanks,
Note that you can easily rename a branch from launchpad.

review: Approve
Revision history for this message
Lara (Therp) (lfreeke) :
review: Approve (test)
Revision history for this message
Yann Papouin (yann-papouin) wrote :

Please do not forgot the MP against official branch

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/controllers/main.py'
2--- addons/web/controllers/main.py 2014-02-21 11:58:55 +0000
3+++ addons/web/controllers/main.py 2014-05-19 12:42:22 +0000
4@@ -1751,16 +1751,24 @@
5 report = zlib.decompress(report)
6 report_mimetype = self.TYPES_MAPPING.get(
7 report_struct['format'], 'octet-stream')
8- file_name = action.get('name', 'report')
9- if 'name' not in action:
10- reports = req.session.model('ir.actions.report.xml')
11- res_id = reports.search([('report_name', '=', action['report_name']),],
12- 0, False, False, context)
13- if len(res_id) > 0:
14- file_name = reports.read(res_id[0], ['name'], context)['name']
15- else:
16- file_name = action['report_name']
17+ file_name = action['report_name']
18+ # Try to get current object model and their ids from context
19+ if 'context' in action:
20+ action_context = action['context']
21+ if (action_context.get('active_model')
22+ and action_context['active_ids']):
23+ # Use built-in ORM method to get data from DB
24+ m = req.session.model(action_context['active_model'])
25+ r = m.name_get(action_context['active_ids'], context)
26+ # Parse result to create a better filename
27+ item_names = [item[1] or str(item[0]) for item in r]
28+ if action.get('name'):
29+ item_names.insert(0, action['name'])
30+ file_name = '-'.join(item_names)
31 file_name = '%s.%s' % (file_name, report_struct['format'])
32+ # Create safe filename
33+ p = re.compile('[/:(")<>|?*]|(\\\)')
34+ file_name = p.sub('_', file_name)
35
36 return req.make_response(report,
37 headers=[

Subscribers

People subscribed via source and target branches