selection multiple des photos à uploader

This commit is contained in:
2020-08-06 11:03:04 +02:00
parent aa19d3f936
commit ae498a9bc4
5 changed files with 104 additions and 86 deletions

View File

@@ -380,20 +380,22 @@ def upload_img(request):
if 'form.submitted' in request.params:
# récupère le fichier download dans le dossier /tmp
input_file = request.POST['filename'].file
input_name = request.POST['filename'].filename
ext_allowed = ['jpeg','jpg','png']
temp_file = downloadFile2Temp(input_file, input_name, ext_allowed)
if temp_file[:8] == 'ERREUR: ':
request.session.flash(temp_file, 'danger')
return HTTPFound(location=url)
# fabriquer le nom du rapport
filename = '%s-DD%s-%s-%s' % (societe, nochantier, norapport, input_name)
tempFile2Dossier(request, societe, nochantier, norapport, nosection, temp_file, filename, logged_in)
request.session.flash('%s : Ce fichier est téléchargé avec succès.' % input_name, 'success')
# récupère le(s) fichier(s) download dans le dossier /tmp
fileslist = request.POST.getall('files')
for f in fileslist:
input_file = f.file
input_name = f.filename
ext_allowed = ['jpeg','jpg','png']
temp_file = downloadFile2Temp(input_file, input_name, ext_allowed)
if temp_file[:8] == 'ERREUR: ':
request.session.flash(temp_file, 'danger')
return HTTPFound(location=url)
# fabriquer le nom du rapport
filename = '%s-DD%s-%s-%s' % (societe, nochantier, norapport, input_name)
tempFile2Dossier(request, societe, nochantier, norapport, nosection, temp_file, filename, logged_in)
request.session.flash('%s : Ce fichier est téléchargé avec succès.' % input_name, 'success')
# lire tous les photos attachées
photos = get_photos(request, nodossier, int(norapport), int(nosection))
@@ -967,50 +969,60 @@ def demandes(request):
return HTTPFound(location=request.route_url('home'))
raw_email = msg_data[0][1]
import pdb;pdb.set_trace()
# converts byte literal to string removing b''
raw_email_string = raw_email.decode('utf-8')
email_message = email.message_from_string(raw_email_string)
# get the message's body
body = ''
for part in email_message.walk():
ctype = part.get_content_type()
cdispo = str(part.get('Content-Disposition'))
# skip any text/plain (txt) attachments
if ctype == 'text/html' and 'attachment' not in cdispo:
body = part.get_payload(decode=True) # decode
break
# downloading attachment
temp_file_path = download_pdf_to_tmp(email_message)
# convertir le fichier pdf en texte
texte, extracted_file = pdf_convert_to_txt(temp_file_path)
nbLus = nbLus + 1
# mission annulée ?
if 'Objet : ANNULATION MISSION' in texte :
# genere ANNULATION mission MAIF
# import pdb;pdb.set_trace()
n = generer_annul_maif(request, societe, extracted_file, temp_file_path)
nbAnnules = nbAnnules + n
# déplacer le message dans la poubelle
conn.store(num, '+FLAGS', '\\Deleted')
elif 'ANNULATION ORDRE DE MISSION' in texte:
# genere ANNULATION mission DOMUS
nosin = str(body)[84:95]
# import pdb;pdb.set_trace()
n = generer_annul_domus(request, societe, nosin, temp_file_path)
nbAnnules = nbAnnules + n
try:
raw_email_string = raw_email.decode('utf-8')
except:
# déplacer le message dans la poubelle
conn.store(num, '+FLAGS', '\\Deleted')
conn.expunge()
else:
# genere le dossier d'après le mail
n = generer_mission(request, societe, criteria, extracted_file, temp_file_path)
nbCrees = nbCrees + n
# déplacer le message dans la poubelle
conn.store(num, '+FLAGS', '\\Deleted')
conn.expunge()
email_message = email.message_from_string(raw_email_string)
# get the message's body
body = ''
for part in email_message.walk():
ctype = part.get_content_type()
cdispo = str(part.get('Content-Disposition'))
# skip any text/plain (txt) attachments
if ctype == 'text/html' and 'attachment' not in cdispo:
body = part.get_payload(decode=True) # decode
break
# downloading attachment
temp_file_path = download_pdf_to_tmp(email_message)
# convertir le fichier pdf en texte
texte, extracted_file = pdf_convert_to_txt(temp_file_path)
nbLus = nbLus + 1
# mission annulée ?
if 'Objet : ANNULATION MISSION' in texte :
# genere ANNULATION mission MAIF
# import pdb;pdb.set_trace()
n = generer_annul_maif(request, societe, extracted_file, temp_file_path)
nbAnnules = nbAnnules + n
# déplacer le message dans la poubelle
conn.store(num, '+FLAGS', '\\Deleted')
conn.expunge()
elif 'ANNULATION ORDRE DE MISSION' in texte:
# genere ANNULATION mission DOMUS
nosin = str(body)[84:95]
# import pdb;pdb.set_trace()
n = generer_annul_domus(request, societe, nosin, temp_file_path)
nbAnnules = nbAnnules + n
# déplacer le message dans la poubelle
conn.store(num, '+FLAGS', '\\Deleted')
conn.expunge()
else:
# genere le dossier d'après le mail
n = generer_mission(request, societe, criteria, extracted_file, temp_file_path)
nbCrees = nbCrees + n
# déplacer le message dans la poubelle
conn.store(num, '+FLAGS', '\\Deleted')
conn.expunge()
conn.close()
# deconnexion du serveur
conn.logout()