Conjunto de cambios 17dcd3a en seiven para gestion_informacion
- Fecha y hora:
- 13/12/2016 10:32:58 (hace 7 años)
- Branches:
- master, carga
- Children:
- 3ccd153
- Parents:
- 9ae3a72
- Fichero:
-
- 1 editado
Leyenda
- No modificado
- Añadido
- Eliminado
-
gestion_informacion/ajax.py
re9477bd r17dcd3a 12 12 # @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> 13 13 from __future__ import unicode_literals, absolute_import 14 15 import os 14 16 15 17 from django.http import HttpResponse … … 27 29 import logging 28 30 import json 29 import pyexcel30 import csv31 31 import xlwt 32 32 … … 68 68 modelo = apps.get_model(app, mod) 69 69 workbook = xlwt.Workbook() 70 sheet = workbook.add_sheet("Datos" )70 sheet = workbook.add_sheet("Datos", cell_overwrite_ok=True) 71 71 instance = modelo() 72 datos = instance.gestion_init(**filter) 73 font_bold = xlwt.easyxf('font: bold 1') 72 contenido = instance.gestion_init(**filter) 74 73 75 if datos['cabecera'][0]: 76 c = 0 74 row = 0 75 ## Loop que permite agregar datos al archivo a descargar 76 for con in contenido['fields']: 77 index_col, style = 0, 'align: horiz center;' 78 for col in con: 79 if 'color' in col: 80 style += 'pattern: pattern solid, fore_colour %s;' % col['color'] 81 if 'text_color' in col: 82 style += 'font: color %s, bold True;' % col['text_color'] 83 custom_style = xlwt.easyxf(style) 84 sheet.write(row, index_col, col['tag'], custom_style) 85 if 'cabecera' in col: 86 sheet.col(index_col).width = int(333 * (len(col['tag']) + 1)) 77 87 78 for cabecera in datos['cabecera'][0]: 79 style = font_bold 80 if cabecera['color'] and cabecera['text_color']: 81 style = xlwt.easyxf('pattern: pattern solid, fore_colour %s; font: color %s, bold True; align: horiz center;' % (cabecera['color'], cabecera['text_color'])) 82 if cabecera['combine'] > 0: 83 count_merge = c + cabecera['combine'] 84 sheet.write_merge(0, 0, c, count_merge, cabecera['tag'], style) 85 c = count_merge + 1 88 if 'combine' in col and col['combine'] > 0: 89 sheet.merge(row, row, index_col, (index_col + (col['combine']-1)), custom_style) 90 index_col = col['combine'] + index_col 86 91 else: 87 sheet.write(0, c, cabecera['tag'], style) 88 sheet.col(c).width = int(256 * (len(cabecera['tag']) + 1)) 89 c += 1 92 index_col += 1 93 row += 1 90 94 91 i = 0 92 for cabecera in datos['cabecera'][1]: 93 sheet.write(1, i, cabecera['label'], font_bold) 94 sheet.col(i).width = int(256 * (len(cabecera['label']) + 1)) 95 i += 1 95 # Ruta y nombre del archivo a generar 96 archivo = "%s/%s.xls" % (settings.GESTION_INFORMACION_FILES, contenido['output']) 96 97 97 # Se obtiene la cantidad de datos 98 cantidad = len(datos['data']) 99 # Si existen datos se crean las filas requeridas 100 if cantidad > 0: 101 for i in range(1, cantidad + 1): 102 row = len(datos['cabecera']) 103 for j in range(0, row): 104 sheet.write(i, j, datos['data'][i - 1][j]) 105 106 archivo = "%s/%s.xls" % (settings.GESTION_INFORMACION_FILES, datos['output']) 107 98 # Guarda el contenido de la hoja de cálculo al archivo indicado 108 99 workbook.save(archivo) 109 100 110 open_file = "%s.xls" % datos['output'] 101 # Nombre del archivo a utilizar para la descarga 102 open_file = "%s.xls" % contenido['output'] 111 103 112 104 return HttpResponse(json.dumps({ … … 158 150 process = instance.gestion_process(archivo, request.user, **filter) 159 151 152 # elimina el archivo después de cargar los datos 153 os.unlink(ruta) 154 160 155 if process['result']: 161 156 return HttpResponse(json.dumps({'result': True, 'message': str(MSG_UPLOAD_FILE_SUCCESS)}))
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.