Merge lp:~openerp-dev/openobject-addons/6.0-opw-578969-cbi into lp:openobject-addons/6.0

Proposed by Chris Biersbach (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/6.0-opw-578969-cbi
Merge into: lp:openobject-addons/6.0
Diff against target: 63 lines (+11/-7)
1 file modified
survey/wizard/survey_send_invitation.py (+11/-7)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.0-opw-578969-cbi
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+127648@code.launchpad.net

Description of the change

To reproduce this issue, try to send invitations via the module survey.

On non-english-locale systems, this will cause a Traceback with a UnicodeDecodeError.

The cause of this is the function string.letters, called when generating the password.
This return only a-z,A-Z in english locale but also special characters in other locale.
The solution was to replace it with a call to string.ascii_letters, which always return a-z,A-Z.

I also removed some unused code that has been there for a long time (2010) and was never used since, so it is not needed anymore. I figured that it was some old debugging code that was not removed.

To post a comment you must log in.
5352. By Chris Biersbach (OpenERP)

[FIX] A report was created in a directory where sometimes the user has no write access. I changed this to automatically detect the temporary folder of the OS and create the report there, which is always possible

Unmerged revisions

5352. By Chris Biersbach (OpenERP)

[FIX] A report was created in a directory where sometimes the user has no write access. I changed this to automatically detect the temporary folder of the OS and create the report there, which is always possible

5351. By Chris Biersbach (OpenERP)

[FIX] changed a call to string.letters into a call to string.ascii_letters to avoid problems related to non-ascii characters. Also removed some unused code.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'survey/wizard/survey_send_invitation.py'
2--- survey/wizard/survey_send_invitation.py 2011-01-14 00:11:01 +0000
3+++ survey/wizard/survey_send_invitation.py 2012-10-09 12:04:21 +0000
4@@ -56,7 +56,7 @@
5 }
6
7 def genpasswd(self):
8- chars = string.letters + string.digits
9+ chars = string.ascii_letters + string.digits
10 return ''.join([choice(chars) for i in range(6)])
11
12 def default_get(self, cr, uid, fields_list, context=None):
13@@ -81,7 +81,13 @@
14 if not report_name or not res_ids:
15 return (False, Exception('Report name and Resources ids are required !!!'))
16 try:
17- ret_file_name = addons.get_module_resource('survey', 'report') + file_name + '.pdf'
18+ # Windows: Use %temp% environment variable
19+ if os.name == 'nt':
20+ tempfolder = os.environ['temp']
21+ # Unixoid Oses: user /tmp
22+ elif os.name == 'posix':
23+ tempfolder = '/tmp'
24+ ret_file_name = tempfolder + os.sep + file_name + '.pdf'
25 service = netsvc.LocalService(report_name);
26 (result, format) = service.create(cr, uid, res_ids, {}, {})
27 fp = open(ret_file_name, 'wb+');
28@@ -110,7 +116,6 @@
29 act_id = self.pool.get('ir.actions.act_window')
30 act_id = act_id.search(cr, uid, [('res_model', '=' , 'survey.name.wiz'), \
31 ('view_type', '=', 'form')])
32- out = "login,password\n"
33 skipped = 0
34 existing = ""
35 created = ""
36@@ -125,8 +130,8 @@
37 for use in exist_user:
38 new_user.append(use.id)
39 for id in survey_ref.browse(cr, uid, survey_ids):
40- report = self.create_report(cr, uid, [id.id], 'report.survey.form', id.title)
41- file = open(addons.get_module_resource('survey', 'report') + id.title +".pdf")
42+ report, ret_file_name = self.create_report(cr, uid, [id.id], 'report.survey.form', id.title)
43+ file = open(ret_file_name)
44 file_data = ""
45 while 1:
46 line = file.readline()
47@@ -135,7 +140,7 @@
48 break
49 attachments.append((id.title +".pdf",file_data))
50 file.close()
51- os.remove(addons.get_module_resource('survey', 'report') + id.title +".pdf")
52+ os.remove(ret_file_name)
53
54 for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids):
55 for addr in partner.address:
56@@ -168,7 +173,6 @@
57 (user_email.name, user_email.login, user_email.password)
58 continue
59 passwd= self.genpasswd()
60- out+= addr.email + ',' + passwd + '\n'
61 mail= record['mail'] % {'login' : addr.email, 'passwd' : passwd, 'name' : addr.name}
62 if record['send_mail']:
63 ans = tools.email_send(record['mail_from'], [addr.email], \