[TASK] Begin introducing a service file for operations on sqlite and more.

This commit is contained in:
Jan Philipp Timme 2014-09-01 17:01:13 +02:00
parent 73dbacb74b
commit 89e76b6844
4 changed files with 13 additions and 7 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
citavi_mapper/private_settings.py
static/
media/*

View File

@ -148,18 +148,17 @@ class ProjectView(ProtectedFormView, SingleObjectMixin):
""" 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())
project_id = self.request.session[u'project_id']
file = form.files[u'file']
relative_path = default_storage.save('tmp/citavi_import.sqlite', ContentFile(file.read()))
relative_path = default_storage.save('tmp/project_import_' + project_id + '.ctt4', ContentFile(file.read()))
path = os.path.join(settings.MEDIA_ROOT, relative_path)
print "Path: " + path
#TODO: Use file to do things here.
from service.sqlitehelper import import_sqlite
import_sqlite(project_id=project_id, sqlite_file=path)
default_storage.delete('tmp/citavi_import.sqlite')
default_storage.delete(relative_path)
return super(ProjectView, self).form_valid(form)

2
service/__init__.py Normal file
View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

4
service/sqlitehelper.py Normal file
View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
def import_sqlite(project_id, sqlite_file):
pass