Merge pull request #1994 from normanjaeckel/FileNotFound

Fixed error if a PDF file was deleted from the server. Fixed #1988.
This commit is contained in:
Emanuel Schütze 2016-02-23 22:44:35 +01:00
commit ca5f707f74

View File

@ -24,7 +24,11 @@ class AngularCompatibleFileField(FileField):
'type': filetype 'type': filetype
} }
if filetype == 'application/pdf': if filetype == 'application/pdf':
result['pages'] = PdfFileReader(open(value.path, 'rb')).getNumPages() try:
result['pages'] = PdfFileReader(open(value.path, 'rb')).getNumPages()
except FileNotFoundError:
# File was deleted from server. Set 'pages' to 0.
result['pages'] = 0
return result return result