1 from django.shortcuts import render_to_response
2 from django.template import RequestContext
3 from forum.http_responses import HttpResponseUnauthorized
4 from forum.models import User
6 from zipfile import ZipFile
9 def sximporter(request):
10 if (not User.objects.exists()) or (request.user.is_authenticated() and request.user.is_superuser):
12 if request.method == "POST" and "dump" in request.FILES:
13 dump = ZipFile(request.FILES['dump'])
14 members = [f for f in dump.namelist() if f.endswith('.xml')]
15 extract_to = os.path.join(os.path.dirname(__file__), 'tmp')
17 if not os.path.exists(extract_to):
18 os.makedirs(extract_to)
21 f = open(os.path.join(extract_to, m), 'w')
25 #dump.extractall(extract_to, members)
28 options = dict([(k, v) for k, v in request.POST.items()])
29 options['authenticated_user'] = (request.user.is_authenticated() and (request.user,) or (None,))[0]
31 importer.sximport(extract_to, options)
33 return render_to_response('modules/sximporter/page.html', {
35 }, context_instance=RequestContext(request))
37 return HttpResponseUnauthorized(request)