class AddonBrowseVersionSerializer(MinimalVersionSerializerWithChannel): validation_url_json = serializers.SerializerMethodField() validation_url = serializers.SerializerMethodField() has_been_validated = serializers.SerializerMethodField() file = FileEntriesSerializer(source='current_file') addon = SimpleAddonSerializer() class Meta: model = Version fields = ( # Bare minimum fields we need from parent... 'id', 'channel', 'reviewed', 'version', # Plus our custom ones. 'addon', 'file', 'has_been_validated', 'validation_url', 'validation_url_json' ) def get_validation_url_json(self, obj): return absolutify(reverse('devhub.json_file_validation', args=[ obj.addon.slug, obj.current_file.id ])) def get_validation_url(self, obj): return absolutify(reverse('devhub.file_validation', args=[ obj.addon.slug, obj.current_file.id ])) def get_has_been_validated(self, obj): return obj.current_file.has_been_validated
class AddonBrowseVersionSerializer(VersionSerializer): validation_url_json = serializers.SerializerMethodField() validation_url = serializers.SerializerMethodField() has_been_validated = serializers.SerializerMethodField() file = FileEntriesSerializer(source='current_file') addon = SimpleAddonSerializer() class Meta: model = Version # Doesn't contain `files` from VersionSerializer fields = ('id', 'channel', 'compatibility', 'edit_url', 'is_strict_compatibility_enabled', 'license', 'release_notes', 'reviewed', 'version', # Our custom fields 'file', 'validation_url', 'validation_url_json', 'has_been_validated', 'addon') def get_validation_url_json(self, obj): return absolutify(reverse('devhub.json_file_validation', args=[ obj.addon.slug, obj.current_file.id ])) def get_validation_url(self, obj): return absolutify(reverse('devhub.file_validation', args=[ obj.addon.slug, obj.current_file.id ])) def get_has_been_validated(self, obj): return obj.current_file.has_been_validated
class AddonBrowseVersionSerializer(AddonBrowseVersionSerializerFileOnly): validation_url_json = serializers.SerializerMethodField() validation_url = serializers.SerializerMethodField() has_been_validated = serializers.SerializerMethodField() addon = SimpleAddonSerializer() class Meta: model = Version fields = ( 'id', 'channel', 'reviewed', 'version', 'addon', 'file', 'has_been_validated', 'validation_url', 'validation_url_json' ) def get_validation_url_json(self, obj): return absolutify(reverse('devhub.json_file_validation', args=[ obj.addon.slug, obj.current_file.id ])) def get_validation_url(self, obj): return absolutify(reverse('devhub.file_validation', args=[ obj.addon.slug, obj.current_file.id ])) def get_has_been_validated(self, obj): return obj.current_file.has_been_validated
class AddonBrowseVersionSerializer( AddonBrowseVersionSerializerFileOnly, FileEntriesMixin ): validation_url_json = serializers.SerializerMethodField() validation_url = serializers.SerializerMethodField() has_been_validated = serializers.SerializerMethodField() file_entries = serializers.SerializerMethodField() addon = SimpleAddonSerializer() class Meta: model = Version fields = ( 'id', 'channel', 'reviewed', 'version', 'addon', 'file', 'has_been_validated', 'validation_url', 'validation_url_json', 'file_entries', ) def get_file_entries(self, obj): entries = self._get_entries() return self._trim_entries(entries) def _trim_entries(self, entries): result = OrderedDict() for value in entries.values(): result[value['path']] = self._trim_entry(value) return result def _trim_entry(self, entry): return { key: entry[key] for key in ('depth', 'filename', 'mime_category', 'path', 'status') if key in entry } def get_validation_url_json(self, obj): return absolutify( drf_reverse( 'reviewers-addon-json-file-validation', request=self.context.get('request'), args=[obj.addon.pk, obj.current_file.id], ) ) def get_validation_url(self, obj): return absolutify( reverse('devhub.file_validation', args=[obj.addon.pk, obj.current_file.id]) ) def get_has_been_validated(self, obj): return obj.current_file.has_been_validated