[TASK] Add very basic file handling. Upload processing still TODO.
This commit is contained in:
parent
988771a219
commit
73dbacb74b
|
@ -5,6 +5,8 @@ from django.http import HttpResponse, HttpResponseRedirect
|
||||||
class EnforceActiveProjectProxy():
|
class EnforceActiveProjectProxy():
|
||||||
|
|
||||||
def do_debug_output(self, request, *args, **kwargs):
|
def do_debug_output(self, request, *args, **kwargs):
|
||||||
|
if True:
|
||||||
|
return
|
||||||
print "\n########## <session> ##########"
|
print "\n########## <session> ##########"
|
||||||
print ',\n'.join("%s: %s" % item for item in request.session.items())
|
print ',\n'.join("%s: %s" % item for item in request.session.items())
|
||||||
print "########## </session> ##########"
|
print "########## </session> ##########"
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- 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.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.views.generic import TemplateView, FormView, CreateView, UpdateView
|
from django.views.generic import TemplateView, FormView, CreateView, UpdateView
|
||||||
from django.views.generic.detail import SingleObjectMixin
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
|
@ -140,12 +146,20 @@ class ProjectView(ProtectedFormView, SingleObjectMixin):
|
||||||
self.success_url = self.success_url + project_id
|
self.success_url = self.success_url + project_id
|
||||||
return super(ProjectView, self).post(request, *args, **kwargs)
|
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):
|
def form_valid(self, form, *args, **kwargs):
|
||||||
print("FORM:")
|
print("FORM:")
|
||||||
attrs = vars(form)
|
attrs = vars(form)
|
||||||
print ', '.join("%s: %s" % item for item in attrs.items())
|
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)
|
return super(ProjectView, self).form_valid(form)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue