Commit d3e789c9 authored by Daniel STAN's avatar Daniel STAN

impressions: get_storage_dir (pour env de test)

parent 49afe7ae
......@@ -116,6 +116,18 @@ def get_club(request):
club = tuple(club)
return club
def get_storage_dir(login, filename):
"""Donne le chemin vers le fichier, pour enregistrement"""
if os.getenv('DBG_PRINTER', '0') == '0':
mkdir = ["sudo", "-n", "/usr/scripts/utils/chown_impressions.sh", login]
pattern = "/home/impressions/%s/%s"
else:
mkdir = ["mkdir", "-p", "/tmp/intranet/%s" % login]
pattern = "/tmp/intranet/%s/%s"
subprocess.check_call(mkdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
filepath = pattern % (login, filename)
return filepath
class NotPdfFile(Exception):
"""Exception levée si le fichier uploadé n'est pas un pdf"""
pass
......@@ -162,11 +174,9 @@ def view(request):
login_used = club
else:
login_used = login
createdir = subprocess.Popen(["sudo", "/usr/scripts/utils/chown_impressions.sh", login_used], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
createdir.communicate()
# On y enregistre ensuite le fichier
filename = fichier.name
filepath = "/home/impressions/%s/%s" % (login_used, filename)
filepath = get_storage_dir(login_used, filename)
with open(filepath, 'wb+') as destination:
for chunk in fichier.chunks():
destination.write(chunk)
......@@ -268,7 +278,7 @@ def view(request):
jo = Jobs.objects.filter(file=filename,login=login).latest('id')
if jo.club:
login = jo.club
job = impression("/home/impressions/%s/%s" % (login, filename), adh=login)
job = impression(get_storage_dir(login, filename), adh=login)
# On met à jour les options et on envoie
job.changeSettings(papier=format,couleur=couleur,copies=copies,agrafage=agrafe,perforation=perforation,livret=livr,recto_verso=rv)
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment