diff --git a/cosiap_api/dynamic_tables/DynamicTable.py b/cosiap_api/dynamic_tables/DynamicTable.py index 4538082ad6d97fd644dee9149bf44cae896f7b46..07e428cd28226ff5dc94aa6afba3d61296304f04 100644 --- a/cosiap_api/dynamic_tables/DynamicTable.py +++ b/cosiap_api/dynamic_tables/DynamicTable.py @@ -85,6 +85,7 @@ class DynamicTable(serializers.ModelSerializer): clean_filters = self.validate_and_clean_filters({'filters': filters}, available_filters) queryset = model.objects.all() + print(queryset) # Aplicar filtros usando la función recursiva queryset = self.apply_filters(queryset, clean_filters, exclude_filters) @@ -151,9 +152,6 @@ class DynamicTable(serializers.ModelSerializer): model = self.buscar_modelo(obj) for column in obj.columns: - print(column) - if column == 'formulario': - continue field_path = column.split('__') field = model label = "" @@ -188,6 +186,10 @@ class DynamicTable(serializers.ModelSerializer): elif isinstance(field, models.DateField) or isinstance(field, models.DateTimeField): filter_info['html_type'] = 'dateInput' filter_info['lookups'] = ['gt', 'lt', 'gte', 'lte'] + elif isinstance(field, models.BooleanField): + filter_info['html_type'] = 'checkbox' + filter_info['lookups'] = ['iexact'] + filter_info['choices'] = ['True', 'False'] available_filters.append(filter_info) @@ -326,6 +328,7 @@ class DynamicTable(serializers.ModelSerializer): :return: Queryset filtrado según los filtros y las exclusiones especificadas. """ + print(filters, exclude_filters) if not filters and not exclude_filters: return queryset @@ -334,6 +337,7 @@ class DynamicTable(serializers.ModelSerializer): # Aplicar filtros (OR dentro de un mismo campo, AND entre diferentes campos) for field, lookup_values in filters.items(): + print(field, lookup_values) field_q_objects = Q() for lookup, values in lookup_values.items(): lookup_q_objects = Q() diff --git a/cosiap_api/dynamic_tables/DynamicTableDynamicForm.py b/cosiap_api/dynamic_tables/DynamicTableDynamicForm.py index 65d2b050847200b005954814572e447eef870703..0edff3f4baec796a220968f3649510b4983b0c33 100644 --- a/cosiap_api/dynamic_tables/DynamicTableDynamicForm.py +++ b/cosiap_api/dynamic_tables/DynamicTableDynamicForm.py @@ -1,7 +1,7 @@ from .DynamicTable import DynamicTable from dynamic_forms.models import DynamicForm from solicitudes.models import Solicitud -from dynamic_forms.models import Respuesta +from dynamic_forms.models import Respuesta, RCasillas, RDesplegable, RDocumento, RFecha, RHora, RNumerico, ROpcionMultiple, RTextoCorto, RTextoParrafo from dynamic_forms.serializers import OpcionSerializer, ElementosOpcionesSerializer, ElementoSerializer, SeccionesElementosSerializer, SeccionSerializer, DynamicFormsSeccionesSerializer, DynamicFormSerializer, RespuestaFormularioSerializer @@ -29,4 +29,5 @@ class DynamicTableDynamicForm(DynamicTable): + \ No newline at end of file diff --git a/cosiap_api/users/urls.py b/cosiap_api/users/urls.py index 60d722866fdef5ed86cdd23be5cc56d2b2d3805f..db0e4aa4f07eb9fe3eeb986c9cd0317dc073b752 100644 --- a/cosiap_api/users/urls.py +++ b/cosiap_api/users/urls.py @@ -9,7 +9,8 @@ app_name = 'users' urlpatterns = [ path('token/', CustomTokenObtainPairView.as_view(), name='token_obtain'), path('token/refresh/', CustomTokenRefreshView.as_view(), name='token_refresh'), - path('uid/', views.UserIDUserIsStaff.as_view(), name='user_id'), + path('uid/', views.UserID.as_view(), name='user_id'), + path('user-is-admin/', views.UserIsStaff.as_view(), name='user_staff'), path('', views.UsuarioAPIView.as_view(), name = 'usuarios'), path('/', views.UsuarioAPIView.as_view(), name = 'usuarios_pk'), diff --git a/cosiap_api/users/views.py b/cosiap_api/users/views.py index 22c9646c2c1cfe79f6514692e9ad19a94756fd8e..1abba574a6e76020b7f772ff7c6415d4f056326d 100644 --- a/cosiap_api/users/views.py +++ b/cosiap_api/users/views.py @@ -60,30 +60,45 @@ class CustomTokenRefreshView(TokenRefreshView): return response -class UserIDUserIsStaff(APIView): +class UserID(APIView): ''' - Clase para obtener el id y el tipo de usuario del usuario actual + Clase para recuperar el ID del usuario logeado actual ''' - permission_classes = [AllowAny] + + permission_classes = [IsAuthenticated] + data = {} def get(self, request, *args, **kwargs): - ''' - Método get para obtener la response con el id y tipo de usuario del usuario que - realizó la petición - ''' - data = {} + try: user = request.user uid = user.id - user_type = user.is_staff + self.data['user_id'] = uid + return Response(self.data, status= status.HTTP_200_OK) + except Exception as e: + Mensaje.error(self.data, str(e)) + return Response(self.data, status=status.HTTP_400_BAD_REQUEST) + - data = {'user_id': uid, 'user_is_admin': user_type} +class UserIsStaff(APIView): + ''' + Clase para indicar si el usuario logeado es admin o solicitante + ''' - return Response(data, status = status.HTTP_200_OK) + permission_classes = [IsAuthenticated] + data = {} + + def get(self, request, *args, **kwargs): + try: + user = request.user + user_is_admin = user.is_staff + self.data['user_is_admin'] = user_is_admin + return Response(self.data, status= status.HTTP_200_OK) except Exception as e: - - Mensaje.error(data, str(e)) + Mensaje.error(self.data, str(e)) + return Response(self.data, status=status.HTTP_400_BAD_REQUEST) +