[TASK] Add very basic file handling. Upload processing still TODO.

This commit is contained in:
Jan Philipp Timme 2014-09-01 15:30:57 +02:00
parent 988771a219
commit 73dbacb74b
2 changed files with 18 additions and 2 deletions

View File

@ -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########## <session> ##########"
print ',\n'.join("%s: %s" % item for item in request.session.items())
print "########## </session> ##########"
@ -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("<proxy> You tried to work on a project with ID " + project_id_arg + ", but your active project id is " + request.session['project_id'] + ".")

View File

@ -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)