diff --git a/frontend/proxy.py b/frontend/proxy.py index 5f6bc90..f1b7a6e 100644 --- a/frontend/proxy.py +++ b/frontend/proxy.py @@ -5,6 +5,8 @@ from django.http import HttpResponse, HttpResponseRedirect class EnforceActiveProjectProxy(): def do_debug_output(self, request, *args, **kwargs): + if True: + return print "\n########## ##########" print ',\n'.join("%s: %s" % item for item in request.session.items()) print "########## ##########" @@ -22,8 +24,8 @@ class EnforceActiveProjectProxy(): # kwargs project_id AND path project_id have to match! print request.path try: - project_id_arg = args[2][u'project_id'] - if request.session[u'project_id'] != None: + project_id_arg = args[2][u'project_id'] + if request.session[u'project_id'] != None: print "Active project ID: " + request.session[u'project_id'] if project_id_arg != request.session[u'project_id']: return HttpResponse(" You tried to work on a project with ID " + project_id_arg + ", but your active project id is " + request.session['project_id'] + ".") diff --git a/frontend/views.py b/frontend/views.py index 94047dc..a7398bc 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -1,5 +1,11 @@ # -*- coding: utf-8 -*- +# File upload related imports +import os +from django.core.files.storage import default_storage +from django.core.files.base import ContentFile +from django.conf import settings + from django.http import HttpResponse, HttpResponseRedirect from django.views.generic import TemplateView, FormView, CreateView, UpdateView from django.views.generic.detail import SingleObjectMixin @@ -140,12 +146,20 @@ class ProjectView(ProtectedFormView, SingleObjectMixin): self.success_url = self.success_url + project_id return super(ProjectView, self).post(request, *args, **kwargs) + """ This form_valid handles the file uploads and triggers a citavi schema import and things. """ def form_valid(self, form, *args, **kwargs): print("FORM:") attrs = vars(form) print ', '.join("%s: %s" % item for item in attrs.items()) + file = form.files[u'file'] + relative_path = default_storage.save('tmp/citavi_import.sqlite', ContentFile(file.read())) + path = os.path.join(settings.MEDIA_ROOT, relative_path) + print "Path: " + path + #TODO: Use file to do things here. + + default_storage.delete('tmp/citavi_import.sqlite') return super(ProjectView, self).form_valid(form)