from django.shortcuts import render

from rest_framework.viewsets import ModelViewSet
from .models import TestOrg,TestOrgNotice
from utils.queryset import get_child_queryset2
from .serializers import TestOrgSerializer,TestOrgNoticeSerializer,TestOrgNoticListSerializer
from apps.system.permission_data import RbacFilterSet
from apps.system.mixins import CreateUpdateCustomMixin, OptimizationMixin
# Create your views here.

class TestOrgViewSet(CreateUpdateCustomMixin, OptimizationMixin, ModelViewSet):
    perms_map = {'get': '*', 'post': 'TestOrg_create',
                 'put': 'TestOrg_update', 'delete': 'TestOrg_delete'}
    queryset = TestOrg.objects
    serializer_class = TestOrgSerializer
    search_fields = ['name', 'code']
    ordering = ['-create_time']
class TestOrgNoticeViewSet(CreateUpdateCustomMixin, OptimizationMixin, ModelViewSet):
    perms_map = {'get': '*', 'post': 'TestOrgNotice_create',
                 'put': 'TestOrgNotice_update', 'delete': 'TestOrgNotice_delete'}
    queryset = TestOrgNotice.objects
    serializer_class = TestOrgNoticeSerializer
    search_fields = ['name']
    ordering = ['-create_time']
    def get_serializer_class(self):
        # 根据请求类型动态变更serializer
        if self.action == 'list':
            return TestOrgNoticListSerializer
        return TestOrgNoticeSerializer
   
