--- a/webui.py
+++ b/webui.py
@@ -38,6 +38,7 @@
'maxchars': 500,
'maxresults': 0,
'perpage': 25,
+ 'csvfields': 'filename title author size time mtype url',
}
# sort fields/labels
@@ -111,6 +112,11 @@
for k, v in DEFAULTS.items():
value = select([bottle.request.get_cookie(k), v])
config[k] = type(v)(value)
+ # Fix csvfields: get rid of invalid ones to avoid needing tests in the dump function
+ cf = config['csvfields'].split()
+ ncf = [f for f in cf if f in FIELDS]
+ config['csvfields'] = ' '.join(ncf)
+ config['fields'] = ' '.join(FIELDS)
# get mountpoints
config['mounts'] = {}
for d in config['dirs']:
@@ -175,7 +181,7 @@
return '</span>'
#}}}
#{{{ recoll_search
-def recoll_search(q):
+def recoll_search(q, dosnippets=True):
config = get_config()
tstart = datetime.datetime.now()
results = []
@@ -213,7 +219,8 @@
d['label'] = select([d['title'], d['filename'], '?'], [None, ''])
d['sha'] = hashlib.sha1(d['url']+d['ipath']).hexdigest()
d['time'] = timestr(d['mtime'], config['timefmt'])
- d['snippet'] = query.makedocabstract(doc, highlighter).encode('utf-8')
+ if dosnippets:
+ d['snippet'] = query.makedocabstract(doc, highlighter).encode('utf-8')
results.append(d)
tend = datetime.datetime.now()
return results, nres, tend - tstart
@@ -317,18 +324,20 @@
#{{{ csv
@bottle.route('/csv')
def get_csv():
+ config = get_config()
query = get_query()
query['page'] = 0
qs = query_to_recoll_string(query)
bottle.response.headers['Content-Type'] = 'text/csv'
bottle.response.headers['Content-Disposition'] = 'attachment; filename=recoll-%s.csv' % normalise_filename(qs)
- res, nres, timer = recoll_search(query)
+ res, nres, timer = recoll_search(query, False)
si = StringIO.StringIO()
cw = csv.writer(si)
- cw.writerow(FIELDS)
+ fields = config['csvfields'].split()
+ cw.writerow(fields)
for doc in res:
row = []
- for f in FIELDS:
+ for f in fields:
row.append(doc[f])
cw.writerow(row)
return si.getvalue().strip("\r\n")