aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--accounts/templates/accounts/index.html2
-rw-r--r--accounts/views.py49
-rw-r--r--requirements.txt1
-rw-r--r--server/templates/server/user_list.html2
4 files changed, 41 insertions, 13 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"
diff --git a/requirements.txt b/requirements.txt
index 82f7c89..90dceca 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,3 +3,4 @@ pillow
pdfkit
dateparser
pytz
+pdf2image
diff --git a/server/templates/server/user_list.html b/server/templates/server/user_list.html
index afd4163..a197001 100644
--- a/server/templates/server/user_list.html
+++ b/server/templates/server/user_list.html
@@ -116,7 +116,7 @@
<label for="home_phone">Telefono di casa</label>
</div>
<div class="input-field col l4 s12">
- <input disabled value="{{user.1.email}}" name="email" id="email" type="text" >
+ <input disabled value="{{user.0.email}}" name="email" id="email" type="text" >
<label for="email">Email</label>
</div>
<div class="input-field col l8 s12">