Browse Source

Move printing_path from models to utils

fix_refill_balance
Maxime Bombar 7 years ago
parent
commit
ee9827deda
  1. 6
      printer/models.py
  2. 19
      printer/utils.py

6
printer/models.py

@ -26,6 +26,8 @@ from .settings import (
PRICES, PRICES,
) )
from .utils import user_printing_path
import math import math
""" """
@ -34,10 +36,6 @@ import math
""" """
def user_printing_path(instance, filename):
# File will be uploaded to MEDIA_ROOT/printings/user_<id>/<filename>
return 'printings/user_{0}/{1}'.format(instance.user.id, filename)
class JobWithOptions(RevMixin, models.Model): class JobWithOptions(RevMixin, models.Model):
""" """

19
printer/utils.py

@ -1,6 +1,16 @@
import subprocess import subprocess
def user_printing_path(instance, filename):
"""
Defines the path where will be uploaded the files
Currently MEDIA_ROOT/printings/user_<id>/<filename>
"""
# File will be uploaded to MEDIA_ROOT/printings/user_<id>/<filename>
return 'printings/user_{0}/{1}'.format(instance.user.id, filename)
def pdfinfo(file_path): def pdfinfo(file_path):
""" """
Uses pdfinfo to extract the PDF meta information. 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""" """Extracts the right hand value from a : delimited row"""
row=row.decode() row=row.decode()
return row.split(':', 1)[1].strip() return row.split(':', 1)[1].strip()
output = {} output = {}
labels = ['Title', 'Author', 'Creator', 'Producer', 'CreationDate', 'ModDate', labels = ['Title', 'Author', 'Creator', 'Producer', 'CreationDate', 'ModDate',
'Tagged', 'Pages', 'Encrypted', 'Page size', 'Tagged', 'Pages', 'Encrypted', 'Page size',
'File size', 'Optimized', 'PDF version'] 'File size', 'Optimized', 'PDF version']
cmd_output = subprocess.check_output(['/usr/bin/pdfinfo', file_path]) cmd_output = subprocess.check_output(['/usr/bin/pdfinfo', file_path])
for line in cmd_output.splitlines(): for line in cmd_output.splitlines():
for label in labels: for label in labels:
if label in line.decode(): if label in line.decode():
output[label] = _extract(line) output[label] = _extract(line)
return output return output

Loading…
Cancel
Save