]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/exporter/views.py
Applies patches by Justing Grant. Makes several improvements in the db exporter.
[osqa.git] / forum_modules / exporter / views.py
index 1b9f664656f542706cace3267128c8885aefe973..fe8086ff9c38e5dc121bc4a2622e6f3ce2f4eb1b 100644 (file)
@@ -1,15 +1,19 @@
-import os
+import os, tarfile, ConfigParser, datetime
 
+from StringIO import StringIO
 from django.http import HttpResponse, HttpResponseRedirect, Http404
 from django.utils.translation import ugettext as _
 from django.utils import simplejson
 from django.core.cache import cache
 from django.core.urlresolvers import reverse
 from forum.views.admin import admin_tools_page, admin_page
+from forum.models import User
 from forms import ExporterForm
 from threading import Thread
+import settings as selsettings
+from forum import settings
 
-from exporter import export, CACHE_KEY, EXPORT_STEPS, LAST_BACKUP
+from exporter import export, CACHE_KEY, EXPORT_STEPS, LAST_BACKUP, DATE_AND_AUTHOR_INF_SECTION, DATETIME_FORMAT
 
 
 @admin_tools_page(_('exporter'), _('XML data export'))
@@ -23,7 +27,7 @@ def exporter(request):
         form = ExporterForm(request.POST)
 
         if form.is_valid():
-            thread = Thread(target=export, args=[form.cleaned_data])
+            thread = Thread(target=export, args=[form.cleaned_data, request.user])
             thread.setDaemon(True)
             thread.start()
 
@@ -31,8 +35,28 @@ def exporter(request):
     else:
         form = ExporterForm()
 
+    available = []
+
+    #folder = unicode(selsettings.EXPORTER_BACKUP_STORAGE)
+
+    #for f in os.listdir(folder):
+    #    if (not os.path.isdir(os.path.join(folder, f))) and f.endswith('.tar.gz'):
+    #        try:
+    #            tar = tarfile.open(os.path.join(folder, f), "r")
+    #            inf = ConfigParser.SafeConfigParser()
+    #            inf.readfp(tar.extractfile('backup.inf'))
+    #
+    #            if inf.get(DATE_AND_AUTHOR_INF_SECTION, 'site') == settings.APP_URL:
+    #                available.append({
+    #                    'author': User.objects.get(id=inf.get(DATE_AND_AUTHOR_INF_SECTION, 'author')),
+    #                    'date': datetime.strptime(inf.get(DATE_AND_AUTHOR_INF_SECTION, 'finished'), )
+    #                })
+    #        except Exception, e:
+    #            pass
+
     return ('modules/exporter/exporter.html', {
-        'form': form
+        'form': form,
+        'available': available,
     })
 
 @admin_page
@@ -60,4 +84,5 @@ def download(request):
     response['Content-Disposition'] = 'attachment; filename=backup.tar.gz'
     return response
 
+