Here is a patch that enables exporting csv with actual names of linked items instead of their ids. It adds a new action, "export_csv_names" to the "extensions" directory in your tracker.
The action works like export_csv except on columns with the Link type. The action tries to find a column called name in the linked class, or username if the class is user. If it is found, it prints this column instead of the id. Simply change the lines in the desired html pages from export_csv to export_csv_names, copy this file to the extensions directory, and that's it.
This action has been evaluated on Roundup 0.8.2 only, and was updated from the original version that ran under 0.7.
[BEWARE: get the patch from the wiki page source, not from the html display, since the wiki software removes quotes. Any suggestions of a better way to put this patch online are welcome.]
(cut here)----ExportCSVNamesAction.py-------------------- from roundup.cgi.actions import Action from roundup.cgi import templating from roundup import hyperdbimport csv
class ExportCSVNamesAction(Action): name =
exportpermissionType =Viewdef handle(self): ''' Export the specified search query as CSV. ''' # figure the request request = templating.HTMLRequest(self.client) filterspec = request.filterspec sort = request.sort group = request.group columns = request.columns klass = self.db.getclass(request.classname)
# full-text search if request.search_text: matches = self.db.indexer.search( re.findall(r'\b\w{2,25}\b', request.search_text), klass) else: matches = None
h = self.client.additional_headers h['Content-Type'] =
text/csv# some browsers will honor the filename here... h['Content-Disposition'] =inline; filename=query.csvself.client.header()
if self.client.env['REQUEST_METHOD'] == 'HEAD': # all done, return a dummy string return
dummywriter = csv.writer(self.client.request.wfile) writer.writerow(columns)
# Figure out Link columns represent = {}
def repr_link(cls,col): def f(x): if x==None: return "" else: return str(cls.get(x,col)) return f
props = klass.getprops()
for col in columns: represent[col] = str if isinstance(props[col], hyperdb.Link): cn = props[col].classname cl = self.db.getclass(cn) if cl.getprops().has_key(
name): represent[col] = repr_link(cl,name) elif cn == 'user': represent[col] = repr_link(cl,username)# and search for itemid in klass.filter(matches, filterspec, sort, group): writer.writerow([represent[col](klass.get(itemid, col)) for col in columns])
return
\ndef init(instance): instance.registerAction(
export_csv_names, ExportCSVNamesAction)# vim: set filetype=python sts=4 sw=4 et si
(cut here)----ExportCSVNamesAction.py--------------------