]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/exporter/views.py
Adds a file format option to xml backups.
[osqa.git] / forum_modules / exporter / views.py
index 37090372dbba0b86450e9d5117aacb108610f0a3..af77f5b0d4b14a13d218f819b361e9105ceaf8d0 100644 (file)
@@ -13,7 +13,7 @@ from threading import Thread
 import settings as selsettings
 from forum import settings
 
-from exporter import export, CACHE_KEY, EXPORT_STEPS, LAST_BACKUP, DATE_AND_AUTHOR_INF_SECTION, DATETIME_FORMAT
+from exporter import export, CACHE_KEY, EXPORT_STEPS, DATE_AND_AUTHOR_INF_SECTION, DATETIME_FORMAT
 from importer import start_import
 
 
@@ -77,14 +77,24 @@ def state(request):
 
 @admin_page
 def download(request):
-    fname = LAST_BACKUP
+    if request.GET and request.GET.get('file', None):
+        fname = os.path.join(selsettings.EXPORTER_BACKUP_STORAGE, request.GET.get('file'))
+    else:
+        raise Http404
 
     if not os.path.exists(fname):
         raise Http404
 
-    response = HttpResponse(open(fname, 'rb').read(), content_type='application/x-gzip')
+    if fname.endswith('.gz'):
+        content_type='application/x-gzip'
+        filename = 'backup.tar.gz'
+    else:
+        content_type='application/zip'
+        filename = 'backup.zip'
+
+    response = HttpResponse(open(fname, 'rb').read(), content_type=content_type)
     response['Content-Length'] = os.path.getsize(fname)
-    response['Content-Disposition'] = 'attachment; filename=backup.tar.gz'
+    response['Content-Disposition'] = 'attachment; filename=%s' % filename
     return response