Commit 02429581 authored by John Red Medrano's avatar John Red Medrano

added company and department endpoint for change request app

parent ad73e4d6
from rest_framework import serializers
from app.entities.models import Company
class AdminCompanySerializer(serializers.ModelSerializer):
class Meta:
model = Company
fields = '__all__'
from django_filters import rest_framework as filters
from django.db.models import Count
from app.entities.models import Company
from django.db.models import Q
class ChangeRequestCompanyFilterSet(filters.FilterSet):
# search = filters.CharFilter(method='search_bar', label='search')
# def search_bar(self, queryset, name, value):
# return queryset.filter(
# Q(Companyname__icontains=value) |
# Q(first_name__icontains=value) |
# Q(last_name__icontains=value))
class Meta:
model = Company
fields = '__all__'
from rest_framework.filters import SearchFilter, OrderingFilter
from django_filters import rest_framework as filters
from app.entities.models import Company, AllowedCompany
from rest_framework import viewsets, status
from app.businesslayer.company.serializer import AdminCompanySerializer
from app.applicationlayer.utils import CustomPagination, status_message_response
from django_filters.rest_framework import DjangoFilterBackend
from app.applicationlayer.management.company import serializer
from app.applicationlayer.cms.master.company.table_filters import (
ChangeRequestCompanyFilterSet
)
from app.helper.decorators import rms
from rest_framework.response import Response
class ChangeRequestCompanyViewSet(viewsets.ModelViewSet):
queryset = Company.objects.all()
serializer_class = AdminCompanySerializer
pagination_class = CustomPagination
filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)
filterset_class = ChangeRequestCompanyFilterSet
ordering_fields = '__all__'
search_fields = ('name',)
http_method_names = ['get']
def list(self, request, *args, **kwargs):
print(self.request.user.code)
queryset = self.filter_queryset(self.get_queryset())
allowed = AllowedCompany.objects.filter(
id_number=self.request.user.code
).values('company_pivot')
# print(allowed)
queryset = queryset.filter(code__in=allowed)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
message = status_message_response(
200,
'success',
'list of Company found',
serializer.data
)
return self.get_paginated_response(message)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
from rest_framework import serializers
from app.entities.models import Department
from django.forms.models import model_to_dict
class AdminDepartmentSerializer(serializers.ModelSerializer):
def to_representation(self, instance):
ret = super().to_representation(instance)
ret['company'] = model_to_dict(instance.company)
return ret
class Meta:
model = Department
fields = '__all__'
read_only_fields = (
'created', 'createdby', 'modified', 'modifiedby', 'code',
)
from django_filters import rest_framework as filters
from django.db.models import Count
from app.entities.models import Department
from django.db.models import Q
class ChangeRequestDepartmentFilterSet(filters.FilterSet):
# search = filters.CharFilter(method='search_bar', label='search')
# def search_bar(self, queryset, name, value):
# return queryset.filter(
# Q(Companyname__icontains=value) |
# Q(first_name__icontains=value) |
# Q(last_name__icontains=value))
class Meta:
model = Department
fields = '__all__'
from rest_framework import viewsets, status
from rest_framework.response import Response
from django.forms.models import model_to_dict
from rest_framework.filters import SearchFilter, OrderingFilter
from django_filters import rest_framework as filters
from app.entities.models import Department, AllowedCompany
from app.applicationlayer.utils import (
CustomPagination, status_message_response
)
from django_filters.rest_framework import DjangoFilterBackend
from app.applicationlayer.master.department import serializer
from app.applicationlayer.cms.master.department.table_filters import (
ChangeRequestDepartmentFilterSet
)
from app.helper.decorators import rms
class ChangeRequestDepartmentViewSet(viewsets.ModelViewSet):
queryset = Department.objects.all()
serializer_class = serializer.AdminDepartmentSerializer
pagination_class = CustomPagination
lookup_field = 'code'
filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)
filterset_class = ChangeRequestDepartmentFilterSet
ordering_fields = '__all__'
search_fields = ('name', 'company__name', 'code')
@rms.department_list
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
allowed = AllowedCompany.objects.filter(
id_number=self.request.user.code
).values('group_pivots')
queryset = queryset.filter(code__in=allowed)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
message = status_message_response(
200,
'success',
'list of Department found',
serializer.data
)
return self.get_paginated_response(message)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
......@@ -5,7 +5,9 @@ from django.conf.urls import url
from app.applicationlayer.management.notification.views import NotificationsViewset
from app.applicationlayer.cms.template import views as crtemplate_views
from app.applicationlayer.cms.form import views as crform_views
from app.applicationlayer.cms.allowed_company import views
from app.applicationlayer.cms.allowed_company import views as allowed
from app.applicationlayer.cms.master.company.views import ChangeRequestCompanyViewSet
from app.applicationlayer.cms.master.department.views import ChangeRequestDepartmentViewSet
router = routers.DefaultRouter()
......@@ -22,13 +24,14 @@ router.register(r'form-approvers', crform_views.ChangeRequestFormApproversViewse
router.register(r'form-stakeholders', crform_views.ChangeRequestFormStakeHoldersViewset)
router.register(r'form-attachments', crform_views.ChangeRequestFormAttachmentsViewset)
router.register(r'form-details', crform_views.ChangeRequestFormDetailsViewset)
router.register(r'allowed-companies', views.AllowedCompanyViewSet)
router.register(r'allowed-companies', allowed.AllowedCompanyViewSet)
router.register(r'companies', ChangeRequestCompanyViewSet)
router.register(r'departments', ChangeRequestDepartmentViewSet)
urlpatterns = (
path('', include(router.urls)),
path('template-post/', crtemplate_views.ChangeRequestTemplatePost.as_view()),
path('form-post/', crform_views.ChangeRequestFormPost.as_view()),
# path('allowed-companies/', views.AllowedCompanyApiView.as_view()),
path('user-list/', crtemplate_views.UserList.as_view(), name="User List"),
)
......@@ -16,6 +16,34 @@
CREATE DATABASE IF NOT EXISTS `rms_db` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `rms_db`;
-- Dumping structure for table rms_db.allowed_company
CREATE TABLE IF NOT EXISTS `allowed_company` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_change_request` tinyint(1) NOT NULL,
`create_change_request_template` tinyint(1) NOT NULL,
`view_all_change_request` tinyint(1) NOT NULL,
`created_at` datetime(6) NOT NULL,
`deleted_at` datetime(6) DEFAULT NULL,
`company_pivot_id` varchar(255) NOT NULL,
`group_pivots_id` varchar(255) NOT NULL,
`id_number_id` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `allowed_company_company_pivot_id_35c7dec7_fk_companies_code` (`company_pivot_id`),
KEY `allowed_company_group_pivots_id_3b2e331c_fk_departments_code` (`group_pivots_id`),
KEY `allowed_company_id_number_id_7c5c7fc8_fk_auth_user_code` (`id_number_id`),
CONSTRAINT `allowed_company_company_pivot_id_35c7dec7_fk_companies_code` FOREIGN KEY (`company_pivot_id`) REFERENCES `companies` (`code`),
CONSTRAINT `allowed_company_group_pivots_id_3b2e331c_fk_departments_code` FOREIGN KEY (`group_pivots_id`) REFERENCES `departments` (`code`),
CONSTRAINT `allowed_company_id_number_id_7c5c7fc8_fk_auth_user_code` FOREIGN KEY (`id_number_id`) REFERENCES `auth_user` (`code`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8;
-- Dumping data for table rms_db.allowed_company: ~1 rows (approximately)
DELETE FROM `allowed_company`;
/*!40000 ALTER TABLE `allowed_company` DISABLE KEYS */;
INSERT INTO `allowed_company` (`id`, `create_change_request`, `create_change_request_template`, `view_all_change_request`, `created_at`, `deleted_at`, `company_pivot_id`, `group_pivots_id`, `id_number_id`) VALUES
(24, 1, 1, 1, '2019-09-18 15:01:40.721221', NULL, 'COMPANY-20190917-0000001', 'DEPARTMENT-20190917-0000001', 'USER-20190917-0000001'),
(25, 1, 1, 1, '2019-09-18 15:01:40.745227', NULL, 'COMPANY-20190917-0000001', 'DEPARTMENT-20190917-0000001', 'USER-20190917-0000001');
/*!40000 ALTER TABLE `allowed_company` ENABLE KEYS */;
-- Dumping structure for table rms_db.applications
CREATE TABLE IF NOT EXISTS `applications` (
`id` int(11) NOT NULL AUTO_INCREMENT,
......@@ -72,7 +100,7 @@ CREATE TABLE IF NOT EXISTS `authtoken_token` (
DELETE FROM `authtoken_token`;
/*!40000 ALTER TABLE `authtoken_token` DISABLE KEYS */;
INSERT INTO `authtoken_token` (`key`, `created`, `user_id`) VALUES
('c31a15d4793d2c8bf82230446cce9924c055f9c7', '2019-09-17 16:29:01.409868', 1);
('b7b77207fd444444355e6abf3883c11771d1a48e', '2019-09-18 15:15:10.827183', 1);
/*!40000 ALTER TABLE `authtoken_token` ENABLE KEYS */;
-- Dumping structure for table rms_db.auth_access_token
......@@ -133,9 +161,9 @@ CREATE TABLE IF NOT EXISTS `auth_permission` (
PRIMARY KEY (`id`),
UNIQUE KEY `auth_permission_content_type_id_codename_01ab375a_uniq` (`content_type_id`,`codename`),
CONSTRAINT `auth_permission_content_type_id_2f476e4b_fk_django_co` FOREIGN KEY (`content_type_id`) REFERENCES `django_content_type` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8;
-- Dumping data for table rms_db.auth_permission: ~132 rows (approximately)
-- Dumping data for table rms_db.auth_permission: ~136 rows (approximately)
DELETE FROM `auth_permission`;
/*!40000 ALTER TABLE `auth_permission` DISABLE KEYS */;
INSERT INTO `auth_permission` (`id`, `name`, `content_type_id`, `codename`) VALUES
......@@ -270,7 +298,11 @@ INSERT INTO `auth_permission` (`id`, `name`, `content_type_id`, `codename`) VALU
(129, 'Can add auth token', 33, 'add_authtoken'),
(130, 'Can change auth token', 33, 'change_authtoken'),
(131, 'Can delete auth token', 33, 'delete_authtoken'),
(132, 'Can view auth token', 33, 'view_authtoken');
(132, 'Can view auth token', 33, 'view_authtoken'),
(133, 'Can add allowed company', 34, 'add_allowedcompany'),
(134, 'Can change allowed company', 34, 'change_allowedcompany'),
(135, 'Can delete allowed company', 34, 'delete_allowedcompany'),
(136, 'Can view allowed company', 34, 'view_allowedcompany');
/*!40000 ALTER TABLE `auth_permission` ENABLE KEYS */;
-- Dumping structure for table rms_db.auth_user
......@@ -321,11 +353,15 @@ CREATE TABLE IF NOT EXISTS `auth_user_application` (
KEY `auth_user_application_application_id_5c17d611_fk_applications_id` (`application_id`),
CONSTRAINT `auth_user_application_application_id_5c17d611_fk_applications_id` FOREIGN KEY (`application_id`) REFERENCES `applications` (`id`),
CONSTRAINT `auth_user_application_user_id_7b07e391_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
-- Dumping data for table rms_db.auth_user_application: ~0 rows (approximately)
DELETE FROM `auth_user_application`;
/*!40000 ALTER TABLE `auth_user_application` DISABLE KEYS */;
INSERT INTO `auth_user_application` (`id`, `user_id`, `application_id`) VALUES
(17, 1, 1),
(18, 1, 2),
(19, 1, 3);
/*!40000 ALTER TABLE `auth_user_application` ENABLE KEYS */;
-- Dumping structure for table rms_db.auth_user_groups
......@@ -396,6 +432,7 @@ CREATE TABLE IF NOT EXISTS `change_request_form_approvers` (
`form_code_id` varchar(255) NOT NULL,
`tmp_approver_id` varchar(255) DEFAULT NULL,
`user_id` varchar(255) DEFAULT NULL,
`action_date` datetime(6) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`),
KEY `change_request_form__form_code_id_5dfe5c56_fk_change_re` (`form_code_id`),
......@@ -759,9 +796,9 @@ CREATE TABLE IF NOT EXISTS `django_content_type` (
`model` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `django_content_type_app_label_model_76bd3d3b_uniq` (`app_label`,`model`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8;
-- Dumping data for table rms_db.django_content_type: ~33 rows (approximately)
-- Dumping data for table rms_db.django_content_type: ~34 rows (approximately)
DELETE FROM `django_content_type`;
/*!40000 ALTER TABLE `django_content_type` DISABLE KEYS */;
INSERT INTO `django_content_type` (`id`, `app_label`, `model`) VALUES
......@@ -770,6 +807,7 @@ INSERT INTO `django_content_type` (`id`, `app_label`, `model`) VALUES
(2, 'auth', 'permission'),
(6, 'authtoken', 'token'),
(4, 'contenttypes', 'contenttype'),
(34, 'entities', 'allowedcompany'),
(8, 'entities', 'application'),
(9, 'entities', 'attachment'),
(33, 'entities', 'authtoken'),
......@@ -807,9 +845,9 @@ CREATE TABLE IF NOT EXISTS `django_migrations` (
`name` varchar(255) NOT NULL,
`applied` datetime(6) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;
-- Dumping data for table rms_db.django_migrations: ~20 rows (approximately)
-- Dumping data for table rms_db.django_migrations: ~22 rows (approximately)
DELETE FROM `django_migrations`;
/*!40000 ALTER TABLE `django_migrations` DISABLE KEYS */;
INSERT INTO `django_migrations` (`id`, `app`, `name`, `applied`) VALUES
......@@ -832,7 +870,10 @@ INSERT INTO `django_migrations` (`id`, `app`, `name`, `applied`) VALUES
(17, 'admin', '0003_logentry_add_action_flag_choices', '2019-09-17 15:32:32.738930'),
(18, 'authtoken', '0001_initial', '2019-09-17 15:32:32.936422'),
(19, 'authtoken', '0002_auto_20160226_1747', '2019-09-17 15:32:34.046297'),
(20, 'sessions', '0001_initial', '2019-09-17 15:32:34.204229');
(20, 'sessions', '0001_initial', '2019-09-17 15:32:34.204229'),
(21, 'entities', '0002_auto_20190917_1716', '2019-09-17 17:39:34.818932'),
(23, 'entities', '0003_allowedcompany', '2019-09-17 18:02:56.850725'),
(24, 'entities', '0004_auto_20190918_1104', '2019-09-18 11:05:03.287159');
/*!40000 ALTER TABLE `django_migrations` ENABLE KEYS */;
-- Dumping structure for table rms_db.django_session
......@@ -940,20 +981,12 @@ CREATE TABLE IF NOT EXISTS `notifications` (
`is_read` tinyint(1) DEFAULT NULL,
`created` datetime(6) NOT NULL,
`modified` datetime(6) NOT NULL,
`account_no_id` varchar(255) NOT NULL,
`app_id` varchar(255) NOT NULL,
`form_code_id` varchar(255) NOT NULL,
`sender_account_no_id` varchar(255) NOT NULL,
`account_no` varchar(255) DEFAULT NULL,
`app` varchar(255) DEFAULT NULL,
`form_code` varchar(255) DEFAULT NULL,
`sender_account_no` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`),
KEY `notifications_account_no_id_ff388d8f_fk_auth_user_code` (`account_no_id`),
KEY `notifications_app_id_1b485e03_fk_applications_code` (`app_id`),
KEY `notifications_form_code_id_a2f6cde7_fk_change_re` (`form_code_id`),
KEY `notifications_sender_account_no_id_8d711c98_fk_auth_user_code` (`sender_account_no_id`),
CONSTRAINT `notifications_account_no_id_ff388d8f_fk_auth_user_code` FOREIGN KEY (`account_no_id`) REFERENCES `auth_user` (`code`),
CONSTRAINT `notifications_app_id_1b485e03_fk_applications_code` FOREIGN KEY (`app_id`) REFERENCES `applications` (`code`),
CONSTRAINT `notifications_form_code_id_a2f6cde7_fk_change_re` FOREIGN KEY (`form_code_id`) REFERENCES `change_request_form_headers` (`form_code`),
CONSTRAINT `notifications_sender_account_no_id_8d711c98_fk_auth_user_code` FOREIGN KEY (`sender_account_no_id`) REFERENCES `auth_user` (`code`)
UNIQUE KEY `code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Dumping data for table rms_db.notifications: ~0 rows (approximately)
......
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