Refactor Extension and Version: explicit constructors from File #191

Merged
Oleg-Komarov merged 6 commits from refactor-models into main 2024-06-20 14:40:41 +02:00
Showing only changes of commit dce7a40241 - Show all commits

View File

@ -36,13 +36,6 @@ class UploadFileView(LoginRequiredMixin, CreateView):
def form_valid(self, form):
"""Create an extension and a version already, associated with the user."""
file = form.save()
if file.user != self.request.user:
# this must never happen, but checking here to prevent misattributing the extension
# to a wrong user
raise Exception(
f'user {self.request.user} uploaded a file hash={file.hash} owned by {file.user}, '
f'this must never happen'
)
self.extension = Extension.create_from_file(file)
self.extension.create_version_from_file(file)
return super().form_valid(form)