mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
proper filenames for originals and archived documents
This commit is contained in:
parent
64180b5668
commit
17a581495c
@ -241,6 +241,10 @@ class Document(models.Model):
|
|||||||
def file_name(self):
|
def file_name(self):
|
||||||
return slugify(str(self)) + self.file_type
|
return slugify(str(self)) + self.file_type
|
||||||
|
|
||||||
|
@property
|
||||||
|
def archive_file_name(self):
|
||||||
|
return slugify(str(self)) + ".pdf"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def file_type(self):
|
def file_type(self):
|
||||||
return mimetypes.guess_extension(str(self.mime_type))
|
return mimetypes.guess_extension(str(self.mime_type))
|
||||||
|
@ -138,8 +138,10 @@ class DocumentViewSet(RetrieveModelMixin,
|
|||||||
def file_response(self, pk, request, disposition):
|
def file_response(self, pk, request, disposition):
|
||||||
doc = Document.objects.get(id=pk)
|
doc = Document.objects.get(id=pk)
|
||||||
mime_type = doc.mime_type
|
mime_type = doc.mime_type
|
||||||
|
filename = doc.file_name
|
||||||
if not self.original_requested(request) and os.path.isfile(doc.archive_path): # NOQA: E501
|
if not self.original_requested(request) and os.path.isfile(doc.archive_path): # NOQA: E501
|
||||||
file_handle = doc.archive_file
|
file_handle = doc.archive_file
|
||||||
|
filename = doc.archive_file_name
|
||||||
mime_type = 'application/pdf'
|
mime_type = 'application/pdf'
|
||||||
elif doc.storage_type == Document.STORAGE_TYPE_UNENCRYPTED:
|
elif doc.storage_type == Document.STORAGE_TYPE_UNENCRYPTED:
|
||||||
file_handle = doc.source_file
|
file_handle = doc.source_file
|
||||||
@ -148,7 +150,7 @@ class DocumentViewSet(RetrieveModelMixin,
|
|||||||
|
|
||||||
response = HttpResponse(file_handle, content_type=mime_type)
|
response = HttpResponse(file_handle, content_type=mime_type)
|
||||||
response["Content-Disposition"] = '{}; filename="{}"'.format(
|
response["Content-Disposition"] = '{}; filename="{}"'.format(
|
||||||
disposition, doc.file_name)
|
disposition, filename)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@action(methods=['post'], detail=False)
|
@action(methods=['post'], detail=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user