@@ -0,0 +1,3046 @@
+from rest_framework import status, viewsets%0Afrom rest_framework.exceptions import ValidationError%0Afrom rest_framework.response import Response%0Afrom rest_framework.permissions import AllowAny%0A%0A%0Aclass BaseViewSet(viewsets.ModelViewSet):%0A    true = True%0A    false = False%0A    none = None%0A%0A    authentication_classes = AllowAny,%0A%0A    def list(self, request, *args, **kwargs):%0A        queryset = self.filter_queryset(self.get_queryset())%0A        page = self.paginate_queryset(queryset)%0A%0A        if page is not self.none:%0A            serializer = self.get_serializer(page, many=self.true)%0A            return self.get_paginated_response(serializer.data)%0A%0A        serializer = self.get_serializer(queryset, many=self.true)%0A        return Response(data=serializer.data, status=status.HTTP_200_OK)%0A%0A    def retrieve(self, request, *args, **kwargs):%0A        instance = self.get_object()%0A        serializer = self.get_serializer(instance)%0A%0A        return Response(data=serializer.data, status=status.HTTP_200_OK)%0A%0A    def create(self, request, *args, **kwargs):%0A        data = request.data%0A        serializer = self.get_serializer(data=data)%0A%0A        try:%0A            serializer.is_valid(raise_exception=self.true)%0A        except ValidationError as exception:%0A            invalid_fields = list(exception.detail.keys())%0A            message = %7B'invalid_input_fields': invalid_fields%7D%0A            return Response(data=message, status=status.HTTP_400_BAD_REQUEST)%0A%0A        try:%0A            instance_to_create = serializer.create(validated_data=data)%0A        except Exception as exception:%0A            message = exception.message%0A            return Response(data=message, status=status.HTTP_400_BAD_REQUEST)%0A%0A        serialized_instance = self.get_serializer(instance_to_create).data%0A        return Response(%0A            data=serialized_instance, status=status.HTTP_201_CREATED)%0A%0A    def update(self, request, *args, **kwargs):%0A        instance_to_update = self.get_object()%0A%0A        data = request.data%0A%0A        try:%0A            updated_object = self.get_serializer().update(%0A                instance=instance_to_update, validated_data=data)%0A        except ValidationError as exception:%0A            invalid_fields = list(exception.detail.keys())%0A            message = %7B'invalid_input_fields': invalid_fields%7D%0A            return Response(data=message, status=status.HTTP_400_BAD_REQUEST)%0A%0A        except ValueError:%0A            return Response(%0A                data=%7B'message': 'Value error'%7D,%0A                status=status.HTTP_400_BAD_REQUEST)%0A%0A        except Exception as exception:%0A            return Response(%0A                data=%7B'message': exception.message%7D,%0A                status=status.HTTP_403_FORBIDDEN)%0A%0A        serialized_instance = self.get_serializer(updated_object).data%0A        return Response(%0A            data=serialized_instance, status=status.HTTP_202_ACCEPTED)%0A%0A    def destroy(self, request, *args, **kwargs):%0A        instance = self.get_object()%0A        self.perform_destroy(instance)%0A        return Response(status=status.HTTP_200_OK)%0A

Create default BaseViewSet for all the common actions