Changes in / [bc3aa92:d9b20e6] in firmaeventos
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
base/templates/base.vars.javascript.html
r5d88f36 r452668a 9 9 // URL para comprobar si el firmante es el último 10 10 var URL_ULTIMO_FIRMANTE = "{% url 'participantes:participante_restante_evento_nid' %}"; 11 12 // URL para comprobar si el documento esta siendo firmado 13 var URL_COMPROBAR_FIRMA = "{% url 'events:comprobar_evento_nid' %}"; 14 11 15 12 16 </script> -
eventos/forms.py
rbc3aa92 rbc3aa92 39 39 'readonly': 40 40 'readonly'}) 41 self.fields['archivo'].required = True41 self.fields['archivo'].required = False 42 42 self.fields['archivo'].widget.attrs.update( 43 43 {'class': 'file-path validate', … … 45 45 'accept': '.pdf'}) 46 46 self.fields['pos_x'].widget = forms.HiddenInput() 47 self.fields['pos_x'].required=False 47 48 self.fields['pos_y'].widget = forms.HiddenInput() 49 self.fields['pos_y'].required=False 48 50 self.fields['pag'].widget = forms.HiddenInput() 51 self.fields['pag'].required=False 52 49 53 50 54 class FirmaEventoForm(forms.Form): -
eventos/models.py
r5d88f36 reb2672b 13 13 nombre_evento = models.CharField(max_length=128, unique=True) 14 14 fecha = models.DateField(null=False) 15 serial = models.CharField(max_length=128 )16 pos_x = models.CharField(max_length=32 )17 pos_y = models.CharField(max_length=32 )18 pag = models.CharField(max_length=4 )15 serial = models.CharField(max_length=128,null=True) 16 pos_x = models.CharField(max_length=32,null=True) 17 pos_y = models.CharField(max_length=32,null=True) 18 pag = models.CharField(max_length=4,null=True) 19 19 activo = models.BooleanField(default=True) 20 20 procesando = models.BooleanField(default=False) -
eventos/templates/evento.detail.html
r5d88f36 reb2672b 52 52 </div> 53 53 <div class="center"> 54 <iframe width="700px" height="600px" src="https://192.168.12.154:8443/Murachi/0.1/archivos/listadopdf/{{object.serial}}">'; 54 {% if object.serial %} 55 <iframe width="700px" height="600px" src="https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/listadopdf/{{object.serial}}">'; 55 56 </iframe> 57 {% else %} 58 <h4 class="red-text">No cargó ningun documento</h4> 59 {% endif %} 56 60 </div> 57 61 <div class="row"> -
eventos/templates/evento.list.html
r5d88f36 r974a9c3 24 24 <i class="material-icons left">search</i> Detalle 25 25 </a> 26 {% if evento.serial %} 26 27 <a type="button" class="btn waves-effect blue darken-1" href="{% url 'events:firma_events' evento.id %}"> 27 28 <i class="material-icons left">mode_edit</i> Firmar 28 29 </a> 30 {% else %} 31 <a type="button" class="btn waves-effect blue darken-1" href="{% url 'events:update_evento' evento.id %}"> 32 <i class="material-icons left">backup</i> Cargar Documento 33 </a> 34 {% endif %} 29 35 </div> 30 36 </div> -
eventos/templates/evento.update.html
rbc3aa92 rbc3aa92 15 15 {% block content %} 16 16 <div class="content"> 17 {% if object.serial %} 18 <div class="center"> 19 <h5 class="center">El evento {{object.nombre_evento}}, ya contiene un documento</h5><hr/><br> 20 <iframe width="700px" height="600px" src="https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/listadopdf/{{object.serial}}">'; 21 </iframe> 22 </div> 23 {% else %} 17 24 <h5 class="center">Cargar Archivo al Evento</h5><hr/><br> 18 25 <form id="form" method="post" enctype="multipart/form-data"> … … 65 72 </div> 66 73 </form> 74 {% endif %} 67 75 </div> 68 76 {% endblock %} -
eventos/urls.py
rbc3aa92 rbc3aa92 14 14 url(r'^detail-evento/(?P<pk>\d+)$', DetailEvent.as_view(), 15 15 name='detail_event'), 16 url(r'^comprobar-evento/(?P<event_id>\d+)$', EventoProcesado.as_view(), 17 name='comprobar_evento'), 16 18 url(r'^comprobar-evento/$', EventoProcesado.as_view(), 17 name='comprobar_evento'), 19 name='comprobar_evento_nid'), 20 url(r'^actualizar-evento/(?P<event_id>\d+)$', UpdateFileEvent.as_view(), 21 name='update_evento'), 18 22 ] -
eventos/views.py
rbc3aa92 rbc3aa92 10 10 from django.core.urlresolvers import reverse_lazy 11 11 from django.http import JsonResponse 12 from django.utils.decorators import method_decorator 13 from django.views.decorators.csrf import csrf_exempt 12 14 from django.shortcuts import ( 13 15 redirect … … 60 62 61 63 def post(self, request, *args, **kwargs): 62 file = request.FILES['file'] 63 handle_uploaded_file(request.FILES['file'], file) 64 ruta = '%s/%s' % (settings.TMP, file) 65 file = open(ruta, 'rb') 66 files = {'file': file} 67 try: 68 r = requests.post('https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/cargar', verify=False, headers={'Authorization': 'Basic YWRtaW46YWRtaW4='}, files=files) 69 nuevo_participante = self.form_participante(request.POST) 70 consulta_api = r.json()['fileId'] 71 # elimina el archivo si fue creado en la carpeta tmp 72 file.close() 73 os.unlink(ruta) 74 except Exception as e: 75 print (e) 76 file.close() 77 os.unlink(ruta) 78 messages.error(self.request, "Error al concetar al servidor y subir\ 79 el archivo a la api Murachi") 80 return redirect(self.success_url) 81 try: 64 nuevo_participante = self.form_participante(request.POST) 65 consulta_api = None 66 if len(request.FILES)>0: 67 file = request.FILES['file'] 68 handle_uploaded_file(request.FILES['file'], file) 69 ruta = '%s/%s' % (settings.TMP, file) 70 file = open(ruta, 'rb') 71 files = {'file': file} 72 try: 73 r = requests.post('https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/cargar', verify=False, headers={'Authorization': 'Basic YWRtaW46YWRtaW4='}, files=files) 74 consulta_api = r.json()['fileId'] 75 # elimina el archivo si fue creado en la carpeta tmp 76 file.close() 77 os.unlink(ruta) 78 except Exception as e: 79 print (e) 80 file.close() 81 os.unlink(ruta) 82 messages.error(self.request, "Error al concetar al servidor y subir\ 83 el archivo a la api Murachi") 84 return redirect(self.success_url) 85 try: 86 82 87 if self.form_class(request.POST).is_valid() and nuevo_participante.is_valid(): 83 88 nuevo_evento = self.form_class(request.POST, request.FILES).save(commit=False) … … 101 106 asigna_evento.save() 102 107 messages.success(self.request, "El usaurio %s, ha creado con exito,\ 103 un nuevo e nvento %s" %108 un nuevo evento %s" % 104 109 (str(self.request.user), 105 110 str(nuevo_evento))) … … 184 189 return context 185 190 186 191 @method_decorator(csrf_exempt, name='dispatch') 187 192 class EventoProcesado(View): 188 193 """! … … 196 201 model = Evento 197 202 198 def get(self, request ):203 def get(self, request, event_id): 199 204 """! 200 205 Metodo que permite verificar si el documento esta procesado … … 206 211 @return Retorna un Json con la respuesta 207 212 """ 208 evento_id = request.GET.get('event_id', None)209 213 mensaje = '' 210 214 procesando = False 211 if event o_id is not None:215 if event_id is not None: 212 216 try: 213 evento_pro = self.model.objects.get(pk=event o_id)217 evento_pro = self.model.objects.get(pk=event_id) 214 218 except: 215 219 print(e) … … 231 235 return JsonResponse(data, safe=False) 232 236 233 def post(self, request ):237 def post(self, request, event_id): 234 238 """! 235 239 Metodo que permite cambiar el valor procesado al evento … … 241 245 @return Retorna un Json con la respuesta 242 246 """ 243 evento_id = request.POST.get('event_id', None) 244 if evento_id is not None: 247 if event_id is not None: 245 248 try: 246 evento = self.model.objects.get(pk=event o_id)249 evento = self.model.objects.get(pk=event_id) 247 250 evento.procesando = not evento.procesando 248 251 evento.save() … … 251 254 print(e) 252 255 validado = False 256 253 257 return JsonResponse(validado, safe=False) 254 258 … … 266 270 form_class = UpdateFileEventoForm 267 271 template_name = 'evento.update.html' 268 269 def form_valid(self, form, request): 270 print(request) 272 success_url = reverse_lazy('events:list_events') 273 274 def get_context_data(self, **kwargs): 275 evento = int(self.kwargs['event_id']) 276 context = super(UpdateFileEvent, self).get_context_data(**kwargs) 277 try: 278 evento = self.model.objects.select_related().get(pk=evento) 279 except Exception as e: 280 print(e) 281 evento = None 282 context['object'] = evento 283 return context 284 285 def form_valid(self, form): 286 print(form) 287 file = self.request.FILES['file'] 288 posx = form.cleaned_data['pos_x'] 289 posy = form.cleaned_data['pos_y'] 290 pag = form.cleaned_data['pag'] 291 consulta_api = None 292 try: 293 event = Evento.objects.get(pk=int(self.kwargs['event_id'])) 294 except Exception as e: 295 print(e) 296 messages.error(self.request, "Error, no se encuentra registrado\ 297 este evento") 298 return redirect(self.success_url) 299 300 print(posx) 301 handle_uploaded_file(self.request.FILES['file'], file) 302 ruta = '%s/%s' % (settings.TMP, file) 303 file = open(ruta, 'rb') 304 files = {'file': file} 305 try: 306 r = requests.post('https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/cargar', verify=False, headers={'Authorization': 'Basic YWRtaW46YWRtaW4='}, files=files) 307 consulta_api = r.json()['fileId'] 308 # elimina el archivo si fue creado en la carpeta tmp 309 file.close() 310 os.unlink(ruta) 311 except Exception as e: 312 print (e) 313 file.close() 314 os.unlink(ruta) 315 messages.error(self.request, "Error al concetar al servidor y subir\ 316 el archivo a la api Murachi") 317 return redirect(self.success_url) 318 319 if event is not None and consulta_api is not None: 320 event.serial = consulta_api 321 event.pos_x = posx 322 event.pos_y = posy 323 event.pag = pag 324 event.save() 325 messages.success(self.request, "El usaurio %s, ha actualizado con exito,\ 326 el evento %s" % 327 (str(self.request.user), 328 str(event))) 329 else: 330 messages.error(self.request, "Error al actualizar, debes llanar\ 331 todos los campos incluyendo la\ 332 configuracion de la firma") 333 return redirect(self.success_url) -
static/js/funciones.js
r5d88f36 r452668a 80 80 } 81 81 else{ 82 html += '<a type="button" id="firmar" class="btn waves-effect blue darken-1" onclick=" ObtenerCertificadoFirmanteMultiples(\''+data.documento+'\')">';82 html += '<a type="button" id="firmar" class="btn waves-effect blue darken-1" onclick="comprobarFirma(\''+data.documento+'\')">'; 83 83 html += '<i class="material-icons left">mode_edit</i> Firmar</a>'; 84 84 } … … 87 87 88 88 /** 89 * Función para comprobar firma 90 * @param fileId Recibe el id del documento 91 */ 92 function comprobarFirma(fileId){ 93 var routes = $(location).attr('pathname').split('/'); 94 var pk = routes[routes.length-1]; 95 $.ajax({ 96 type: 'GET', 97 async: false, 98 url:URL_COMPROBAR_FIRMA+pk, 99 success: function(datos){ 100 if (datos.validate==true) { 101 simple_modal(datos.mensaje); 102 } 103 else{ 104 $.ajax({ 105 type: 'POST', 106 async: false, 107 url:URL_COMPROBAR_FIRMA+pk, 108 success: function(datos){ 109 if (datos.validate==true) { 110 ObtenerCertificadoFirmanteMultiples(fileId,pk); 111 } 112 else{ 113 simple_modal("Ocurrió un error al actualizar los datos"); 114 } 115 }, 116 error: function(jqXHR, textStatus, errorThrown){ 117 console.log('error: ' + textStatus); 118 } 119 }); 120 } 121 }, 122 error: function(jqXHR, textStatus, errorThrown){ 123 console.log('error: ' + textStatus); 124 } 125 }); 126 } 127 128 /** 89 129 * Función para obtener el certificado del participante 90 130 * @param fileId Recibe el id del documento 91 */ 92 function ObtenerCertificadoFirmanteMultiples(fileId){ 131 * @param pk Recibe el id del evento 132 */ 133 function ObtenerCertificadoFirmanteMultiples(fileId,pk){ 93 134 var xPos = yPos= signaturePage = ""; 94 135 var lastSignature = false; 95 var routes = $(location).attr('pathname').split('/');96 var pk = routes[routes.length-1];97 136 98 137 $.ajax({ … … 125 164 126 165 // ahora llamar al ajax de obtener la resena del pdf 127 ObtenerHashPDFServerMultiples(parameters, cert );166 ObtenerHashPDFServerMultiples(parameters, cert, pk); 128 167 129 168 }, … … 139 178 error = "No hay soporte para el manejo del certificado"; 140 179 } 180 $.ajax({ 181 type: 'POST', 182 async: false, 183 url:URL_COMPROBAR_FIRMA+pk, 184 success: function(datos){ 185 console.log(datos); 186 }, 187 error: function(jqXHR, textStatus, errorThrown){ 188 console.log('error: ' + textStatus); 189 } 190 }); 141 191 simple_modal(error); 142 192 } … … 155 205 * @param parameters Recibe los parametros 156 206 * @param cert Recibe los certificados 157 */ 158 function ObtenerHashPDFServerMultiples(parameters,cert){ 207 * @param pk Recibe el id del evento 208 */ 209 function ObtenerHashPDFServerMultiples(parameters,cert,pk){ 159 210 160 211 $.ajax({ … … 175 226 window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then( 176 227 function(signature) { 177 FinalizarFirmaMultiples(signature.hex );228 FinalizarFirmaMultiples(signature.hex, pk); 178 229 }, 179 230 function(err) { … … 188 239 error = "No hay soporte para el manejo del certificado"; 189 240 } 241 $.ajax({ 242 type: 'POST', 243 async: false, 244 url:URL_COMPROBAR_FIRMA+pk, 245 success: function(datos){ 246 console.log(datos); 247 }, 248 error: function(jqXHR, textStatus, errorThrown){ 249 console.log('error: ' + textStatus); 250 } 251 }); 190 252 simple_modal(error); 191 253 }); … … 202 264 * Función para enviar la firma al servidor 203 265 * @param signature Recibe la firma 204 */ 205 function FinalizarFirmaMultiples(signature){ 266 * @param pk Recibe el id del evento 267 */ 268 function FinalizarFirmaMultiples(signature, pk){ 206 269 207 270 $.ajax({ … … 215 278 success: function(data, textStatus, jqXHR){ 216 279 actualizar_participante(data['signedFileId']); 280 $.ajax({ 281 type: 'POST', 282 async: false, 283 url:URL_COMPROBAR_FIRMA+pk, 284 success: function(datos){ 285 console.log(datos); 286 }, 287 error: function(jqXHR, textStatus, errorThrown){ 288 console.log('error: ' + textStatus); 289 } 290 }); 217 291 }, 218 292 error: function(jqXHR, textStatus, errorThrown){ 219 293 console.log('error en pdfs/resenas: ' + textStatus); 294 $.ajax({ 295 type: 'POST', 296 async: false, 297 url:URL_COMPROBAR_FIRMA+pk, 298 success: function(datos){ 299 console.log(datos); 300 }, 301 error: function(jqXHR, textStatus, errorThrown){ 302 console.log('error: ' + textStatus); 303 } 304 }); 220 305 } 221 306 });
Note: See TracChangeset
for help on using the changeset viewer.