From 1d2b0ca2d9bf48fc1a43ed3fc449734b14f716a4 Mon Sep 17 00:00:00 2001 From: mipel Date: Wed, 1 Sep 2021 16:40:36 +0200 Subject: [PATCH] #18 File upload in certain folders * increases max_size for FileFields --> triggers when the file name will be automatically changed during upload * adds Http404 Exception in case document file does not exist anymore on the hard drive --- compensation/models.py | 6 ++++-- ema/models.py | 3 ++- intervention/models.py | 8 +++++--- konova/utils/documents.py | 7 +++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/compensation/models.py b/compensation/models.py index c2b47d35..b4a3de37 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -208,7 +208,8 @@ class CompensationDocument(AbstractDocument): related_name="documents", ) file = models.FileField( - upload_to=generate_document_file_upload_path + upload_to=generate_document_file_upload_path, + max_length=1000, ) @@ -323,7 +324,8 @@ class EcoAccountDocument(AbstractDocument): related_name="documents", ) file = models.FileField( - upload_to=generate_document_file_upload_path + upload_to=generate_document_file_upload_path, + max_length=1000, ) diff --git a/ema/models.py b/ema/models.py index c57432bb..109120f6 100644 --- a/ema/models.py +++ b/ema/models.py @@ -97,5 +97,6 @@ class EmaDocument(AbstractDocument): related_name="documents", ) file = models.FileField( - upload_to=generate_document_file_upload_path + upload_to=generate_document_file_upload_path, + max_length=1000, ) \ No newline at end of file diff --git a/intervention/models.py b/intervention/models.py index e5ad1687..31b430f8 100644 --- a/intervention/models.py +++ b/intervention/models.py @@ -86,7 +86,8 @@ class RevocationDocument(AbstractDocument): related_name="document", ) file = models.FileField( - upload_to=generate_document_file_upload_path + upload_to=generate_document_file_upload_path, + max_length=1000, ) @property @@ -334,5 +335,6 @@ class InterventionDocument(AbstractDocument): related_name="documents", ) file = models.FileField( - upload_to=generate_document_file_upload_path - ) \ No newline at end of file + upload_to=generate_document_file_upload_path, + max_length=1000, + ) diff --git a/konova/utils/documents.py b/konova/utils/documents.py index 7960f635..695347c3 100644 --- a/konova/utils/documents.py +++ b/konova/utils/documents.py @@ -5,7 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de Created on: 01.09.21 """ -from django.http import FileResponse, HttpRequest +from django.http import FileResponse, HttpRequest, HttpResponse, Http404 from django.utils.translation import gettext_lazy as _ from konova.forms import RemoveModalForm @@ -22,7 +22,10 @@ def get_document(doc: AbstractDocument): Returns: """ - return FileResponse(doc.file, as_attachment=True) + try: + return FileResponse(doc.file, as_attachment=True) + except FileNotFoundError: + raise Http404() def remove_document(request: HttpRequest, doc: AbstractDocument):