django_socio_grpc.grpc_actions.utils

Module Contents

Functions

get_serializer_class

get_serializer_base_name

get_lookup_field_from_serializer

Find the field associated to the lookup field serializer_instance: instance of the serializer used in this service where the lookup field should be present service_instance: the service instance itself where we can introspect for lookupfield

get_partial_update_request_from_serializer_class

This metaclass exists so we can set the PARTIAL_UPDATE_FIELD_NAME variable as an attribute name of PartialUpdateMetaClass. This can be replaced by just declaring in your serializer: _partial_update_fields = serializers.ListField(child=serializers.CharField(), write_only=True) but this would not be dynamic if a constant changes or if we want it to be configurable in settings in the future. This metaclass should inherit from DRF SerializerMetaclass as serializer has it’s own metaclass to add _declared_fields attribute Using PartialUpdateRequest.setattr is not enough as _declared_fields is done in metaclass so all fields should be declared before

get_partial_update_request_from_service

API

django_socio_grpc.grpc_actions.utils.get_serializer_class(service: django_socio_grpc.generics.GenericService, action: str | None = None)
django_socio_grpc.grpc_actions.utils.get_serializer_base_name(service: django_socio_grpc.generics.GenericService, action: str | None = None)
django_socio_grpc.grpc_actions.utils.get_lookup_field_from_serializer(serializer_instance, service_instance)

Find the field associated to the lookup field serializer_instance: instance of the serializer used in this service where the lookup field should be present service_instance: the service instance itself where we can introspect for lookupfield

return: iterable: [str, <drf.serializers.Field>]

django_socio_grpc.grpc_actions.utils.get_partial_update_request_from_serializer_class(serializer_class)

This metaclass exists so we can set the PARTIAL_UPDATE_FIELD_NAME variable as an attribute name of PartialUpdateMetaClass. This can be replaced by just declaring in your serializer: _partial_update_fields = serializers.ListField(child=serializers.CharField(), write_only=True) but this would not be dynamic if a constant changes or if we want it to be configurable in settings in the future. This metaclass should inherit from DRF SerializerMetaclass as serializer has it’s own metaclass to add _declared_fields attribute Using PartialUpdateRequest.setattr is not enough as _declared_fields is done in metaclass so all fields should be declared before

django_socio_grpc.grpc_actions.utils.get_partial_update_request_from_service(service)