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
