From 5c4c56244c20bd2e567a8ad11d79cc8ff4cbd36e Mon Sep 17 00:00:00 2001 From: Maxime Bombar Date: Tue, 25 Sep 2018 13:39:12 +0200 Subject: [PATCH] Move printing_path from models to utils --- printer/models.py | 6 ++---- printer/utils.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/printer/models.py b/printer/models.py index 7c61e298..782753db 100644 --- a/printer/models.py +++ b/printer/models.py @@ -26,6 +26,8 @@ from .settings import ( PRICES, ) +from .utils import user_printing_path + import math """ @@ -34,10 +36,6 @@ import math """ -def user_printing_path(instance, filename): - # File will be uploaded to MEDIA_ROOT/printings/user_/ - return 'printings/user_{0}/{1}'.format(instance.user.id, filename) - class JobWithOptions(RevMixin, models.Model): """ diff --git a/printer/utils.py b/printer/utils.py index 89a6b522..fffec47d 100644 --- a/printer/utils.py +++ b/printer/utils.py @@ -1,6 +1,16 @@ import subprocess +def user_printing_path(instance, filename): + """ + Defines the path where will be uploaded the files + Currently MEDIA_ROOT/printings/user_/ + """ + # File will be uploaded to MEDIA_ROOT/printings/user_/ + return 'printings/user_{0}/{1}'.format(instance.user.id, filename) + + + def pdfinfo(file_path): """ Uses pdfinfo to extract the PDF meta information. @@ -11,18 +21,17 @@ def pdfinfo(file_path): """Extracts the right hand value from a : delimited row""" row=row.decode() return row.split(':', 1)[1].strip() - + output = {} - + labels = ['Title', 'Author', 'Creator', 'Producer', 'CreationDate', 'ModDate', 'Tagged', 'Pages', 'Encrypted', 'Page size', 'File size', 'Optimized', 'PDF version'] - + cmd_output = subprocess.check_output(['/usr/bin/pdfinfo', file_path]) for line in cmd_output.splitlines(): for label in labels: if label in line.decode(): output[label] = _extract(line) - + return output -