@@ -0,0 +1,1346 @@
+from rest_framework import serializers%0A%0A%0Aclass JobValidator(serializers.Serializer):%0A    %22%22%22%0A    A serializer class for validating and deserializing job data.%0A    Task is included for completeness of documentation of expected fields.%0A    But we will validate the existence of this before we get to this point.%0A    %22%22%22%0A%0A    type = serializers.CharField(required=True)%0A%0A    def validate(self, data):%0A        kwargs = data.copy()%0A        kwargs.pop(%22type%22)%0A        return %7B%0A            %22args%22: (),%0A            %22kwargs%22: kwargs,%0A            %22extra_metadata%22: %7B%7D,%0A        %7D%0A%0A    def run_validation(self, data):%0A        value = super(JobValidator, self).run_validation(data)%0A        if not isinstance(value, dict):%0A            raise TypeError(%22Validator must return a dict.%22)%0A        extra_metadata = value.get(%22extra_metadata%22, %7B%7D)%0A        if extra_metadata is not None and not isinstance(extra_metadata, dict):%0A            raise TypeError(%22'extra_metadata' must be a dict.%22)%0A        if %22user%22 in self.context and self.context%5B%22user%22%5D.is_authenticated():%0A            user = self.context%5B%22user%22%5D%0A            extra_metadata.update(%0A                %7B%0A                    %22started_by%22: user.id,%0A                    %22started_by_username%22: user.username,%0A                %7D%0A            )%0A        value%5B%22extra_metadata%22%5D = extra_metadata%0A        return value%0A

Implement a base job validator using DRF serializers.