Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.6] Fix the pdf editing #77

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions osis_document/api/views/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
# ##############################################################################
import sys
from io import BytesIO
from tempfile import TemporaryFile

import filetype
from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.utils.translation import gettext_lazy as _
from rest_framework import status
from rest_framework.generics import get_object_or_404
Expand Down Expand Up @@ -94,7 +93,12 @@ def post(self, request, *args, **kwargs):
writer.write(temp_bytes)
temp_bytes.seek(0)
file = InMemoryUploadedFile(
temp_bytes, None, file.name, file.content_type, sys.getsizeof(temp_bytes), None
temp_bytes,
None,
file.name,
file.content_type,
sys.getsizeof(temp_bytes),
None,
)

# Process file: calculate hash and save it to db
Expand All @@ -103,7 +107,7 @@ def post(self, request, *args, **kwargs):
fileguess = filetype.guess(bytesa)
if fileguess.mime != file.content_type or file.content_type != 'application/pdf':
raise MimeMismatch
upload.file = file
upload.file.save(upload.file.name, file)
upload.size = file.size
upload.metadata['hash'] = calculate_hash(file)
upload.save()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

setup(
name='OSIS Document',
version='0.5',
version='0.6',
description='Document management API and widget',
url='http://github.com/uclouvain/osis-document',
author='Université catholique de Louvain',
Expand Down