Commit 3945e1ed authored by John Red Medrano's avatar John Red Medrano

added endpoint list of user to change request application

parent 1ff80f8e
......@@ -83,8 +83,8 @@ class RefreshToken(APIView):
class CurrentUser(APIView):
# @decorators.error_safe
def get(self, request, token=None, *arUserManagementRetreiveSerializergs, **kwargs):
@decorators.error_safe
def get(self, request, token=None, *args, **kwargs):
serializer = UserManagementRetreiveSerializer
context = {"request": request}
......
......@@ -20,7 +20,7 @@ import requests
from django.conf import settings
from rest_framework.exceptions import ValidationError
from django.db import transaction, IntegrityError, connection
from app.applicationlayer.utils import QuerySetHelper
from app.applicationlayer.utils import QuerySetHelper, CustomPagination, status_message_response
from app.businesslayer.changerequest import change_request
from app.applicationlayer.cms.utils_cr import number_generator, crhistory_save
from django.shortcuts import get_object_or_404
......@@ -28,7 +28,69 @@ from django.shortcuts import get_object_or_404
from rest_framework.generics import GenericAPIView
from rest_framework.mixins import UpdateModelMixin
from django.forms.models import model_to_dict
from app.entities import enums
from app.entities import enums, models
from app.applicationlayer.management.account.serializer import ChangeRequestList
class UserList(APIView):
pagination_class = CustomPagination
def get(self, request, *args, **kwargs):
try:
serializer = ChangeRequestList
dept = self.request.query_params['department_id']
queryset = models.User.objects.filter(department=dept).order_by('name')
page = self.paginate_queryset(queryset)
if page is not None:
serializer = ChangeRequestList(page, many=True)
message = status_message_response(
200,
'success',
'list of User found',
serializer.data
)
return self.get_paginated_response(message)
except Exception as e:
return Response(
{"message": "this endpoint expect a query params department_id"},
status=status.HTTP_400_BAD_REQUEST
)
@property
def paginator(self):
"""
The paginator instance associated with the view, or `None`.
"""
if not hasattr(self, '_paginator'):
if self.pagination_class is None:
self._paginator = None
else:
self._paginator = self.pagination_class()
return self._paginator
def paginate_queryset(self, queryset):
"""
Return a single page of results, or `None` if pagination is disabled.
"""
if self.paginator is None:
return None
return self.paginator.paginate_queryset(queryset, self.request, view=self)
def get_paginated_response(self, data):
"""
Return a paginated style `Response` object for the given output data.
"""
assert self.paginator is not None
return self.paginator.get_paginated_response(data)
class ChangeRequestTemplatesViewset(meviewsets.ModelViewSet):
......
......@@ -27,4 +27,5 @@ urlpatterns = (
path('', include(router.urls)),
path('template-post/', crtemplate_views.ChangeRequestTemplatePost.as_view()),
path('form-post/', crform_views.ChangeRequestFormPost.as_view()),
path('user-list/', crtemplate_views.UserList.as_view(), name="User List"),
)
......@@ -33,6 +33,20 @@ class UserSerializer(serializers.ModelSerializer):
)
class ChangeRequestList(serializers.ModelSerializer):
class Meta:
model = User
fields = (
'id',
'code', 'name',
'username', 'contact_no',
'email', 'default_app',
'user_type', 'is_active',
'doa'
)
class ChangePasswordSerializer(serializers.Serializer):
old_password = serializers.CharField(required=True)
new_password = serializers.CharField(required=True, min_length=6)
......
......@@ -26,7 +26,7 @@ class ModuleViewSet(viewsets.ModelViewSet):
ordering_fields = '__all__'
search_fields = (
'name', 'application__name',
'code', 'component', 'sort_number'
'code', 'component', 'sort_id'
)
@transaction.atomic
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment