From 89e76b6844934c8c0191e641a1fb57bc78ae3736 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 1 Sep 2014 17:01:13 +0200 Subject: [PATCH] [TASK] Begin introducing a service file for operations on sqlite and more. --- .gitignore | 1 + frontend/views.py | 13 ++++++------- service/__init__.py | 2 ++ service/sqlitehelper.py | 4 ++++ 4 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 service/__init__.py create mode 100644 service/sqlitehelper.py diff --git a/.gitignore b/.gitignore index 6ceb9bf..2220269 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ citavi_mapper/private_settings.py static/ +media/* diff --git a/frontend/views.py b/frontend/views.py index a7398bc..f44784a 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -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. + #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) diff --git a/service/__init__.py b/service/__init__.py new file mode 100644 index 0000000..633f866 --- /dev/null +++ b/service/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- + diff --git a/service/sqlitehelper.py b/service/sqlitehelper.py new file mode 100644 index 0000000..0c02241 --- /dev/null +++ b/service/sqlitehelper.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +def import_sqlite(project_id, sqlite_file): + pass \ No newline at end of file