def validate(self, data): if utils.is_probable_url(data.get('criteria')): data['criteria_url'] = data.pop('criteria') elif not isinstance(data.get('criteria'), (str, unicode)): raise serializers.ValidationError( "Provided criteria text could not be properly processed as URL or plain text." ) else: data['criteria_text'] = data.pop('criteria') return data
def validate(self, data): if 'criteria' in data: if 'criteria_url' in data or 'criteria_text' in data: raise serializers.ValidationError( "The criteria field is mutually-exclusive with the criteria_url and criteria_text fields" ) if utils.is_probable_url(data.get('criteria')): data['criteria_url'] = data.pop('criteria') elif not isinstance(data.get('criteria'), (str, unicode)): raise serializers.ValidationError( "Provided criteria text could not be properly processed as URL or plain text." ) else: data['criteria_text'] = data.pop('criteria') else: if data.get('criteria_text', None) is None and data.get('criteria_url', None) is None: raise serializers.ValidationError( "One or both of the criteria_text and criteria_url fields must be provided" ) return data