From f1eecb349d008e0464905f925f07937fc993cd47 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Mon, 31 Dec 2012 14:58:45 +0000 Subject: [PATCH] Add timestamp to downloads svn: r20907 --- gramps/webapp/grampsdb/views.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gramps/webapp/grampsdb/views.py b/gramps/webapp/grampsdb/views.py index e00b7d1c2..3308b5e79 100644 --- a/gramps/webapp/grampsdb/views.py +++ b/gramps/webapp/grampsdb/views.py @@ -32,6 +32,7 @@ Each object can be operated on with the following actions: import os import sys +import time if sys.version_info[0] < 3: import cPickle as pickle else: @@ -171,6 +172,12 @@ def user_page(request, username=None): else: raise Http404(_("Requested page is not accessible.")) +def timestamp(): + """ + Construct a string of current time for filenames. + """ + return time.strftime("%Y-%m-%d:%H:%M:%S") + def send_file(request, filename, mimetype): """ Send a file through Django without loading the whole file into @@ -215,17 +222,18 @@ def process_report_run(request, handle): args[key] = value ############################################################################# if report.report_type == "report": - filename = "/tmp/%s-%s.%s" % (str(profile.user.username), str(handle), args["off"]) + filename = "/tmp/%s-%s-%s.%s" % (str(profile.user.username), str(handle), timestamp(), args["off"]) run_report(db, handle, of=filename, **args) mimetype = 'application/%s' % args["off"] elif report.report_type == "export": - filename = "/tmp/%s-%s.%s" % (str(profile.user.username), str(handle), args["off"]) + filename = "/tmp/%s-%s-%s.%s" % (str(profile.user.username), str(handle), timestamp(), args["off"]) export_file(db, filename, gramps.cli.user.User()) # callback mimetype = 'text/plain' elif report.report_type == "import": - filename = download(args["i"], "/tmp/%s-%s.%s" % (str(profile.user.username), - str(handle), - args["iff"])) + filename = download(args["i"], "/tmp/%s-%s-%s.%s" % (str(profile.user.username), + str(handle), + timestamp(), + args["iff"])) if filename is not None: if True: # run in background, with error handling import threading