diff --git a/drfautoapi/drfautoapi.py b/drfautoapi/drfautoapi.py index cca4eacdb..ff9153da7 100644 --- a/drfautoapi/drfautoapi.py +++ b/drfautoapi/drfautoapi.py @@ -152,6 +152,15 @@ class ApiViewSetConstrutor(): def update(cls, other): cls._built_sets.update(other._built_sets) + @classmethod + def import_modules(cls, modules): + for m in modules: + importlib.import_module(m) + #components = inspect.getmembers(components_ref) + # for key, vclass in components: + # if type(vclass) == cls: + # cls.update(vclass) + @classmethod def build_class(cls, apps): @@ -160,7 +169,7 @@ class ApiViewSetConstrutor(): serializers_classes = {} filters_classes = {} - global_serializer_class = rest_serializers.ModelSerializer + global_serializer_mixin = rest_serializers.ModelSerializer global_filter_class = ApiFilterSetMixin try: @@ -185,14 +194,14 @@ class ApiViewSetConstrutor(): filters_classes )} - if 'GLOBAL_SERIALIZER_CLASS' in DRFAUTOAPI: - cs = DRFAUTOAPI['GLOBAL_SERIALIZER_CLASS'].split('.') + if 'GLOBAL_SERIALIZER_MIXIN' in DRFAUTOAPI: + cs = DRFAUTOAPI['GLOBAL_SERIALIZER_MIXIN'].split('.') module = importlib.import_module( '.'.join(cs[0:-1])) - global_serializer_class = getattr(module, cs[-1]) + global_serializer_mixin = getattr(module, cs[-1]) - if 'GLOBAL_FILTERSET_CLASS' in DRFAUTOAPI: - cs = DRFAUTOAPI['GLOBAL_FILTERSET_CLASS'].split('.') + if 'GLOBAL_FILTERSET_MIXIN' in DRFAUTOAPI: + cs = DRFAUTOAPI['GLOBAL_FILTERSET_MIXIN'].split('.') m = importlib.import_module('.'.join(cs[0:-1])) global_filter_class = getattr(m, cs[-1]) @@ -206,7 +215,7 @@ class ApiViewSetConstrutor(): serializer_name = f'{object_name}Serializer' _serializer_class = serializers_classes.get( - serializer_name, global_serializer_class) + serializer_name, global_serializer_mixin) filter_name = f'{object_name}FilterSet' _filterset_class = filters_classes.get( diff --git a/sapl/api/views.py b/sapl/api/views.py index 9999af462..a9c0686e8 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -8,17 +8,6 @@ from rest_framework.response import Response from rest_framework.views import APIView from drfautoapi.drfautoapi import ApiViewSetConstrutor -from sapl.api.views_audiencia import AudienciaApiViewSetConstrutor -from sapl.api.views_base import BaseApiViewSetConstrutor -from sapl.api.views_comissoes import ComissoesApiViewSetConstrutor -from sapl.api.views_compilacao import CompilacaoApiViewSetConstrutor -from sapl.api.views_materia import MateriaApiViewSetConstrutor -from sapl.api.views_norma import NormaApiViewSetConstrutor -from sapl.api.views_painel import PainelApiViewSetConstrutor -from sapl.api.views_parlamentares import ParlamentaresApiViewSetConstrutor -from sapl.api.views_protocoloadm import ProtocoloAdmApiViewSetConstrutor -from sapl.api.views_sessao import SessaoApiViewSetConstrutor - logger = logging.getLogger(__name__) @@ -47,16 +36,18 @@ class AppVersionView(APIView): SaplApiViewSetConstrutor = ApiViewSetConstrutor -SaplApiViewSetConstrutor.update(AudienciaApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(BaseApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(ComissoesApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(CompilacaoApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(MateriaApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(NormaApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(PainelApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(ParlamentaresApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(ProtocoloAdmApiViewSetConstrutor) -SaplApiViewSetConstrutor.update(SessaoApiViewSetConstrutor) +SaplApiViewSetConstrutor.import_modules([ + 'sapl.api.views_audiencia', + 'sapl.api.views_base', + 'sapl.api.views_comissoes', + 'sapl.api.views_compilacao', + 'sapl.api.views_materia', + 'sapl.api.views_norma', + 'sapl.api.views_painel', + 'sapl.api.views_parlamentares', + 'sapl.api.views_protocoloadm', + 'sapl.api.views_sessao', +]) """