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