[BUGFIX] Make django replace pre-existing uploaded files while updating them.

This commit is contained in:
Jan Philipp Timme 2014-09-16 11:44:06 +02:00
parent f92e780380
commit 31bc03510d
1 changed files with 11 additions and 3 deletions

View File

@ -131,7 +131,8 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
original_filename = str(original_file) original_filename = str(original_file)
""" Put file into temporary folder for analysis """ """ Put file into temporary folder for analysis """
relative_path = default_storage.save('tmp/project_' + str(self.project_id) + '.ctt4', ContentFile(original_file.read())) target_filename = 'tmp/project_' + str(self.project_id) + '.ctt4'
relative_path = default_storage.save(target_filename, ContentFile(original_file.read()))
temp_sqlite = os.path.join(settings.MEDIA_ROOT, relative_path) temp_sqlite = os.path.join(settings.MEDIA_ROOT, relative_path)
""" Test if SQLite is a valid citavi project. """ """ Test if SQLite is a valid citavi project. """
@ -146,8 +147,13 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
""" TODO: Put up an error message or something. """ """ TODO: Put up an error message or something. """
pass pass
else: else:
target_filename = 'citavi/project_' + str(self.project_id) + '.ctt4'
""" Remove eventually pre-existing citavi file. """
if default_storage.exists(target_filename):
default_storage.delete(target_filename)
""" Actually store file in citavi folder """ """ Actually store file in citavi folder """
relative_path = default_storage.save('citavi/project_' + str(self.project_id) + '.ctt4', ContentFile(original_file.read())) relative_path = default_storage.save(target_filename, ContentFile(original_file.read()))
sqlite_path = os.path.join(settings.MEDIA_ROOT, relative_path) sqlite_path = os.path.join(settings.MEDIA_ROOT, relative_path)
""" Store new original filename in Project """ """ Store new original filename in Project """
@ -157,5 +163,7 @@ class UpdateProjectView(ProtectedFormView, SingleObjectMixin):
""" Refresh identities from citavi project. """ """ Refresh identities from citavi project. """
# TODO # TODO
#citavi_project = Citavi.CitaviProject(sqlite_path)
#del citavi_project
return super(UpdateProjectView, self).form_valid(form) return super(UpdateProjectView, self).form_valid(form)