# -*- encoding: UTF-8 -*- from datetime import datetime from django.core.exceptions import ImproperlyConfigured from django.db.models.query_utils import Q # from django.views.generic.base import RedirectView from django.views.generic.edit import UpdateView, DeleteView, FormView from django.core.urlresolvers import reverse_lazy from django.views.generic import ListView, DetailView, CreateView, View from django.contrib import messages # from rest_framework.generics import ListAPIView from django.views.generic.base import TemplateView from pure_pagination.mixins import PaginationMixin from padron.serializers import GetDetallePersonaSerialize, EstatusSerialize from .forms import * from django.conf import settings from .models import * from pyjasperclient import JasperClient from django.http import HttpResponseRedirect, HttpResponse from django.utils.decorators import method_decorator from django.contrib.auth.decorators import login_required # Create your views here.sfds from padron.models import Bienes class DinamicPaginationMixin(PaginationMixin): def get_paginate_by(self, queryset): self.paginate_by = self.request.GET.get('rpp', 10) if self.paginate_by: self.paginate_by = int(self.paginate_by) return self.paginate_by def get_context_data(self, **kwargs): context = super(DinamicPaginationMixin, self).get_context_data(**kwargs) context['rpp'] = self.get_paginate_by(self.queryset) return context class SearchMixin(object): def get_search(self): return self.request.GET.get('search', '') def get_filter(self, queryset): raise ImproperlyConfigured('Debe especificar implementar el filtro de búsqueda') def get_queryset(self): queryset = super(SearchMixin, self).get_queryset() queryset = self.get_filter(queryset) return queryset def get_context_data(self, **kwargs): context = super(SearchMixin, self).get_context_data(**kwargs) context['search'] = self.get_search() return context class ListaFirmasView(DinamicPaginationMixin, SearchMixin, ListView): model = firmas queryset = firmas.objects.filter(estatus='Activo') def get_filter(self, queryset): search = self.get_search() if queryset: queryset = queryset.filter( Q(director__icontains=search) ) return queryset def get_context_data(self, **kwargs): context = super(ListaFirmasView, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context class DetalleFirmasView(DetailView): model = firmas def get_context_data(self, **kwargs): context = super(DetalleFirmasView, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context class CrearFirmasView(CreateView): model = firmas form_class = FirmasForm def get_success_url(self): messages.success(self.request, "Se agrego la firma correctamente") return reverse('lista-firmas') def form_valid(self, form): queryset = firmas.objects.filter(director=form.cleaned_data["director"], estatus='Activo') if queryset: messages.error(self.request, 'Ya existe la firma con el mismo nombre.') return HttpResponseRedirect(reverse('crear-firmas')) else: form.instance.fecha_registro = datetime.now() form.save() return super(CrearFirmasView, self).form_valid(form) def get_context_data(self, **kwargs): context = super(CrearFirmasView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["padron"] = "active" return context class EliminarFirmasView(UpdateView): model = firmas form_class = FirmasUpdateForm def get_success_url(self): return reverse('lista-firmas') def form_valid(self, form): form.instance.estatus = 'Eliminado' form.instance.fecha_registro = datetime.now() form.save() messages.success(self.request, "Se eliminó exitosamente la firma") return super(EliminarFirmasView, self).form_valid(form) def get_context_data(self, **kwargs): context = super(EliminarFirmasView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["eliminar_firma"] = True return context class UpdateFirmasView(UpdateView): model = firmas form_class = FirmasForm def get_success_url(self): messages.success(self.request, "Se actualizo la firma correctamente") return reverse('lista-firmas') def form_valid(self, form): # queryset = firmas.objects.filter(director=form.cleaned_data["director"],estatus='Activo') # # if queryset: # messages.error(self.request, 'La firma ya se encuentra almacenada en nuestra base de datos.') # return HttpResponseRedirect(reverse('update-firmas', kwargs={"pk": self.kwargs["pk"]})) # else: form.instance.fecha_registro = datetime.now() form.save() return super(UpdateFirmasView, self).form_valid(form) def get_context_data(self, **kwargs): context = super(UpdateFirmasView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["padron"] = "active" return context class ListaUsuariosView(DinamicPaginationMixin, SearchMixin, ListView): model = usuarios queryset = usuarios.objects.filter(estatus='Activo').order_by('nombre') def get_filter(self, queryset): search = self.get_search() if queryset: queryset = queryset.filter( Q(apellido_paterno__icontains=search) | Q(apellido_materno__icontains=search) | Q(cargo__icontains=search) | Q(nombre__icontains=search) ) return queryset def get_context_data(self, **kwargs): context = super(ListaUsuariosView, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context class CrearUsuariosView(CreateView): model = usuarios form_class = UsuariosForm def get_success_url(self): messages.success(self.request, "Se agrego la firma correctamente") return reverse('lista-usuarios') def form_valid(self, form): queryset = usuarios.objects.filter(nombre=form.cleaned_data["nombre"], apellido_paterno=form.cleaned_data["apellido_paterno"], apellido_materno=form.cleaned_data["apellido_materno"], estatus='Activo') if queryset: messages.error(self.request, 'Ya existe el usuario con el mismo nombre.') return HttpResponseRedirect(reverse('crear-usuarios')) else: form.instance.fecha_registro = datetime.now() form.save() return super(CrearUsuariosView, self).form_valid(form) def get_context_data(self, **kwargs): context = super(CrearUsuariosView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["padron"] = "active" return context class UpdateUsuariosView(UpdateView): model = usuarios form_class = UsuariosForm def get_success_url(self): messages.success(self.request, "La información del usuario se actualizo correctamente") return reverse_lazy('lista-usuarios') def form_valid(self, form): form.instance.fecha_registro = datetime.now() form.save() return super(UpdateUsuariosView, self).form_valid(form) def get_context_data(self, **kwargs): context = super(UpdateUsuariosView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["padron"] = "active" return context class EliminarUsuariosView(UpdateView): model = usuarios form_class = UsuariosUpdateForm def get_success_url(self): messages.success(self.request, "Se ha eliminado el usuario correctamente") return reverse('lista-usuarios') def form_valid(self, form): queryset = Bienes.objects.filter(usuarios_id=self.kwargs["pk"]) if queryset: messages.error(self.request, 'El usuario no puede ser eliminado por que tiene asociado un bien.') return HttpResponseRedirect(reverse('lista-usuarios')) else: form.instance.fecha_registro = datetime.now() form.instance.estatus = "Eliminado" form.save() return super(EliminarUsuariosView, self).form_valid(form) def get_context_data(self, **kwargs): context = super(EliminarUsuariosView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["eliminar_usuario"] = True return context class DetalleUsuariosView(DetailView): model = usuarios def get_context_data(self, **kwargs): context = super(DetalleUsuariosView, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context class ListaBienesView(DinamicPaginationMixin, SearchMixin, ListView): model = Bienes queryset = Bienes.objects.filter(estatus_id__in=[1, 4, 5, 6, 9]).order_by('no_inventario_oficial') def get_filter(self, queryset): buscar = self.request.GET.get('busca') search = self.get_search() if queryset: queryset = queryset.filter( Q(descripcion__icontains=search) | Q(marca__icontains=search) | Q(modelo__icontains=search) | Q(no_serie__icontains=search) | Q(no_factura__icontains=search) | Q(no_inventario_oficial__icontains=search) | Q(no_inventario_dgtic__icontains=search) | Q(no_resguardo__icontains=search) | Q(estado__icontains=search) | Q(observaciones__icontains=search) | Q(ubicacion__icontains=search) | Q(usuarios__nombre__icontains=search) | Q(usuarios__apellido_paterno__icontains=search) | Q(usuarios__apellido_materno__icontains=search) | Q(usuarios__dependencias__nombre__icontains=search) | Q(usuarios__dependencias__clave_dependencia__icontains=search) | Q(usuarios__departamentos__nombre__icontains=search) | Q(usuarios__departamentos__clave_departamento__icontains=search) | Q(usuarios__cargo__icontains=search) ) if buscar: if int(buscar) == 1: queryset = queryset.filter(estatus_id=5) if int(buscar) == 2: queryset = queryset.filter(Q(estatus_id=5) | Q(estatus_id=1)) if int(buscar) == 3: queryset = queryset.filter(estatus_id=6) return queryset def get_context_data(self, **kwargs): context = super(ListaBienesView, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(ListaBienesView, self).dispatch(*args, **kwargs) class CrearBienesView(CreateView): model = Bienes form_class = BienesForm def get_success_url(self): messages.success(self.request, "Se agrego el bien correctamente") return reverse('lista-bienes') def get_context_data(self, **kwargs): context = super(CrearBienesView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["padron"] = "active" return context class bieneslocalizados(DinamicPaginationMixin, SearchMixin, ListView): template_name = 'padron/bienes_list.html' model = Bienes def get_filter(self, queryset): search = self.get_search() if queryset: queryset = queryset.filter( Q(descripcion__icontains=search) | Q(marca__icontains=search) | Q(modelo__icontains=search) | Q(no_serie__icontains=search) | Q(no_factura__icontains=search) | Q(no_inventario_oficial__icontains=search) | Q(no_inventario_dgtic__icontains=search) | Q(no_resguardo__icontains=search) | Q(estado__icontains=search) | Q(observaciones__icontains=search) | Q(ubicacion__icontains=search) | Q(usuarios__nombre__icontains=search) | Q(usuarios__apellido_paterno__icontains=search) | Q(usuarios__apellido_materno__icontains=search) | Q(usuarios__dependencias__nombre__icontains=search) | Q(usuarios__dependencias__clave_dependencia__icontains=search) | Q(usuarios__departamentos__nombre__icontains=search) | Q(usuarios__departamentos__clave_departamento__icontains=search) | Q(usuarios__cargo__icontains=search) ) return queryset def get_queryset(self): return Bienes.objects.all().filter(localizado=False) def get_context_data(self, **kwargs): context = super(bieneslocalizados, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(bieneslocalizados, self).dispatch(*args, **kwargs) class UpdateBienesView(UpdateView): model = Bienes form_class = BienesUpdateForm template_name = "padron/bienes_edit_form.html" def get_success_url(self): messages.success(self.request, "Se actualizo el bien correctamente") return reverse('lista-bienes') def get_context_data(self, **kwargs): context = super(UpdateBienesView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["padron"] = "active" return context def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(UpdateBienesView, self).form_invalid(form) class EliminarBienesView(DeleteView): model = Bienes def get_success_url(self): messages.success(self.request, "Se elimino el bien correctamente") return reverse('lista-bienes') def get_context_data(self, **kwargs): context = super(EliminarBienesView, self).get_context_data(**kwargs) context["padron"] = "active" return context class DetalleBienesView(DetailView): model = Bienes def get_context_data(self, **kwargs): context = super(DetalleBienesView, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context class JasperMix(object): url = settings.JASPERSERVER username = 'jasperadmin' password = 'jasperadmin' def generateReport(self, path, namefile, params={}, tipo=None): """ Gennara reportes atravez del jasperserver :param path: :param namefile: :param params: :param tipo: default is PDF """ j = JasperClient(self.url, self.username, self.password) ret = j.runReport(path, ("PDF" if not tipo else tipo), params) f = file(namefile, 'w') f.write(ret['data']) f.close() class reporteusuario(FormView, JasperMix): template_name = 'padron/reporteusuarioform.html' form_class = ReporteUsuarioForm def get(self, request, *args, **kwargs): return super(reporteusuario, self).get(request, *args, **kwargs) def form_valid(self, form): uid = self.request.POST['usuario'] folio = self.request.POST['folio'] firma = '' if form.cleaned_data["firmas"] != None: firma = form.cleaned_data["firmas"].director url = 'http://10.2.8.36/jasperserver/flow.html?_flowId=viewReportFlow&standAlone=true&ParentFolderUri=%2Flocalizacionbienesmuebles%2Fproduccion&reportUnit=%2Flocalizacionbienesmuebles%2Fproduccion%2Fusuario&j_username=jasperadmin&j_password=jasperadmin&uid=' + str( uid) + '&folio=' + folio + '&firma=' + firma + '&output=xls' return HttpResponseRedirect(url) def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(reporteusuario, self).form_invalid(form) def get_context_data(self, **kwargs): context = super(reporteusuario, self).get_context_data(**kwargs) context['padron'] = 'active' context["padron_ac"] = "active" return context from io import BytesIO import requests from rest_framework.views import Response, status, APIView class GetDetallePersona(APIView): def get(self, request): data = {} if self.request.is_ajax: if self.request.GET.get('firma'): id_persona = self.request.GET.get('firma') if self.request.GET.get('firma_director'): id_persona = self.request.GET.get('firma_director') firma = firmas.objects.get(pk=id_persona) serialize = GetDetallePersonaSerialize(firma) data = serialize.data return Response(data) class EstatusBien(APIView): def get(self,request): data = {} if self.request.is_ajax: id_estatus = self.request.GET.get('id_estatus') estatus = Estatus.objects.get(pk=id_estatus) serialize = EstatusSerialize(estatus) data = serialize.data return Response(data) class reporteusuariopdf(View): def get(self, request, **kwargs): report_name = 'produccion' try: usuario = self.request.GET.get('usuario') folio = self.request.GET.get('folio') firma = self.request.GET.get('firma') puesto_jefe_inmediato = self.request.GET.get('puesto_jefe_inmediato') firma_director = self.request.GET.get('firma_director') p_director = self.request.GET.get('p_director') if p_director == 'null': p_director = '' estatus = self.request.GET.get('id_estatus') parametros = { 'uid': usuario, 'folio': folio, 'firma': firma, 'puesto_jefe_inmediato': puesto_jefe_inmediato, 'firma_director': firma_director, 'p_director': p_director, 'id_estatus': estatus } url = '{url}/jasperserver/flow.html?_flowId=viewReportFlow&standAlone=true&_flowId=viewReportFlow&ParentFolderUri=%2Flocalizacionbienesmuebles%2F' \ 'produccion&reportUnit=%2Flocalizacionbienesmuebles%2Fproduccion%2Freporte_usuario2_actualizado&output=pdf'.format( url=settings.JASPER_URL, report_name=report_name) r = requests.get(url, params=parametros, auth=(settings.JASPER_USER, settings.JASPER_PASSWORD)) response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'filename=reporteusuario{0}{0}{0}{0}{0}{0}{0}.pdf'.format(usuario, folio, firma, puesto_jefe_inmediato, firma_director, p_director,estatus) buffer = BytesIO(r.content) pdf = buffer.getvalue() buffer.close() response.write(pdf) return response except Exception as error: return Response(status=status.HTTP_404_NOT_FOUND, data={"Error": "{0}".format(error)}) class reporteusuarioxls(View): def get(self, request, **kwargs): report_name = 'produccion' try: usuario = self.request.GET.get('usuario') folio = self.request.GET.get('folio') firma = self.request.GET.get('firma') puesto_jefe_inmediato = self.request.GET.get('puesto_jefe_inmediato') firma_director = self.request.GET.get('firma_director') p_director = self.request.GET.get('p_director') estatus = self.request.GET.get('id_estatus') parametros = { 'uid': usuario, 'folio': folio, 'firma': firma, 'puesto_jefe_inmediato': puesto_jefe_inmediato, 'firma_director': firma_director, 'p_director': p_director, 'id_estatus': estatus } url = '{url}/jasperserver/flow.html?_flowId=viewReportFlow&standAlone=true&_flowId=viewReportFlow&ParentFolderUri=%2Flocalizacionbienesmuebles%2F' \ 'produccion&reportUnit=%2Flocalizacionbienesmuebles%2Fproduccion%2Freporte_usuario2_actualizado&output=xls'.format( url=settings.JASPER_URL, report_name=report_name) r = requests.get(url, params=parametros, auth=(settings.JASPER_USER, settings.JASPER_PASSWORD)) response = HttpResponse(content_type='application/xls') response['Content-Disposition'] = 'filename=reporteusuario{0}{0}{0}{0}{0}{0}{0}.xls'.format(usuario, folio, firma, puesto_jefe_inmediato, firma_director, p_director,estatus) buffer = BytesIO(r.content) xls = buffer.getvalue() buffer.close() response.write(xls) return response except Exception as error: return Response(status=status.HTTP_404_NOT_FOUND, data={"Error": "{0}".format(error)}) class reporteusuario2(FormView, JasperMix): template_name = 'padron/reporteusuarioform.html' form_class = ReporteUsuarioForm def get(self, request, *args, **kwargs): return super(reporteusuario2, self).get(request, *args, **kwargs) def form_valid(self, form): uid = self.request.POST['usuario'] folio = self.request.POST['folio'] pdf = self.request.POST.get('pdf') exel = self.request.POST.get('excel') firma = '' puesto_jefe_inmediato = '' if form.cleaned_data["firma"] != None: firma = form.cleaned_data["firma"].director puesto_jefe_inmediato = form.cleaned_data["firma"].puesto firma_director = form.cleaned_data["firma_director"].director puesto = firmas.objects.get(director=firma_director) p_director = puesto.puesto try: queryset = Bienes.objects.filter(estatus_id__in=[1, 4, 5, 6, 7, 9], usuarios_id=uid) if len(queryset) < 1: messages.error(self.request, 'No existen datos para mostrar') return HttpResponseRedirect(reverse('reporteusuario2')) elif pdf == 'PDF': # LINK DEL VIEJO REPORTE # self.generateReport('/localizacionbienesmuebles/produccion/usuario2', self.generateReport('/localizacionbienesmuebles/produccion/reporte_usuario2_actualizado', settings.MEDIA_ROOT + 'reporteusuario.PDF', {'uid': uid, 'firma': firma, 'puesto_jefe_inmediato': puesto_jefe_inmediato, 'folio': folio, 'firma_director': firma_director, 'p_director': p_director, }, 'PDF') return HttpResponseRedirect('/media/reporteusuario.PDF') elif exel == 'EXCEL': # LINK DEL VIEJO REPORTE # self.generateReport('/localizacionbienesmuebles/produccion/usuario2', self.generateReport('/localizacionbienesmuebles/produccion/reporte_usuario2_actualizado', settings.MEDIA_ROOT + 'reporteusuario.xls', {'uid': uid, 'firma': firma, 'puesto_jefe_inmediato': puesto_jefe_inmediato, 'folio': folio, 'firma_director': firma_director, 'p_director': p_director, }, 'xls') return HttpResponseRedirect('/media/reporteusuario.xls') return except Exception, e: messages.error(self.request, 'ocurrio un error durante la carga del reporte' + str(e)) return HttpResponseRedirect(reverse('reporteusuario2')) def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(reporteusuario2, self).form_invalid(form) def get_context_data(self, **kwargs): context = super(reporteusuario2, self).get_context_data(**kwargs) context['reporte'] = 'active' return context class reportebienind(FormView, JasperMix): template_name = 'padron/reportebienindform.html' form_class = ReporteBienForm def get(self, request, *args, **kwargs): return super(reportebienind, self).get(request, *args, **kwargs) def form_valid(self, form): uid = self.request.POST['bien'] folio = self.request.POST['folio'] firma = '' if form.cleaned_data["firmas"] != None: firma = form.cleaned_data["firmas"].director try: self.generateReport('/localizacionbienesmuebles/produccion/bienind', settings.MEDIA_ROOT + 'reportebienind.PDF', {'uid': uid, 'firma': firma, 'folio': folio, }, 'PDF') return HttpResponseRedirect('/media/reportebienind.PDF') except Exception, e: messages.error(self.request, 'ocurrio un error durante la carga del reporte' + str(e)) return HttpResponseRedirect(reverse('reportebienind')) def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(reportebienind, self).form_invalid(form) def get_context_data(self, **kwargs): context = super(reportebienind, self).get_context_data(**kwargs) context['padron'] = 'active' context["padron_ac"] = "active" return context class reporteresguardo(FormView, JasperMix): template_name = 'padron/reportebienindform.html' form_class = ReporteResguardoForm def get(self, request, *args, **kwargs): return super(reporteresguardo, self).get(request, *args, **kwargs) def form_valid(self, form): no_reguardo = self.request.POST['no_resguardo'] folio = self.request.POST['folio'] firma = '' puesto_jefe_inmediato = '' if form.cleaned_data["firma"] != None: firma = form.cleaned_data["firma"].director puesto_jefe_inmediato = form.cleaned_data["firma"].puesto firma_director = form.cleaned_data["firma_director"].director puesto = firmas.objects.get(director=firma_director) p_director = puesto.puesto try: # VIEJA LIGA DE REPORTE # self.generateReport('/localizacionbienesmuebles/produccion/respaldo', self.generateReport('/localizacionbienesmuebles/produccion/reporte_respaldo_actualizado', settings.MEDIA_ROOT + 'reporterespaldo.PDF', {'no_reguardo': no_reguardo, 'firma': firma, 'puesto_jefe_inmediato': puesto_jefe_inmediato, 'folio': folio, 'firma_director': firma_director, 'p_director': p_director, }, 'PDF') return HttpResponseRedirect('/media/reporterespaldo.PDF') except Exception, e: messages.error(self.request, 'ocurrio un error durante la carga del reporte' + str(e)) return HttpResponseRedirect(reverse('reporteresguardo')) def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(reporteresguardo, self).form_invalid(form) def get_context_data(self, **kwargs): context = super(reporteresguardo, self).get_context_data(**kwargs) context['reporte'] = 'active' return context class reportedependencia(FormView, JasperMix): template_name = 'padron/reporteusuarioform.html' form_class = ReporteDependenciaForm def get(self, request, *args, **kwargs): return super(reportedependencia, self).get(request, *args, **kwargs) def form_valid(self, form): did = self.request.POST['dependencias'] pdf = self.request.POST.get('pdf') excel = self.request.POST.get('excel') urls = '' try: if pdf == 'PDF': self.generateReport('/localizacionbienesmuebles/produccion/dependencia', settings.MEDIA_ROOT + 'reportedependencia.PDF', {'did': did, }, 'PDF') urls = '/media/reportedependencia.PDF' elif excel == 'EXCEL': self.generateReport('/localizacionbienesmuebles/produccion/dependencia', settings.MEDIA_ROOT + 'reportedependencia.xls', {'did': did, }, 'xls') urls = '/media/reportedependencia.xls' return HttpResponseRedirect(urls) except Exception, e: messages.error(self.request, 'ocurrio un error durante la carga del reporte' + str(e)) return HttpResponseRedirect(reverse('reportedependencia')) def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(reportedependencia, self).form_invalid(form) def get_context_data(self, **kwargs): context = super(reportedependencia, self).get_context_data(**kwargs) context['reporte'] = 'active' return context class reportedepartamento(FormView, JasperMix): template_name = 'padron/reporteusuarioform.html' form_class = ReporteDepartamentoForm def get(self, request, *args, **kwargs): return super(reportedepartamento, self).get(request, *args, **kwargs) def form_valid(self, form): depeid = self.request.POST['dependencia'] depaid = self.request.POST['departamento'] try: self.generateReport('/localizacionbienesmuebles/local/dependenciadepartamento', settings.MEDIA_ROOT + 'reportedependencia.PDF', {'depeid': depeid, 'depaid': depaid}, 'PDF') return HttpResponseRedirect('/media/reportedependencia.PDF') except Exception, e: messages.error(self.request, 'ocurrio un error durante la carga del reporte' + str(e)) return HttpResponseRedirect(reverse('reportedepartamento')) def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(reportedepartamento, self).form_invalid(form) def get_context_data(self, **kwargs): context = super(reportedepartamento, self).get_context_data(**kwargs) context['padron'] = 'active' context["padron_ac"] = "active" return context class HomeView(TemplateView): template_name = 'tablero.html' def get_context_data(self, **kwargs): context = super(HomeView, self).get_context_data(**kwargs) context['inicio'] = 'active' return context class imprimirinventario(View, JasperMix): def get(self, request, *args, **kwargs): try: self.generateReport('/localizacionbienesmuebles/produccion/global', settings.MEDIA_ROOT + 'global.xls', {}, 'xls') return HttpResponseRedirect('/media/global.xls') except Exception, e: messages.error(self.request, 'ocurrio un error durante la carga del reporte' + str(e)) return HttpResponseRedirect(reverse('reporteusuario2')) class imprimirestatus(FormView, JasperMix): template_name = 'padron/reportebienindform.html' form_class = ReporteEstatusForm def get(self, request, *args, **kwargs): return super(imprimirestatus, self).get(request, *args, **kwargs) def form_valid(self, form): eid = self.request.POST['estatus'] try: queryset = Bienes.objects.filter(estatus_id=eid) if len(queryset) < 1: messages.error(self.request, 'No existen datos para mostrar') return HttpResponseRedirect(reverse('imprimirestatus')) else: self.generateReport('/localizacionbienesmuebles/produccion/estatus', settings.MEDIA_ROOT + 'reporteestatus' + str(eid) + '.xls', {'eid': eid}, 'xls') return HttpResponseRedirect('/media/reporteestatus' + str(eid) + '.xls') except Exception, e: messages.error(self.request, 'ocurrio un error durante la carga del reporte' + str(e)) return HttpResponseRedirect(reverse('imprimirestatus')) def get_context_data(self, **kwargs): context = super(imprimirestatus, self).get_context_data(**kwargs) context['reporte'] = 'active' return context class reporte_bienes(FormView, JasperMix): template_name = 'padron/reporteusuarioform.html' form_class = ReporteUsuarioForm def get(self, request, *args, **kwargs): return super(reporte_bienes, self).get(request, *args, **kwargs) def form_valid(self, form): uid = self.request.POST['usuario'] folio = self.request.POST['folio'] firma = '' if form.cleaned_data["firmas"] != None: firma = form.cleaned_data["firmas"].director try: self.generateReport('/localizacionbienesmuebles/produccion/usuario3', settings.MEDIA_ROOT + 'reporteusuario.xls', {'uid': uid, 'firma': firma, 'folio': folio, }, 'xls') return HttpResponseRedirect('/media/reporteusuario.xls') except Exception, e: messages.error(self.request, 'ocurrio un error durante la carga del reporte' + str(e)) return HttpResponseRedirect(reverse('reporteusuario2')) def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(reporte_bienes, self).form_invalid(form) def get_context_data(self, **kwargs): context = super(reporte_bienes, self).get_context_data(**kwargs) context['padron'] = 'active' context["padron_ac"] = "active" return context class ListaBienesRecepcionView(DinamicPaginationMixin, SearchMixin, ListView): template_name = 'padron/recepcion_list.html' model = Bienes queryset = Bienes.objects.filter(estatus_id=8).order_by('modelo') def get_filter(self, queryset): search = self.get_search() if queryset: queryset = queryset.filter( Q(descripcion__icontains=search) | Q(marca__icontains=search) | Q(modelo__icontains=search) | Q(no_serie__icontains=search) | Q(no_factura__icontains=search) | Q(no_inventario_oficial__icontains=search) | Q(no_inventario_dgtic__icontains=search) | Q(no_resguardo__icontains=search) | Q(estado__icontains=search) | Q(observaciones__icontains=search) | Q(ubicacion__icontains=search) | Q(usuarios__nombre__icontains=search) | Q(usuarios__apellido_paterno__icontains=search) | Q(usuarios__apellido_materno__icontains=search) | Q(usuarios__dependencias__nombre__icontains=search) | Q(usuarios__dependencias__clave_dependencia__icontains=search) | Q(usuarios__departamentos__nombre__icontains=search) | Q(usuarios__departamentos__clave_departamento__icontains=search) | Q(usuarios__cargo__icontains=search) ) return queryset def get_context_data(self, **kwargs): context = super(ListaBienesRecepcionView, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context class CrearRecepcionView(CreateView): template_name = 'padron/recepcion_form.html' model = Bienes form_class = RecepcionForm def get_success_url(self): messages.success(self.request, "Se ha registrado correctamente la información") return reverse_lazy("lista-recepcion") def get_context_data(self, **kwargs): context = super(CrearRecepcionView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["padron"] = "active" return context class DetalleRecepcionView(DetailView): template_name = 'padron/recepcion_detail.html' model = Bienes def get_context_data(self, **kwargs): context = super(DetalleRecepcionView, self).get_context_data(**kwargs) context["padron"] = "active" context["padron_ac"] = "active" return context class UpdateRecepcionView(UpdateView): model = Bienes form_class = RecepcionUpdateForm template_name = "padron/recepcion_edit_form.html" def get_success_url(self): messages.success(self.request, "Se actualizo la información correctamente") return reverse_lazy("lista-recepcion") def get_context_data(self, **kwargs): context = super(UpdateRecepcionView, self).get_context_data(**kwargs) context["padron_ac"] = "active" context["padron"] = "active" return context def form_invalid(self, form): messages.error(self.request, 'corrija los siguientes errores') return super(UpdateRecepcionView, self).form_invalid(form) class EliminarRecepcionView(DeleteView): model = Bienes template_name = "padron/recepcion_confirm_delete.html" def get_success_url(self): messages.success(self.request, "Se elimino el registro correctamente") return reverse_lazy("lista-recepcion") def get_context_data(self, **kwargs): context = super(EliminarRecepcionView, self).get_context_data(**kwargs) context["padron"] = "active" return context