diff options
Diffstat (limited to '')
-rw-r--r-- | accounts/templates/accounts/index.html | 2 | ||||
-rw-r--r-- | accounts/views.py | 49 |
2 files changed, 39 insertions, 12 deletions
diff --git a/accounts/templates/accounts/index.html b/accounts/templates/accounts/index.html index 847e44c..34b2da1 100644 --- a/accounts/templates/accounts/index.html +++ b/accounts/templates/accounts/index.html @@ -40,7 +40,7 @@ </div> <div class="input-field col l4 s12"> <select name="branca" disabled> - <option value="" disabled {{branca_default}}>Scegli</option> + <option value="" disabled {{branca_default}}>Nessuna</option> <option value="colonia" {{branca_castorini}}>Castorini</option> <option value="muta" {{branca_lupetti}}>Lupetti</option> <option value="reparto" {{branca_esploratori}}>Esploratori</option> diff --git a/accounts/views.py b/accounts/views.py index 230e3e1..af7527e 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -15,7 +15,12 @@ import dateparser import os from io import BytesIO from PIL import Image, UnidentifiedImageError - +from pdf2image import convert_from_path, convert_from_bytes +from pdf2image.exceptions import ( + PDFInfoNotInstalledError, + PDFPageCountError, + PDFSyntaxError +) @sensitive_variables("raw_passsword") def signup(request): @@ -156,11 +161,16 @@ def personal(request): name = files[0].name try: # if multiple files concatenate pictures - if len(files) == 1: - im = Image.open(files[0]) - else: - im = Image.open(files.pop(0)) - for f in files: + im = Image.new("RGB", (0, 0), (255, 255, 255)) + for f in files: + if f.name.endswith(".pdf"): + images = convert_from_bytes(f.read()) + for i in images: + dst = Image.new('RGB', (max(im.width, i.width), im.height + i.height), (255, 255, 255)) + dst.paste(im, (0, 0)) + dst.paste(i, (0, im.height)) + im = dst + else: i = Image.open(f) dst = Image.new('RGB', (max(im.width, i.width), im.height + i.height), (255, 255, 255)) dst.paste(im, (0, 0)) @@ -179,6 +189,12 @@ def personal(request): except UnidentifiedImageError: error = True error_text = "Il file non è un immagine valida" + except PDFPageCountError: + error = True + error_text = "Il file non è un pdf valido" + except PDFSyntaxError: + error = True + error_text = "Il file non è un pdf valido" except IOError: error = True error_text = "Il file è un immagine troppo grande" @@ -188,11 +204,16 @@ def personal(request): name = files[0].name try: # if multiple files concatenate pictures - if len(files) == 1: - im = Image.open(files[0]) - else: - im = Image.open(files.pop(0)) - for f in files: + im = Image.new("RGB", (0, 0), (255, 255, 255)) + for f in files: + if f.name.endswith(".pdf"): + images = convert_from_bytes(f.read()) + for i in images: + dst = Image.new('RGB', (max(im.width, i.width), im.height + i.height), (255, 255, 255)) + dst.paste(im, (0, 0)) + dst.paste(i, (0, im.height)) + im = dst + else: i = Image.open(f) dst = Image.new('RGB', (max(im.width, i.width), im.height + i.height), (255, 255, 255)) dst.paste(im, (0, 0)) @@ -211,6 +232,12 @@ def personal(request): except UnidentifiedImageError: error = True error_text = "Il file non è un immagine valida" + except PDFPageCountError: + error = True + error_text = "Il file non è un pdf valido" + except PDFSyntaxError: + error = True + error_text = "Il file non è un pdf valido" except IOError: error = True error_text = "Il file è un immagine troppo grande" |