Commit d3b1fb87 authored by Gladys Forte's avatar Gladys Forte

Merge branch 'core-dev' into 'core-sit'

Core dev

See merge request rms/Backend/api-main-service!870
parents 4b300877 13cf4a8d
......@@ -5,13 +5,11 @@ from drf_renderer_xlsx.renderers import XLSXRenderer
from app.entities.models import (
User
)
# from app.applicationlayer.form_listing_ import headers
from app.applicationlayer.download.accounts.serializers import headers
from app.applicationlayer.master.download.accounts.serializers import headers
from django.db.models import CharField, Value
from django.db.models import Q
from rest_framework.response import Response
from rest_framework.permissions import AllowAny
# from cms.applicationlayer.utilities import logged_user
from rest_framework.exceptions import ParseError
from rest_framework import status
......@@ -25,22 +23,27 @@ class UserDownloadRequest(XLSXFileMixin, ReadOnlyModelViewSet):
def list(self, request, *args, **kwargs):
# id_number = self.request.user
data = User.objects.all().exclude(id=1)
user_type = data.values_list('user_type', flat=True)[0]
user_type = self.request.user.user_type
company = self.request.user.department.company.code
department = self.request.user.department.code
print(user_type)
print(company)
print(department)
if user_type == 'CUA':
code = data.values_list('department__company', flat=True)[0]
print('cua')
data = User.objects.filter(
department__company=code).exclude(id=1)
department__company=company).exclude(id=1)
elif user_type == 'DUA':
code = data.values_list('department', flat=True)[0]
print('dua')
data = User.objects.filter(
department=code).exclude(id=1)
department=department).exclude(id=1)
elif user_type == 'SU':
print('su')
data = User.objects.all().exclude(id=1)
elif user_type == 'OUA':
print('oua')
data = User.objects.all().exclude(id=1)
else:
return Response(
......
from app.entities import models
from rest_framework import serializers
from django.db.models import Q
class headers(serializers.ModelSerializer):
def to_representation(self, instance):
ret = super().to_representation(instance)
ret['deparment'] = instance.department.name
ret['company'] = instance.department.company.name
return ret
class Meta:
model = models.User
fields = (
'code',
'name',
'email',
'contact_no'
)
from rest_framework import viewsets as meviewsets
from rest_framework.viewsets import ReadOnlyModelViewSet
from drf_renderer_xlsx.mixins import XLSXFileMixin
from drf_renderer_xlsx.renderers import XLSXRenderer
from app.entities.models import (
User
)
from app.applicationlayer.master.download.accounts.serializers import headers
from django.db.models import CharField, Value
from django.db.models import Q
from rest_framework.response import Response
from rest_framework.permissions import AllowAny
from rest_framework.exceptions import ParseError
from rest_framework import status
class UserDownloadRequest(XLSXFileMixin, ReadOnlyModelViewSet):
queryset = User.objects.all()
serializer_class = headers
renderer_classes = (XLSXRenderer,)
filename = 'User List.xlsx'
permission_classes = (AllowAny,)
def list(self, request, *args, **kwargs):
user_type = self.request.user.user_type
company = self.request.user.department.company.code
department = self.request.user.department.code
print(user_type)
print(company)
print(department)
if user_type == 'CUA':
print('cua')
data = User.objects.filter(
department__company=company).exclude(id=1)
elif user_type == 'DUA':
print('dua')
data = User.objects.filter(
department=department).exclude(id=1)
elif user_type == 'SU':
print('su')
data = User.objects.all().exclude(id=1)
elif user_type == 'OUA':
print('oua')
data = User.objects.all().exclude(id=1)
else:
return Response(
{"message": "Logged user is unauthorize to access this section"},
status=status.HTTP_400_BAD_REQUEST
)
serializer = headers(data=data, many=True)
serializer.is_valid(raise_exception=False)
return Response(serializer.data)
column_header = {
'titles': [
'ID_NUMBER',
'Name',
'Email',
'Contact Number',
'Department',
'Company'
],
'column_width': [17, 30, 17],
'height': 25,
'style': {
'alignment': {
'horizontal': 'center',
'vertical': 'center',
'wrapText': False,
'shrink_to_fit': True,
},
'border_side': {
'border_style': 'thin',
'color': 'FF000000',
},
'font': {
'name': 'Arial',
'size': 14,
'bold': True,
'color': 'FF000000',
},
},
}
......@@ -6,12 +6,14 @@ from app.applicationlayer.master.company.views import AdminCompanyViewSet
from app.applicationlayer.master.department.views import AdminDepartmentViewSet
from app.applicationlayer.master.user_type.views import UserTypeViewSet
from app.applicationlayer.master.attachment.views import MasterAttachmentViewSet
from app.applicationlayer.master.download.accounts.views import UserDownloadRequest
router = routers.DefaultRouter()
router.register(r'users', AdminAccountViewSet)
router.register(r'companies', AdminCompanyViewSet)
router.register(r'departments', AdminDepartmentViewSet)
router.register(r'attachments', MasterAttachmentViewSet)
router.register(r'user-download', UserDownloadRequest)
urlpatterns = [
path('', include(router.urls)),
......
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