Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix zip files #10

Merged
merged 1 commit into from
Jun 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions controllers/expedientes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
__author__ = "María Andrea Vignau (mavignau@gmail.com)"
__copyright__ = "(C) 2016 María Andrea Vignau. GNU GPL 3."

import zipfile
import os


linked_tables = ['movimiento', 'agenda', 'parte']
import zipfile

@auth.requires_login()
def index():
Expand Down Expand Up @@ -66,25 +68,27 @@ def index():
@auth.requires_login()
def download():
import io
#vars = request.args[0]
zip_filename = 'Movimiento.zip'
tempfile = io.BytesIO()
temparchive = zipfile.ZipFile(tempfile, 'w', zipfile.ZIP_DEFLATED)
#fileIDs = vars.values()
rows = db(db.movimiento.archivo != None).select()
try:
for file_id in rows:
file_single = file_id.archivo #Funciona
#file_single = 'movimiento.archivo.82426746fd76a46e.ZGF0b3MtZXN0cnVjdHVyYWxlcy0yMDE4LmNzdg==.csv'
fileLoc = db.movimiento.archivo.retrieve_file_properties(file_single)['path'] + '/' + file_single #Funciona
file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename']#Funciona
temparchive.writestr(file_single , open(fileLoc, 'rb').read()) #Funciona
#zip.write(file_id)
file_single = file_id.archivo # Funciona
if not file_single:
# if movimiento doesn't have a file, ignore it
continue
file_loc = db.movimiento.archivo.retrieve_file_properties(file_single)['path'] + '/' + file_single # Funciona
file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename'] # Funciona
temparchive.write(file_loc, file_name) # Funciona
finally:
temparchive.close() #writes
tempfile.seek(0)
response.headers['Content-Type'] = 'application/zip'
response.headers['Content-Disposition'] = 'attachment; filename = %s' % zip_filename

response.headers['Content-Type'] = 'application/zip'
response.headers['Content-Disposition'] = 'attachment; filename = %s' % zip_filename
res = response.stream(tempfile, chunk_size=4096)
return res


def vista_expediente():
Expand Down