Multi-platform: support multiple files per version #201
@ -690,7 +690,7 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
current_platforms = set([p.slug for p in self.platforms.all()])
|
||||
files_platforms = set()
|
||||
for file in self.files.all():
|
||||
if file_platforms := file.platforms():
|
||||
if file_platforms := file.get_platforms():
|
||||
files_platforms.update(file_platforms)
|
||||
else:
|
||||
# we have a cross-platform file - version must not specify platforms
|
||||
@ -709,7 +709,7 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
def get_remaining_platforms(self):
|
||||
all_platforms = set(p.slug for p in Platform.objects.all())
|
||||
for file in self.files.all():
|
||||
platforms = file.platforms()
|
||||
platforms = file.get_platforms()
|
||||
if not platforms:
|
||||
# no platforms means any platform
|
||||
return set()
|
||||
@ -811,7 +811,7 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
]
|
||||
platform2file = {}
|
||||
for file in files:
|
||||
platforms = file.platforms()
|
||||
platforms = file.get_platforms()
|
||||
if not platforms:
|
||||
log.warning(
|
||||
f'data error: Version pk={self.pk} has multiple files, but File pk={file.pk} '
|
||||
@ -832,7 +832,7 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
def get_build_list(self) -> List[dict]:
|
||||
build_list = []
|
||||
for file in self.files.all():
|
||||
platforms = file.platforms() or []
|
||||
platforms = file.get_platforms() or []
|
||||
platform = len(platforms) and platforms[0] or None
|
||||
# if file has multiple platforms, picking the first one should still produce a correct
|
||||
# download_url
|
||||
|
@ -74,7 +74,7 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
|
||||
for file in v.files.all():
|
||||
# empty platforms field matches any platform filter
|
||||
# UNKNOWN_PLATFORM matches only empty platforms field
|
||||
platforms = file.platforms()
|
||||
platforms = file.get_platforms()
|
||||
if self.platform and (platforms and self.platform not in platforms):
|
||||
continue
|
||||
return (file, v)
|
||||
@ -108,7 +108,7 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
|
||||
'maintainer': instance.team and instance.team.name or str(instance.authors.all()[0]),
|
||||
'license': [license_iter.slug for license_iter in matching_version.licenses.all()],
|
||||
'permissions': matching_file.metadata.get('permissions'),
|
||||
# TODO? if listing all version files (see the note above) use matching_file.platforms()
|
||||
# listing all platforms for matching_version, not matching_file (see TODO? above)
|
||||
'platforms': [platform.slug for platform in matching_version.platforms.all()],
|
||||
# TODO: handle copyright
|
||||
'tags': [str(tag) for tag in matching_version.tags.all()],
|
||||
|
@ -74,7 +74,7 @@ def extension_version_platform_download(request, type_slug, slug, version, platf
|
||||
ExtensionDownload.create_from_request(request, object_id=extension_version.extension_id)
|
||||
VersionDownload.create_from_request(request, object_id=extension_version.pk)
|
||||
for file in extension_version.files.all():
|
||||
platforms = file.platforms() or []
|
||||
platforms = file.get_platforms() or []
|
||||
if platform is None or platform in platforms:
|
||||
url = file.source.url
|
||||
return redirect(f'{url}?filename={filename}')
|
||||
|
@ -177,7 +177,7 @@ class File(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
'website': data.get('website'),
|
||||
}
|
||||
|
||||
def platforms(self):
|
||||
def get_platforms(self):
|
||||
return self.parse_platforms_from_manifest(self.metadata)
|
||||
|
||||
@classmethod
|
||||
@ -198,7 +198,7 @@ class File(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
'schema_version': data.get('schema_version'),
|
||||
'licenses': data.get('license'),
|
||||
'permissions': data.get('permissions'),
|
||||
'platforms': self.platforms(),
|
||||
'platforms': self.get_platforms(),
|
||||
'tags': data.get('tags'),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user