38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
from .introspection import introspect_standard_fields, STANDARD_OBJECT_REGISTRY
|
|
|
|
|
|
class StandardObjectFieldsView(APIView):
|
|
permission_classes = [IsAuthenticated]
|
|
|
|
def get(self, request, entity_name=None):
|
|
if not entity_name:
|
|
return Response({"error": "entity_name parameter is required"}, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
# Case-insensitive lookup against registry
|
|
matched_name = None
|
|
for key in STANDARD_OBJECT_REGISTRY:
|
|
if key.lower() == entity_name.lower():
|
|
matched_name = key
|
|
break
|
|
|
|
if not matched_name:
|
|
return Response(
|
|
{"error": f"Standard object '{entity_name}' not found. Supported objects: {list(STANDARD_OBJECT_REGISTRY.keys())}"},
|
|
status=status.HTTP_404_NOT_FOUND
|
|
)
|
|
|
|
try:
|
|
fields = introspect_standard_fields(matched_name)
|
|
return Response({
|
|
"entity_name": matched_name,
|
|
"label": matched_name,
|
|
"is_custom": False,
|
|
"standard_fields": fields
|
|
}, status=status.HTTP_200_OK)
|
|
except Exception as e:
|
|
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|