[FIX] website_slides: Don't set completion_time for encrypt/corrupt PDF

Steps to reproduce:

  - Install eLearning module
  - Go to eLearning, open course Basics of Gardening and edit it
  - Click on `How to Grow and Harvest The Best Strawberries | Basics`
  - Upload an encrypted PDF as Attachement

Issue:

  Traceback is raised :
  utils.PdfReadError("File has not been decrypted")

Cause:

  When trying to calculate `completion_time` to read pages, we try to
  get the number of pages of the pdf but an error will be raised if the
  pdf is encrypted.

Solution:

  If not possible to get number of pages, we dont set/update the
  completion_time.

opw-2612529

closes odoo/odoo#79017

X-original-commit: 8eac410996bd9813cf1972ac6e71560ddb582775
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
Nasreddin Boulif (bon)
2021-10-27 18:41:20 +00:00
parent 5a35d6748a
commit 6647d70f53
@@ -362,6 +362,10 @@ class Slide(models.Model):
data = base64.b64decode(self.datas)
if data.startswith(b'%PDF-'):
pdf = PyPDF2.PdfFileReader(io.BytesIO(data), overwriteWarnings=False, strict=False)
try:
pdf.getNumPages()
except PyPDF2.utils.PdfReadError:
return
self.completion_time = (5 * len(pdf.pages)) / 60
else:
self.slide_type = 'infographic'