Modify

Opened 15 years ago

Closed 14 years ago

#6999 closed defect (fixed)

[Patch] CSV export crash + fix

Reported by: Mudrony László Owned by: Colin Guthrie
Priority: normal Component: WorkLogPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description

I tried the WorkLog plugin with current trac 0.12 branch. Works fine so far, but CSV export gave me an exception on Content-Length not being set for the request. Here's a fix as patch agains the 0.11 folder. To evade unicode trouble, I've copied the way trac does CSV (but not the RSS and query stuff) - it has the additional benefit of using Python's csv module. Only tested with trac 0.12..

Index: worklog/webui.py
===================================================================
--- worklog/webui.py	(revision 7854)
+++ worklog/webui.py	(working copy)
@@ -1,4 +1,7 @@
 import re
+from StringIO import StringIO
+import codecs
+import csv
 from util import *
 from time import time
 from datetime import tzinfo, timedelta, datetime
@@ -53,19 +56,20 @@
                 'summary',
                 'comment']
       sep=','
-      req.write(sep.join(fields) + CRLF)
 
+      content = StringIO()
+      writer = csv.writer(content, delimiter=sep, quoting=csv.QUOTE_MINIMAL)
+      writer.writerow([unicode(c).encode('utf-8') for c in fields])
+
       # Rows
       for row in log:
-        first = True
+        values=[]
         for field in fields:
-          if not first:
-            req.write(sep)
-          first = False
-          req.write(str(row[field])
-                    .replace(sep, '_').replace('\\', '\\\\')
-                    .replace('\n', '\\n').replace('\r', '\\r'))
-        req.write(CRLF)
+          values.append(unicode(row[field]).encode('utf-8'))
+        writer.writerow(values)
+
+      req.send_header('Content-Length', content.len)
+      req.write(content.getvalue())
     
     # IRequestHandler methods
     def match_request(self, req):

Attachments (0)

Change History (3)

comment:1 Changed 15 years ago by Mudrony László

Owner: changed from colin to Colin Guthrie

comment:2 Changed 14 years ago by Ryan J Ollos

Summary: CSV export crash + fix[Patch] CSV export crash + fix

#6998 closed as a duplicate.

comment:3 Changed 14 years ago by Colin Guthrie

Resolution: fixed
Status: newclosed

(In [9538]) Fix CSV export regarding utf8 encoding and other issues.

Closes #6999 (thanks for the patch and sorry for the delay)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Colin Guthrie.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.