]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/sximporter/views.py
Several improvements in the sx importer.
[osqa.git] / forum_modules / sximporter / views.py
1 from django.shortcuts import render_to_response\r
2 from django.template import RequestContext\r
3 from forum.views.admin import super_user_required\r
4 import importer\r
5 from zipfile import ZipFile\r
6 import os\r
7 \r
8 @super_user_required\r
9 def sximporter(request):\r
10     list = []\r
11     if request.method == "POST" and "dump" in request.FILES:\r
12         dump = ZipFile(request.FILES['dump'])\r
13         members = [f for f in dump.namelist() if f.endswith('.xml')]\r
14         extract_to = os.path.join(os.path.dirname(__file__), 'tmp')\r
15         dump.extractall(extract_to, members)\r
16         importer.sximport(extract_to, request.POST)\r
17         dump.close()\r
18 \r
19     return render_to_response('modules/sximporter/page.html', {\r
20     'names': list\r
21     }, context_instance=RequestContext(request))