Commit bbadb97b authored by Gladys Forte's avatar Gladys Forte

Merge branch 'core-dev-gladys' into 'core-dev'

{dev bugfix} remove download folder in master

See merge request rms/Backend/api-main-service!876
parents 13cf4a8d f32e83a2
...@@ -5,7 +5,7 @@ from drf_renderer_xlsx.renderers import XLSXRenderer ...@@ -5,7 +5,7 @@ from drf_renderer_xlsx.renderers import XLSXRenderer
from app.entities.models import ( from app.entities.models import (
User User
) )
from app.applicationlayer.master.download.accounts.serializers import headers from app.applicationlayer.download.accounts.serializers import headers
from django.db.models import CharField, Value from django.db.models import CharField, Value
from django.db.models import Q from django.db.models import Q
from rest_framework.response import Response from rest_framework.response import Response
...@@ -27,23 +27,15 @@ class UserDownloadRequest(XLSXFileMixin, ReadOnlyModelViewSet): ...@@ -27,23 +27,15 @@ class UserDownloadRequest(XLSXFileMixin, ReadOnlyModelViewSet):
company = self.request.user.department.company.code company = self.request.user.department.company.code
department = self.request.user.department.code department = self.request.user.department.code
print(user_type)
print(company)
print(department)
if user_type == 'CUA': if user_type == 'CUA':
print('cua')
data = User.objects.filter( data = User.objects.filter(
department__company=company).exclude(id=1) department__company=company).exclude(id=1)
elif user_type == 'DUA': elif user_type == 'DUA':
print('dua')
data = User.objects.filter( data = User.objects.filter(
department=department).exclude(id=1) department=department).exclude(id=1)
elif user_type == 'SU': elif user_type == 'SU':
print('su')
data = User.objects.all().exclude(id=1) data = User.objects.all().exclude(id=1)
elif user_type == 'OUA': elif user_type == 'OUA':
print('oua')
data = User.objects.all().exclude(id=1) data = User.objects.all().exclude(id=1)
else: else:
return Response( 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,14 +6,12 @@ from app.applicationlayer.master.company.views import AdminCompanyViewSet ...@@ -6,14 +6,12 @@ from app.applicationlayer.master.company.views import AdminCompanyViewSet
from app.applicationlayer.master.department.views import AdminDepartmentViewSet from app.applicationlayer.master.department.views import AdminDepartmentViewSet
from app.applicationlayer.master.user_type.views import UserTypeViewSet from app.applicationlayer.master.user_type.views import UserTypeViewSet
from app.applicationlayer.master.attachment.views import MasterAttachmentViewSet from app.applicationlayer.master.attachment.views import MasterAttachmentViewSet
from app.applicationlayer.master.download.accounts.views import UserDownloadRequest
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'users', AdminAccountViewSet) router.register(r'users', AdminAccountViewSet)
router.register(r'companies', AdminCompanyViewSet) router.register(r'companies', AdminCompanyViewSet)
router.register(r'departments', AdminDepartmentViewSet) router.register(r'departments', AdminDepartmentViewSet)
router.register(r'attachments', MasterAttachmentViewSet) router.register(r'attachments', MasterAttachmentViewSet)
router.register(r'user-download', UserDownloadRequest)
urlpatterns = [ urlpatterns = [
path('', include(router.urls)), 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