1 | # -*- encoding: utf-8 -*- |
---|
2 | """! |
---|
3 | Vista que controla los procesos de los proyectos |
---|
4 | |
---|
5 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
6 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
7 | @date 09-01-2017 |
---|
8 | @version 1.0.0 |
---|
9 | """ |
---|
10 | |
---|
11 | import os |
---|
12 | from django.conf import settings |
---|
13 | from django.contrib.auth.mixins import LoginRequiredMixin |
---|
14 | from django.contrib import messages |
---|
15 | from django.shortcuts import render |
---|
16 | from django.shortcuts import render_to_response |
---|
17 | from django.http import HttpResponse, Http404 |
---|
18 | from django.template import RequestContext |
---|
19 | from django.core.files.storage import default_storage |
---|
20 | from django.core.files.base import ContentFile |
---|
21 | from django.core.urlresolvers import reverse_lazy, reverse |
---|
22 | from django.views.generic import ListView, TemplateView |
---|
23 | from django.views.generic.detail import DetailView |
---|
24 | from django.views.generic.edit import ( |
---|
25 | CreateView, |
---|
26 | UpdateView, |
---|
27 | DeleteView |
---|
28 | ) |
---|
29 | from dal import autocomplete |
---|
30 | |
---|
31 | from .utils import ( |
---|
32 | listObjetivoHistoricoNacional, listObjetivoEstrategico, |
---|
33 | listObjetivoGenerales |
---|
34 | ) |
---|
35 | |
---|
36 | from .models import ( |
---|
37 | Proyecto, SubProyecto, Actividad, |
---|
38 | Alcance, |
---|
39 | CargaMasivaObjetivosHistoricos, CargaMasivaObjetivosNacional, |
---|
40 | CargaMasivaObjetivosEstrategico, CargaMasivaObjetivosGeneral |
---|
41 | ) |
---|
42 | |
---|
43 | from utils.forms import ( |
---|
44 | UploadFileForm |
---|
45 | ) |
---|
46 | |
---|
47 | from users.utils import ( |
---|
48 | LoginRequeridoPerAuth |
---|
49 | ) |
---|
50 | |
---|
51 | ## Carga de datos del archivo csv a la base de datos |
---|
52 | def carga_masiva_csv(ruta_archivo_hist, ruta_archivo_naci, ruta_archivo_estr, ruta_archivo_genr): |
---|
53 | n_reg_obj_hist = CargaMasivaObjetivosHistoricos.import_from_filename(ruta_archivo_hist) |
---|
54 | n_reg_obj_naci = CargaMasivaObjetivosNacional.import_from_filename(ruta_archivo_naci) |
---|
55 | n_reg_obj_estr = CargaMasivaObjetivosEstrategico.import_from_filename(ruta_archivo_estr) |
---|
56 | n_reg_obj_genr = CargaMasivaObjetivosGeneral.import_from_filename(ruta_archivo_genr) |
---|
57 | |
---|
58 | return n_reg_obj_hist, n_reg_obj_naci, n_reg_obj_estr, n_reg_obj_genr |
---|
59 | |
---|
60 | |
---|
61 | def cargaObjetivos(request): |
---|
62 | """! |
---|
63 | Funcion que permite cargar un archivo csv desde la interfaz del Administrador |
---|
64 | |
---|
65 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
66 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
67 | @date 09-01-2017 |
---|
68 | @version 1.0.0 |
---|
69 | """ |
---|
70 | form = UploadFileForm() |
---|
71 | context = {'form': form} |
---|
72 | if request.method == 'POST': |
---|
73 | form = UploadFileForm(request.POST, request.FILES) |
---|
74 | if form.is_valid(): |
---|
75 | archivo_objetivos = request.FILES['cargar'] |
---|
76 | extension_objetivos = str(archivo_objetivos).split('.') |
---|
77 | longitud_historico = len(extension_objetivos) |
---|
78 | if extension_objetivos[longitud_historico - 1] == 'csv': |
---|
79 | data_historico = archivo_objetivos.readlines() |
---|
80 | formato_cabeceras = False |
---|
81 | mensaje_error = "" |
---|
82 | for cabecera_historico in range(0, 1): |
---|
83 | separador_historico = data_historico[cabecera_historico].split(b"|") |
---|
84 | if (separador_historico[0]).decode('UTF-8') == "OBJETIVOS HISTÃRICOS" \ |
---|
85 | and (separador_historico[1]).decode('UTF-8') == "OBJETIVOS NACIONALES" and \ |
---|
86 | (separador_historico[2]).decode('UTF-8') == "OBJETIVOS ESTRATÃGICOS" and \ |
---|
87 | (separador_historico[3]).decode('UTF-8') == "OBJETIVOS GENERALES\n": |
---|
88 | formato_cabeceras = True |
---|
89 | else: |
---|
90 | formato_cabeceras = False |
---|
91 | mensaje_error_historico = "Existe un error en la cabecera del csv, del formato del Plan de la Patria\n" |
---|
92 | else: |
---|
93 | mensaje_error = "El formato de archivo debe ser csv" |
---|
94 | messages.error(request, mensaje_error) |
---|
95 | if formato_cabeceras: |
---|
96 | datos_obj = listObjetivoHistoricoNacional(data_historico) |
---|
97 | datos_obj_est = listObjetivoEstrategico(data_historico, datos_obj[1]) |
---|
98 | datos_obj_gene =listObjetivoGenerales(data_historico, datos_obj_est) |
---|
99 | archivo_obj_hist = ''.join(datos_obj[0]) |
---|
100 | archivo_obj_naci = ''.join(datos_obj[1]) |
---|
101 | archivo_obj_est = ''.join(datos_obj_est) |
---|
102 | archivo_obj_gene = ''.join(datos_obj_gene) |
---|
103 | #path_historico = default_storage.save('tmp/formato_historico.csv', ContentFile(archivo_obj_hist)) |
---|
104 | #path_nacional = default_storage.save('tmp/formato_nacional.csv', ContentFile(archivo_obj_naci)) |
---|
105 | #path_estrategico = default_storage.save('tmp/formato_estrategico.csv', ContentFile(archivo_obj_est)) |
---|
106 | #path_general = default_storage.save('tmp/formato_general.csv', ContentFile(archivo_obj_gene)) |
---|
107 | #ruta_historico = os.path.join(settings.MEDIA_ROOT, path_historico) |
---|
108 | #ruta_nacional = os.path.join(settings.MEDIA_ROOT, path_nacional) |
---|
109 | #ruta_estrategico = os.path.join(settings.MEDIA_ROOT, path_estrategico) |
---|
110 | #ruta_general = os.path.join(settings.MEDIA_ROOT, path_general) |
---|
111 | #carga_masiva_csv(ruta_historico, ruta_nacional, ruta_estrategico, ruta_general) |
---|
112 | #path_historico = default_storage.delete('tmp/formato_historico.csv') |
---|
113 | #path_nacional = default_storage.delete('tmp/formato_nacional.csv') |
---|
114 | #path_estrategico = default_storage.delete('tmp/formato_estrategico.csv') |
---|
115 | #path_general = default_storage.delete('tmp/formato_general.csv') |
---|
116 | messages.success(request, 'La data se cargo con exito') |
---|
117 | else: |
---|
118 | messages.error(request, mensaje_error_historico) |
---|
119 | else: |
---|
120 | return render(request, 'utils/cargar_historica.html', context) |
---|
121 | |
---|
122 | context = {'form': form} |
---|
123 | return render(request, 'utils/cargar_historica.html', context) |
---|
124 | |
---|
125 | else: |
---|
126 | return render(request, 'utils/cargar_historica.html', context) |
---|
127 | |
---|
128 | |
---|
129 | class AlcanceAutocomplete(autocomplete.Select2QuerySetView): |
---|
130 | """! |
---|
131 | Clase que crea el autocompletado del alcance de los proyectos en un select |
---|
132 | |
---|
133 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
134 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
135 | @date 09-01-2017 |
---|
136 | @version 1.0.0 |
---|
137 | """ |
---|
138 | |
---|
139 | def get_queryset(self): |
---|
140 | # No se olvide de filtrar los resultados en función del visitante ! |
---|
141 | if not self.request.user.is_authenticated(): |
---|
142 | return Alcance.objects.none() |
---|
143 | |
---|
144 | qs = Alcance.objects.all() |
---|
145 | if self.q: |
---|
146 | qs = qs.filter(opcion_alcance__istartswith=self.q) |
---|
147 | |
---|
148 | return qs |
---|
149 | |
---|
150 | class OptionsMangProjectsView(LoginRequeridoPerAuth, TemplateView): |
---|
151 | """! |
---|
152 | Lista las opciones para la gestion de proyectos |
---|
153 | |
---|
154 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
155 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
156 | @date 09-01-2017 |
---|
157 | @version 1.0.0 |
---|
158 | """ |
---|
159 | template_name = "proyectos/gestion_proyectos.html" |
---|
160 | group_required = [u"Administradores", u"Usuarios Supervisores", u"Usuarios Enlace" ] |
---|
161 | |
---|
162 | def __init__(self): |
---|
163 | super(OptionsMangProjectsView, self).__init__() |
---|
164 | |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | class ProjectsList(ListView): |
---|
169 | """! |
---|
170 | Clase que lista los proyectos |
---|
171 | |
---|
172 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
173 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
174 | @date 09-01-2017 |
---|
175 | @version 1.0.0 |
---|
176 | """ |
---|
177 | model = Proyecto |
---|
178 | |
---|
179 | def __init__(self): |
---|
180 | super(ProjectsList, self).__init__() |
---|
181 | |
---|
182 | |
---|
183 | class ProyectoCreation(LoginRequiredMixin, CreateView): |
---|
184 | """! |
---|
185 | Clase para crear los proyectos |
---|
186 | |
---|
187 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
188 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
189 | @date 09-01-2017 |
---|
190 | @version 1.0.0 |
---|
191 | """ |
---|
192 | model = Proyecto |
---|
193 | success_url = reverse_lazy('projects:consultar_proyectos') |
---|
194 | fields = [ |
---|
195 | 'fk_alcance', 'fk_sector', 'codigo', 'nombre', |
---|
196 | 'justificacion', 'objetivo_general', |
---|
197 | 'objetivos_especificos', 'monto_proyecto', 'fecha_inicio', |
---|
198 | 'fecha_culminacion' |
---|
199 | ] |
---|
200 | |
---|
201 | |
---|
202 | class ProyectoUpdate(UpdateView): |
---|
203 | """! |
---|
204 | Clase para editar o actualizar un proyecto |
---|
205 | |
---|
206 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
207 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
208 | @date 09-01-2017 |
---|
209 | @version 1.0.0 |
---|
210 | """ |
---|
211 | model = Proyecto |
---|
212 | success_url = reverse_lazy('projects:consultar_proyectos') |
---|
213 | fields = [ |
---|
214 | 'fk_alcance', 'fk_sector', 'codigo', 'nombre', |
---|
215 | 'justificacion', 'objetivo_general', |
---|
216 | 'objetivos_especificos', 'monto_proyecto', 'fecha_inicio', |
---|
217 | 'fecha_culminacion' |
---|
218 | ] |
---|
219 | |
---|
220 | |
---|
221 | class SubProjectsList(ListView): |
---|
222 | """! |
---|
223 | Clase para listar o consultar los subproyectos |
---|
224 | |
---|
225 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
226 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
227 | @date 09-01-2017 |
---|
228 | @version 1.0.0 |
---|
229 | """ |
---|
230 | model = SubProyecto |
---|
231 | |
---|
232 | def __init__(self): |
---|
233 | super(SubProjectsList, self).__init__() |
---|
234 | |
---|
235 | |
---|
236 | class SubProyectoCreation(CreateView): |
---|
237 | """! |
---|
238 | Clase que crear los subproyectos |
---|
239 | |
---|
240 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
241 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
242 | @date 09-01-2017 |
---|
243 | @version 1.0.0 |
---|
244 | """ |
---|
245 | model = SubProyecto |
---|
246 | success_url = reverse_lazy('projects:consultar_subproyectos') |
---|
247 | fields = [ |
---|
248 | 'fk_proyecto', 'parroquia', 'codigo', 'nombre', |
---|
249 | 'descripcion_bien_servicio', 'unidad_medida', |
---|
250 | 'meta', 'fecha_inicio', 'fecha_culminacion', 'comunidad', |
---|
251 | 'monto_subproyecto' |
---|
252 | ] |
---|
253 | |
---|
254 | |
---|
255 | class SubProyectoUpdate(UpdateView): |
---|
256 | """! |
---|
257 | Clase que permite actualizar o editar los subproyectos |
---|
258 | |
---|
259 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
260 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
261 | @date 09-01-2017 |
---|
262 | @version 1.0.0 |
---|
263 | """ |
---|
264 | model = SubProyecto |
---|
265 | success_url = reverse_lazy('projects:consultar_subproyectos') |
---|
266 | fields = [ |
---|
267 | 'fk_proyecto', 'parroquia', 'codigo', 'nombre', |
---|
268 | 'descripcion_bien_servicio', 'unidad_medida', |
---|
269 | 'meta', 'fecha_inicio', 'fecha_culminacion', 'comunidad', |
---|
270 | 'monto_subproyecto' |
---|
271 | ] |
---|
272 | |
---|
273 | |
---|
274 | class ActividadList(ListView): |
---|
275 | """! |
---|
276 | Clase que permite listar o consular las actividades |
---|
277 | |
---|
278 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
279 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
280 | @date 09-01-2017 |
---|
281 | @version 1.0.0 |
---|
282 | """ |
---|
283 | model = Actividad |
---|
284 | |
---|
285 | def __init__(self): |
---|
286 | super(ActividadList, self).__init__() |
---|
287 | |
---|
288 | |
---|
289 | class ActividadCreation(CreateView): |
---|
290 | """! |
---|
291 | Clase que permite crear las actividades |
---|
292 | |
---|
293 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
294 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
295 | @date 09-01-2017 |
---|
296 | @version 1.0.0 |
---|
297 | """ |
---|
298 | model = Actividad |
---|
299 | success_url = reverse_lazy('projects:consultar_actividades') |
---|
300 | fields = [ |
---|
301 | 'fk_subproyecto', 'descripcion', 'unidad_medida', 'fecha_inicio', |
---|
302 | 'fecha_culminacion', 'horas_estimadas_ejecucion', |
---|
303 | 'costo_estimadao_ejecucion', 'peso_actividad', |
---|
304 | 'cantidad_estimada_trabajo' |
---|
305 | ] |
---|
306 | |
---|
307 | |
---|
308 | class ActividadUpdate(UpdateView): |
---|
309 | """! |
---|
310 | Clase que permite actualizar o editar las actividades |
---|
311 | |
---|
312 | @author Ing. Leonel P. Hernandez M. (lhernandez at cenditel.gob.ve) |
---|
313 | @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
314 | @date 09-01-2017 |
---|
315 | @version 1.0.0 |
---|
316 | """ |
---|
317 | success_url = reverse_lazy('projects:consultar_actividades') |
---|
318 | fields = [ |
---|
319 | 'fk_subproyecto', 'descripcion', 'unidad_medida', 'fecha_inicio', |
---|
320 | 'fecha_culminacion', 'horas_estimadas_ejecucion', |
---|
321 | 'costo_estimadao_ejecucion', 'peso_actividad', |
---|
322 | 'cantidad_estimada_trabajo' |
---|
323 | ] |
---|