|
@ -22,6 +22,7 @@ from rest_framework.viewsets import ModelViewSet |
|
|
|
|
|
|
|
|
from sapl.api.core.filters import SaplFilterSetMixin |
|
|
from sapl.api.core.filters import SaplFilterSetMixin |
|
|
from sapl.api.permissions import SaplModelPermissions |
|
|
from sapl.api.permissions import SaplModelPermissions |
|
|
|
|
|
from sapl.base.models import Metadata |
|
|
|
|
|
|
|
|
# ATENÇÃO: MUDANÇAS NO CORE DEVEM SER REALIZADAS COM |
|
|
# ATENÇÃO: MUDANÇAS NO CORE DEVEM SER REALIZADAS COM |
|
|
# EXTREMA CAUTELA |
|
|
# EXTREMA CAUTELA |
|
@ -100,6 +101,7 @@ class SaplApiViewSetConstrutor(): |
|
|
# criada a classe sapl.api.core.serializers.{model}Serializer |
|
|
# criada a classe sapl.api.core.serializers.{model}Serializer |
|
|
class SaplSerializer(_serializer_class): |
|
|
class SaplSerializer(_serializer_class): |
|
|
__str__ = SerializerMethodField() |
|
|
__str__ = SerializerMethodField() |
|
|
|
|
|
metadata = SerializerMethodField() |
|
|
|
|
|
|
|
|
class Meta(_meta_serializer): |
|
|
class Meta(_meta_serializer): |
|
|
if not hasattr(_meta_serializer, 'ref_name'): |
|
|
if not hasattr(_meta_serializer, 'ref_name'): |
|
@ -114,14 +116,26 @@ class SaplApiViewSetConstrutor(): |
|
|
if not hasattr(_meta_serializer, 'fields'): |
|
|
if not hasattr(_meta_serializer, 'fields'): |
|
|
fields = '__all__' |
|
|
fields = '__all__' |
|
|
elif _meta_serializer.fields != '__all__': |
|
|
elif _meta_serializer.fields != '__all__': |
|
|
fields = list( |
|
|
fields = list(_meta_serializer.fields) + [ |
|
|
_meta_serializer.fields) + ['__str__', ] |
|
|
'__str__', 'metadata'] |
|
|
else: |
|
|
else: |
|
|
fields = _meta_serializer.fields |
|
|
fields = _meta_serializer.fields |
|
|
|
|
|
|
|
|
def get___str__(self, obj) -> str: |
|
|
def get___str__(self, obj) -> str: |
|
|
return str(obj) |
|
|
return str(obj) |
|
|
|
|
|
|
|
|
|
|
|
def get_metadata(self, obj): |
|
|
|
|
|
try: |
|
|
|
|
|
metadata = Metadata.objects.get( |
|
|
|
|
|
content_type=ContentType.objects.get_for_model( |
|
|
|
|
|
obj._meta.model), |
|
|
|
|
|
object_id=obj.id |
|
|
|
|
|
).metadata |
|
|
|
|
|
except: |
|
|
|
|
|
metadata = {} |
|
|
|
|
|
finally: |
|
|
|
|
|
return metadata |
|
|
|
|
|
|
|
|
_meta_filterset = object if not hasattr( |
|
|
_meta_filterset = object if not hasattr( |
|
|
_filterset_class, 'Meta') else _filterset_class.Meta |
|
|
_filterset_class, 'Meta') else _filterset_class.Meta |
|
|
|
|
|
|
|
@ -162,6 +176,7 @@ class SaplApiViewSetConstrutor(): |
|
|
|
|
|
|
|
|
return cls |
|
|
return cls |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
1. Constroi uma rest_framework.viewsets.ModelViewSet para |
|
|
1. Constroi uma rest_framework.viewsets.ModelViewSet para |
|
|
todos os models de todas as apps do sapl |
|
|
todos os models de todas as apps do sapl |
|
|