Multi-platform: support multiple files per version #201
@ -679,7 +679,7 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def can_upload_more_files(self):
|
def can_upload_more_files(self):
|
||||||
return len(self.get_available_platforms()) > 0
|
return len(self.get_remaining_platforms()) > 0
|
||||||
|
|
||||||
def add_file(self, file: File):
|
def add_file(self, file: File):
|
||||||
self.files.add(file)
|
self.files.add(file)
|
||||||
@ -706,7 +706,7 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
|||||||
for p in to_delete:
|
for p in to_delete:
|
||||||
self.platforms.remove(Platform.objects.get(slug=p))
|
self.platforms.remove(Platform.objects.get(slug=p))
|
||||||
|
|
||||||
def get_available_platforms(self):
|
def get_remaining_platforms(self):
|
||||||
all_platforms = set(p.slug for p in Platform.objects.all())
|
all_platforms = set(p.slug for p in Platform.objects.all())
|
||||||
for file in self.files.all():
|
for file in self.files.all():
|
||||||
platforms = file.platforms()
|
platforms = file.platforms()
|
||||||
|
@ -197,9 +197,9 @@ class ExtensionVersionManifestValidator:
|
|||||||
|
|
||||||
# check for platforms
|
# check for platforms
|
||||||
# TODO test coverage
|
# TODO test coverage
|
||||||
available_platforms = version.get_available_platforms()
|
remaining_platforms = version.get_remaining_platforms()
|
||||||
if platforms := files.models.File.parse_platforms_from_manifest(manifest):
|
if platforms := files.models.File.parse_platforms_from_manifest(manifest):
|
||||||
if diff := set(platforms) - available_platforms:
|
if diff := set(platforms) - remaining_platforms:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
{
|
{
|
||||||
'source': [f'{version} already has files for {", ".join(diff)}'],
|
'source': [f'{version} already has files for {", ".join(diff)}'],
|
||||||
@ -207,12 +207,12 @@ class ExtensionVersionManifestValidator:
|
|||||||
code='invalid',
|
code='invalid',
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if available_platforms:
|
if remaining_platforms:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
{
|
{
|
||||||
'source': [
|
'source': [
|
||||||
f'File upload for {version} is allowed only for remaining platforms: '
|
f'File upload for {version} is allowed only for remaining platforms: '
|
||||||
f'{", ".join(available_platforms)}'
|
f'{", ".join(remaining_platforms)}'
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
code='invalid',
|
code='invalid',
|
||||||
|
Loading…
Reference in New Issue
Block a user