[TASK] Add CitaviProject class, integrate first handling for uploaded projects.
This commit is contained in:
1 parent
c3b32d5de3
commit
f92e780380
2 files changed
+102
-26
No files matched your search
+27
-10
@@ -125,20 +125,37 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
|
||||
self.success_url = self.success_url + self.project_id + '/update'
|
||||
return super(UpdateProjectView, 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):
|
||||
""" This form_valid handles the file upload. """
|
||||
original_file = form.files[u'file']
|
||||
original_filename = str(original_file)
|
||||
relative_path = default_storage.save('tmp/project_' + self.project_id + '.ctt4', ContentFile(original_file.read()))
|
||||
path = os.path.join(settings.MEDIA_ROOT, relative_path)
|
||||
|
||||
#TODO: Actually validate that we get an SQLite3 file!
|
||||
""" Put file into temporary folder for analysis """
|
||||
relative_path = default_storage.save('tmp/project_' + str(self.project_id) + '.ctt4', ContentFile(original_file.read()))
|
||||
temp_sqlite = os.path.join(settings.MEDIA_ROOT, relative_path)
|
||||
|
||||
# Store this in the project model
|
||||
project = Project.objects.get(id=self.project_id)
|
||||
project.associated_filename = original_filename
|
||||
project.save()
|
||||
""" Test if SQLite is a valid citavi project. """
|
||||
from service import Citavi
|
||||
citavi_project = Citavi.CitaviProject(temp_sqlite)
|
||||
citavi_project_valid = citavi_project.is_valid()
|
||||
""" Free temporary ressources. """
|
||||
del citavi_project
|
||||
default_storage.delete(temp_sqlite)
|
||||
|
||||
if citavi_project_valid == False:
|
||||
""" TODO: Put up an error message or something. """
|
||||
pass
|
||||
else:
|
||||
""" Actually store file in citavi folder """
|
||||
relative_path = default_storage.save('citavi/project_' + str(self.project_id) + '.ctt4', ContentFile(original_file.read()))
|
||||
sqlite_path = os.path.join(settings.MEDIA_ROOT, relative_path)
|
||||
|
||||
""" Store new original filename in Project """
|
||||
project = Project.objects.get(id=self.project_id)
|
||||
project.associated_filename = original_filename
|
||||
project.save()
|
||||
|
||||
""" Refresh identities from citavi project. """
|
||||
# TODO
|
||||
return super(UpdateProjectView, self).form_valid(form)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user