source: sapic/organizaciones/ajax.py @ 3fa4fdc

Last change on this file since 3fa4fdc was 6d6c368, checked in by William Páez <wpaez@…>, 6 años ago

actualizar organización social lista

  • Propiedad mode establecida a 100644
File size: 5.0 KB
Línea 
1# -*- encoding: utf-8 -*-
2from django.conf import settings
3from django_datatables_view.base_datatable_view import BaseDatatableView
4from organizaciones.models import (
5    OrganizacionSocial
6    )
7from users.models import (
8    UserProfileVocero
9    )
10from utils.views import (
11    LoginRequeridoPerAuth
12)
13
14class ListOrgsAjaxView(LoginRequeridoPerAuth, BaseDatatableView):
15    """!
16    Prepara la data para mostrar en el datatable
17
18    @author Ing. Erwin Leonel P. (eparedes at cenditel.gob.ve)
19    @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a>
20    @date 08-08-2017
21    @version 1.0.0
22    """
23    # The model we're going to show
24    model = OrganizacionSocial
25    # define the columns that will be returned
26    columns = ['pk','fk_tipo_organizacion','codigo','rif','situr','nombre',
27               'email','fecha_conformacion','sector','localidad','activa']
28    # define column names that will be used in sorting
29    # order is important and should be same as order of columns
30    # displayed by datatables. For non sortable columns use empty
31    # value like ''
32    order_columns = ['pk','fk_tipo_organizacion','codigo', 'rif', 'situr', 'nombre',
33                    'email','fecha_conformacion','sector','localidad','activa']
34    # set max limit of records returned, this is used to protect our site if someone tries to attack our site
35    # and make it return huge amount of data
36    max_display_length = 1000
37    group_required = [u"Administradores", u"Voceros"]
38
39    def __init__(self):
40        super(ListOrgsAjaxView, self).__init__()
41
42    def get_initial_queryset(self):
43        """!
44        Consulta el modelo OrganizacionSocial
45
46        @return: Objeto de la consulta
47        """
48        # return queryset used as base for futher sorting/filtering
49        # these are simply objects displayed in datatable
50        # You should not filter data returned here by any filter values entered by user. This is because
51        # we need some base queryset to count total number of records.
52        user = self.request.user
53        try:
54            grupos = user.groups.all()
55            grupo = []
56            if len(grupos) > 1:
57                for g in grupos:
58                    grupo += str(g),
59            else:
60                grupo = str(user.groups.get())
61        except:
62            grupo = "No pertenece a un grupo"
63        if "Administradores" in grupo:
64            return self.model.objects.all()
65        elif "Voceros" in grupo:
66            return self.model.objects.all()
67        #    try:
68         #       usuario_vocero = UserProfileVocero.objects.select_related().get(fk_user=user)
69          #  except UserProfileVocero.DoesNotExist:
70           #     usuario_vocero = None
71            #return self.model.objects.select_related().filter(vocero__documento_identidad=usuario_vocero.fk_vocero.documento_identidad)
72
73    def prepare_results(self, qs):
74        """!
75        Prepara la data para mostrar en el datatable
76        @return: Objeto json con los datos de los usuarios
77        """
78        # prepare list with output column data
79        json_data = []
80        for item in qs:
81            org = "<a class='btn btn-block btn-info btn-xs fa fa-edit' href='../organizacion/actualizar/%s/'>%s</a>\
82                    " % (str(item.pk), str(item.fk_tipo_organizacion.tipo))
83            if item.fecha_conformacion:
84                fecha_conformacion = item.fecha_conformacion.strftime("%Y-%m-%d")
85            else:
86                fecha_conformacion = "No ha ingresado"
87            if item.activa:
88                activo = "Activo"
89                activar = "<input type='checkbox' id='org-" + str(item.pk) + "' value='" + str(item.pk) + "' name='inactivar' onclick='$(\"#forma_activar\").submit();'/>\
90                            <label for='org-" + str(item.pk) + "'>\
91                                <img  src='" + settings.MEDIA_URL +\
92                                "imagenes/inactivar.png' id='inactivo'\
93                                title='Inactivar Organización' \
94                                />\
95                            </label>"
96
97            else:
98                activo = "Inactivo"
99                activar = "<input type='checkbox' id='org-" + str(item.pk) + "' value='" + str(item.pk) + "' name='activar' onclick='$(\"#forma_activar\").submit();'/>\
100                            <label for='org-" + str(item.pk) + "'>\
101                                <img  src='" + settings.MEDIA_URL + \
102                                "imagenes/activar.png' id='activo' \
103                                title='Activar Organización'/>\
104                            </label>"
105            json_data.append([
106                org,
107                item.codigo,
108                item.rif,
109                item.situr,
110                item.nombre.title(),
111                item.email,
112                fecha_conformacion,
113                item.sector,
114                activo,
115                str(item.localidad),
116                activar
117            ])
118            grupo = ""
119        return json_data
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.