- Fecha y hora:
- 13/12/2016 10:32:58 (hace 7 años)
- Branches:
- master, carga
- Children:
- 3ccd153
- Parents:
- 9ae3a72
- Ubicación:
- economico
- Ficheros:
-
- 2 editados
Leyenda
- No modificado
- Añadido
- Eliminado
-
economico/models.py
r9ae3a72 r17dcd3a 18 18 from django.utils.encoding import python_2_unicode_compatible 19 19 from django.utils.translation import ugettext_lazy as _ 20 from django.db.models import Q 21 from datetime import datetime 20 22 21 23 from base.constant import ( … … 52 54 ## Ciudad del registro. La información registrada es solo para el tipo de dominio por ciudad 53 55 ciudad = models.CharField(max_length=3, choices=DOMINIO[1:], null=True, default=None, verbose_name=_("Ciudad")) 56 57 ## Registro del mes y año 58 fecha = models.DateField(null=True, verbose_name=_("Fecha")) 54 59 55 60 class Meta: … … 68 73 @return Devuelve los datos a incluír en el archivo 69 74 """ 75 76 fields = [ 77 [ 78 {'tag': '', 'cabecera': True}, 79 {'tag': '', 'cabecera': True}, 80 {'tag': '', 'cabecera': True}, 81 {'tag': str(_("Índice por Grupo")), 'color': 'indigo', 'text_color': 'white', 'combine': 13, 'cabecera': True}, 82 {'tag': str(_("Índice por Sector de Origen")), 'color': 'orange', 'text_color': 'white', 'combine': 3, 'cabecera': True}, 83 {'tag': str(_("Índice por Naturaleza y Durabilidad")), 'color': 'gray25', 'text_color': 'black', 'combine': 5, 'cabecera': True}, 84 {'tag': str(_("Índice de Servicios")), 'color': 'green', 'text_color': 'white', 'combine': 3, 'cabecera': True}, 85 {'tag': str(_("Índice del Núcleo Inflacionario")), 'color': 'red', 'text_color': 'white', 'combine': 5, 'cabecera': True}, 86 {'tag': str(_("Índice de Productos Controlados y no Controlados")), 'color': 'aqua', 'text_color': 'black', 'combine': 2, 'cabecera': True}, 87 ], 88 [ 89 {'tag': str(_('Año')), 'cabecera': True}, {'tag': str(_('Mes')), 'cabecera': True}, {'tag': str(_('INPC')), 'cabecera': True}, 90 {'tag': str(_('(1) Alimentos y Bebidas no Alcoholicas')), 'cabecera': True}, 91 {'tag': str(_('(2) Bebidas Alcoholicas y Tabaco')), 'cabecera': True}, 92 {'tag': str(_('(3) Vestido y Calzado')), 'cabecera': True}, 93 {'tag': str(_('(4) Alquiler de Vivienda')), 'cabecera': True}, 94 {'tag': str(_('(5) Servicios de Vivienda Excepto Teléfono')), 'cabecera': True}, 95 {'tag': str(_('(6) Equipamiento de Hogar')), 'cabecera': True}, 96 {'tag': str(_('(7) Salud')), 'cabecera': True}, 97 {'tag': str(_('(8) Transporte')), 'cabecera': True}, 98 {'tag': str(_('(9) Comunicaciones')), 'cabecera': True}, 99 {'tag': str(_('(10) Esparcimiento y Cultura')), 'cabecera': True}, 100 {'tag': str(_('(11) Servicios de Educación')), 'cabecera': True}, 101 {'tag': str(_('(12) Restaurant y Hotel')), 'cabecera': True}, 102 {'tag': str(_('(13) Bienes y Servicios Diversos')), 'cabecera': True}, 103 {'tag': str(_('Bienes durables')), 'cabecera': True}, 104 {'tag': str(_('Bienes semidurables')), 'cabecera': True}, 105 {'tag': str(_('Bienes no durables')), 'cabecera': True}, 106 {'tag': str(_('Bienes')), 'cabecera': True}, 107 {'tag': str(_('Agrícolas')), 'cabecera': True}, 108 {'tag': str(_('Productos pesqueros')), 'cabecera': True}, 109 {'tag': str(_('Agroindustrial')), 'cabecera': True}, 110 {'tag': str(_('Otros manufacturados')), 'cabecera': True}, 111 {'tag': str(_('Total Servicios')), 'cabecera': True}, 112 {'tag': str(_('Servicios Básicos')), 'cabecera': True}, 113 {'tag': str(_('Otros Servicios')), 'cabecera': True}, 114 {'tag': str(_('Núcleo Inflacionario (NI)')), 'cabecera': True}, 115 {'tag': str(_('Alimentos Elaborados')), 'cabecera': True}, 116 {'tag': str(_('Textiles y Prendas de Vestir')), 'cabecera': True}, 117 {'tag': str(_('Bienes industriales excepto alimentos y textiles')), 'cabecera': True}, 118 {'tag': str(_('Servicios no administrados')), 'cabecera': True}, 119 {'tag': str(_('Controlados')), 'cabecera': True}, 120 {'tag': str(_('No Controlados')), 'cabecera': True} 121 ] 122 ] 123 exclude_fields = ['id', 'anho_base', 'real_precios_id', 'base'] 124 125 dominio, data_type = str(_('INPC')), 'N' 126 127 # Condición para filtrar y mostrar la información según la selección del usuario 70 128 if 'dominio' in kwargs: 71 129 if kwargs['dominio'] == 'N': … … 73 131 kwargs['ciudad'] = kwargs.pop('dominio') 74 132 else: 133 dominio, data_type = str(_('Ciudad')), 'C' 134 kwargs['ciudad__in'] = kwargs.pop('dominio') 75 135 kwargs['ciudad__in'] = [d for d in DOMINIO[1:][0]] 76 77 78 grupo_label = str(PreciosGrupo._meta.verbose_name) 79 grupo_count_fields = PreciosGrupo._meta.get_fields()[:-4].__len__() 80 sector_label = str(PreciosSector._meta.verbose_name) 81 sector_count_fields = PreciosSector._meta.get_fields()[:-4].__len__() 82 naturaleza_label = str(PreciosNaturaleza._meta.verbose_name) 83 naturaleza_count_fields = PreciosNaturaleza._meta.get_fields()[:-4].__len__() 84 servicios_label = str(PreciosServicios._meta.verbose_name) 85 servicios_count_fields = PreciosServicios._meta.get_fields()[:-4].__len__() 86 inflacionario_label = str(PreciosInflacionario._meta.verbose_name) 87 inflacionario_count_fields = PreciosInflacionario._meta.get_fields()[:-4].__len__() 88 productos_label = str(PreciosProductos._meta.verbose_name) 89 productos_count_fields = PreciosProductos._meta.get_fields()[:-4].__len__() 90 fields = [ 91 [ 92 {'tag': '', 'color': '', 'text_color': '', 'combine': 0}, 93 {'tag': '', 'color': '', 'text_color': '', 'combine': 0}, 94 {'tag': '', 'color': '', 'text_color': '', 'combine': 0}, 95 {'tag': grupo_label, 'color': 'indigo', 'text_color': 'white', 'combine': grupo_count_fields}, 96 {'tag': sector_label, 'color': 'orange', 'text_color': 'white', 'combine': sector_count_fields}, 97 {'tag': naturaleza_label, 'color': 'gray25', 'text_color': 'black', 'combine': naturaleza_count_fields}, 98 {'tag': servicios_label, 'color': 'green', 'text_color': 'white', 'combine': servicios_count_fields}, 99 {'tag': inflacionario_label, 'color': 'red', 'text_color': 'white', 'combine': inflacionario_count_fields}, 100 {'tag': productos_label, 'color': 'aqua', 'text_color': 'black', 'combine': productos_count_fields}, 101 ], 102 [] 103 ] 104 relations, data, exclude_fields = [], [], ['id', 'anho_base', 'real_precios_id', 'base'] 105 106 if not 'dominio' in kwargs or not kwargs['dominio'] == 'C': 136 # Agrega la columna correspondiente a las ciudades 137 fields[0].insert(2, {'tag': '', 'cabecera': True}) 138 fields[1].insert(2, {'tag': dominio, 'cabecera': True}) 139 140 elif not 'dominio' in kwargs or not kwargs['dominio'] == 'C': 107 141 exclude_fields.append('ciudad') 108 142 109 for f in self._meta.get_fields(): 110 try: 111 field, label, null = f.attname, str(f.verbose_name), f.null 112 if not field in exclude_fields and not f.get_internal_type() == "ManyToOneRel": 113 type, validators, error_messages = f.get_internal_type(), f.validators, f.error_messages 114 115 if type == "ForeignKey": 116 relations.append(f.rel.to) 117 118 fields[1].append({ 119 'field': field, 'label': label, 'type': type, 'null': null, 'validators': validators, 120 'error_messages': error_messages 121 }) 122 except Exception as e: 123 pass 124 125 ## Extrae los campos del modelo de precios por grupo 126 for grupo in PreciosGrupo._meta.get_fields(): 127 if not grupo.attname in exclude_fields: 128 fields[1].append({ 129 'field': grupo.attname, 'label': str(grupo.verbose_name), 'type': grupo.get_internal_type(), 130 'null': grupo.null, 'validators': grupo.validators, 'error_messages': grupo.error_messages 131 }) 132 133 ## Extrae los campos del modelo de precios por sector 134 for sector in PreciosSector._meta.get_fields(): 135 if not sector.attname in exclude_fields: 136 fields[1].append({ 137 'field': sector.attname, 'label': str(sector.verbose_name), 'type': sector.get_internal_type(), 138 'null': sector.null, 'validators': sector.validators, 'error_messages': sector.error_messages 139 }) 140 141 ## Extrae los campos del modelo de precios por naturaleza 142 for naturaleza in PreciosNaturaleza._meta.get_fields(): 143 if not naturaleza.attname in exclude_fields: 144 fields[1].append({ 145 'field': naturaleza.attname, 'label': str(naturaleza.verbose_name), 'type': naturaleza.get_internal_type(), 146 'null': naturaleza.null, 'validators': naturaleza.validators, 'error_messages': naturaleza.error_messages 147 }) 148 149 ## Extrae los campos del modelo de precios por servicios 150 for servicios in PreciosServicios._meta.get_fields(): 151 if not servicios.attname in exclude_fields: 152 fields[1].append({ 153 'field': servicios.attname, 'label': str(servicios.verbose_name), 'type': servicios.get_internal_type(), 154 'null': servicios.null, 'validators': servicios.validators, 'error_messages': servicios.error_messages 155 }) 156 157 ## Extrae los campos del modelo de precios por núcleo inflacionario 158 for inflacionario in PreciosInflacionario._meta.get_fields(): 159 if not inflacionario.attname in exclude_fields: 160 fields[1].append({ 161 'field': inflacionario.attname, 'label': str(inflacionario.verbose_name), 'type': inflacionario.get_internal_type(), 162 'null': inflacionario.null, 'validators': inflacionario.validators, 'error_messages': inflacionario.error_messages 163 }) 164 165 ## Extrae los campos del modelo de precios por productos controlados y no controlados 166 for productos in PreciosProductos._meta.get_fields(): 167 if not productos.attname in exclude_fields: 168 fields[1].append({ 169 'field': productos.attname, 'label': str(productos.verbose_name), 'type': productos.get_internal_type(), 170 'null': productos.null, 'validators': productos.validators, 'error_messages': productos.error_messages 171 }) 143 if 'anho_base' in kwargs: 144 precios_base = {'anho': kwargs['anho_base']} 145 if 'ciudad__in' in kwargs: 146 precios_base.update({'ciudad__in': kwargs['ciudad__in']}) 147 else: 148 precios_base = {} 172 149 173 150 ## Estrae los registros asociados a descargar en archivo 174 for p in Precios.objects.filter(**kwargs): 175 registros = [p.anho, p.mes, p.inpc] 176 #registros.append() 177 data.append(registros) 178 179 return {'cabecera': fields, 'relations': relations, 'data': data, 'output': 'precios'} 151 for p in Precios.objects.filter(Q(**kwargs) | Q(**precios_base)): 152 mes = str(_("Enero")) 153 for m in CONVERT_MES: 154 if CONVERT_MES[m] == p.mes: 155 mes = str(m) 156 157 # Registros de Año y Mes 158 registros = [{'tag': p.anho}, {'tag': mes}] 159 160 # Registros por ciudad si es solicitado 161 if data_type == 'C': 162 for d in DOMINIO[1:]: 163 if d[0] == p.ciudad: 164 registros.append({'tag': str(d[1])}) 165 166 # Índice Nacional de Precios al Consumidor 167 registros.append({'tag': str(p.inpc)}) 168 169 #Asigna los índices por grupo 170 grp = p.preciosgrupo_set.get() 171 for g in grp._meta.get_fields(): 172 if not g.attname in exclude_fields: 173 registros.append({'tag': str(grp.__getattribute__(g.attname))}) 174 175 # Asigna los indices por sector de origen 176 sec = p.preciossector_set.get() 177 for s in sec._meta.get_fields(): 178 if not s.attname in exclude_fields: 179 registros.append({'tag': str(sec.__getattribute__(s.attname))}) 180 181 # Asigna los indices por naturaleza y durabilidad 182 nat = p.preciosnaturaleza_set.get() 183 for n in nat._meta.get_fields(): 184 if not n.attname in exclude_fields: 185 registros.append({'tag': str(nat.__getattribute__(n.attname))}) 186 187 # Asigna los ínidces por servicio 188 ser = p.preciosservicios_set.get() 189 for sv in ser._meta.get_fields(): 190 if not sv.attname in exclude_fields: 191 registros.append({'tag': str(ser.__getattribute__(sv.attname))}) 192 193 # Asigna los ínidces por núcleo inflacionario 194 inf = p.preciosinflacionario_set.get() 195 for ni in inf._meta.get_fields(): 196 if not ni.attname in exclude_fields: 197 registros.append({'tag': str(inf.__getattribute__(ni.attname))}) 198 199 200 # Asigna los ínidces por productos controlados y no controlados 201 prd = p.preciosproductos_set.get() 202 for pr in prd._meta.get_fields(): 203 if not pr.attname in exclude_fields: 204 registros.append({'tag': str(prd.__getattribute__(pr.attname))}) 205 206 # Agrega los datos a la nueva fila del archivo a generar 207 fields.append(registros) 208 209 return {'fields': fields, 'output': 'precios'} 180 210 181 211 def gestion_process(self, file, user, *args, **kwargs): … … 225 255 base = True if i == 0 else False 226 256 257 # Registro de año y mes para los filtros 258 fecha = datetime(int(anho), int(mes), 1) 259 260 # Condiciones para filtrar la información a cargar según las especificaciones del usuario 261 if 'anho_base' in kwargs and kwargs['anho_base'] != load_file.row[2][0]: 262 continue 263 if 'fecha__month__gte' in kwargs and 'fecha__month__lte' in kwargs and kwargs[ 264 'fecha__month__lte'] < mes < kwargs['fecha__month__gte']: 265 continue 266 elif 'fecha__month__gte' in kwargs and mes < kwargs['fecha__month__gte']: 267 continue 268 elif 'fecha__month__lte' in kwargs and mes > kwargs['fecha__month__lte']: 269 continue 270 if 'fecha__year__gte' in kwargs and 'fecha__year__lte' in kwargs and kwargs[ 271 'fecha__year__lte'] < anho < kwargs['fecha__year__gte']: 272 continue 273 elif 'fecha__year__gte' in kwargs and anho < kwargs['fecha__year__gte']: 274 continue 275 elif 'fecha__year__lte' in kwargs and anho > kwargs['fecha__year__lte']: 276 continue 277 227 278 # Gestión para los datos básicos de precios 228 real_p, created = Precios.objects.update_or_create(anho=anho, mes=mes, ciudad=ciudad, defaults={ 229 'anho_base': anho_b, 'inpc': inpc 230 }) 279 real_p, created = Precios.objects.update_or_create( 280 anho=anho, mes=mes, ciudad=ciudad, fecha=fecha, 281 defaults={ 'anho_base': anho_b, 'inpc': inpc } 282 ) 231 283 232 284 -
economico/templates/economico.precios.html
r9ae3a72 r17dcd3a 86 86 } 87 87 if (periodo_mes_ini.val()) { 88 json_filter += "\" periodo_mes_ini\": \"" + periodo_mes_ini.val() + "\",";88 json_filter += "\"fecha__month__gte\": \"" + periodo_mes_ini.val() + "\","; 89 89 } 90 90 if (periodo_mes_fin.val()) { 91 json_filter += "\" periodo_mes_fin\": \"" + periodo_mes_fin.val() + "\",";91 json_filter += "\"fecha__month__lte\": \"" + periodo_mes_fin.val() + "\","; 92 92 } 93 93 if (periodo_anho_ini.val()) { 94 json_filter += "\" periodo_anho_ini\": \"" + periodo_anho_ini.val() + "\",";94 json_filter += "\"fecha__year__gte\": \"" + periodo_anho_ini.val() + "\","; 95 95 } 96 96 if (periodo_anho_fin.val()) { 97 json_filter += "\" periodo_anho_fin\": \"" + periodo_anho_fin.val() + "\",";97 json_filter += "\"fecha__year__lte\": \"" + periodo_anho_fin.val() + "\","; 98 98 } 99 99
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.