id	summary	reporter	owner	description	type	status	priority	component	severity	resolution	keywords	cc	release
7556	[Patch] Vote counter problem in trac 0.12	PeterLawrence	rjollos	I'm getting an issue with this plugin with trac 0.12.\r\nAfter installing this plugin it does not update the vote counter when clicked on, in my installation.\r\nHowever when I reload the page the vote counter is incremented.\r\nWhen investigating my trac log I found it was generating the following error.\r\n{{{\r\nFile "build\\bdist.win32\\egg\\tracvote\\__init__.py", line 152, in process_request\r\n    body, title)))\r\n  File "c:\\docume~1\\lp03\\locals~1\\temp\\1\\easy_install-kpxh76\\Trac-0.12-py2.7-win32.egg.tmp\\trac\\web\\api.py", line 412, in send\r\n    self.write(content)\r\n  File "c:\\docume~1\\lp03\\locals~1\\temp\\1\\easy_install-kpxh76\\Trac-0.12-py2.7-win32.egg.tmp\\trac\\web\\api.py", line 530, in write\r\n    raise ValueError("Can't send unicode content")\r\nValueError: Can't send unicode content\r\n}}}\r\nOn further investigation I think this is related to an API change in 0.12 to refuse taking unicode see http://trac.edgewall.org/ticket/8675\r\n\r\nTo fix it, for now, I've changed the function process_request, in the {{{__init__.py}}} file along similar lines as suggested in the above link. i.e. I convert the string passed to req.send to utf-8 if in an unicode format. See new process_request function below...\r\n\r\n{{{\r\ndef process_request(self, req):\r\n        req.perm.require('VOTE_MODIFY')\r\n        match = self.path_match.match(req.path_info)\r\n        vote, resource = match.groups()\r\n        resource = self.normalise_resource(resource)\r\n        vote = vote == 'up' and +1 or -1\r\n        old_vote = self.get_vote(req, resource)\r\n\r\n        if old_vote == vote:\r\n            vote = 0\r\n            self.set_vote(req, resource, 0)\r\n        else:\r\n            self.set_vote(req, resource, vote)\r\n\r\n        if req.args.get('js'):\r\n            body, title = self.format_votes(resource)\r\n            content = ':'.join((req.href.chrome('vote/' + self.image_map[vote][0]),\r\n                                req.href.chrome('vote/' + self.image_map[vote][1]),\r\n                                body, title));\r\n            if isinstance(content, unicode): \r\n _            content = content.encode('utf-8')                            \r\n            req.send(content);\r\n            \r\n        req.redirect(resource)\r\n}}}\r\n\r\n	defect	closed	normal	VotePlugin	normal	fixed	vote, unicode		0.12
