Multi-platform: support multiple files per version #201
@ -151,6 +151,31 @@ class FiltersTest(APITestCase):
|
|||||||
).json()
|
).json()
|
||||||
self.assertEqual(len(json['data']), 1)
|
self.assertEqual(len(json['data']), 1)
|
||||||
|
|
||||||
|
def test_platform_filter_same_extension(self):
|
||||||
|
version = create_approved_version(
|
||||||
|
metadata__platforms=['linux-x64'],
|
||||||
|
metadata__version='1.0.0',
|
||||||
|
)
|
||||||
|
extension = version.extension
|
||||||
|
version = create_approved_version(
|
||||||
|
extension=extension,
|
||||||
|
metadata__platforms=['windows-x64'],
|
||||||
|
metadata__version='1.0.1',
|
||||||
|
)
|
||||||
|
|
||||||
|
url = reverse('extensions:api')
|
||||||
|
json = self.client.get(
|
||||||
|
url + '?platform=linux-x64',
|
||||||
|
HTTP_ACCEPT='application/json',
|
||||||
|
).json()
|
||||||
|
self.assertEqual(len(json['data']), 1)
|
||||||
|
|
||||||
|
json = self.client.get(
|
||||||
|
url + '?platform=windows-x64',
|
||||||
|
HTTP_ACCEPT='application/json',
|
||||||
|
).json()
|
||||||
|
self.assertEqual(len(json['data']), 1)
|
||||||
|
|
||||||
def test_blender_version_filter_latest_not_max_version(self):
|
def test_blender_version_filter_latest_not_max_version(self):
|
||||||
version = create_approved_version(metadata__blender_version_min='4.0.1')
|
version = create_approved_version(metadata__blender_version_min='4.0.1')
|
||||||
date_created = version.date_created
|
date_created = version.date_created
|
||||||
|
@ -54,14 +54,16 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
|
|||||||
except Platform.DoesNotExist:
|
except Platform.DoesNotExist:
|
||||||
self.platform = self.UNKNOWN_PLATFORM
|
self.platform = self.UNKNOWN_PLATFORM
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def find_matching_file_and_version(self, instance):
|
||||||
matching_file = None
|
|
||||||
matching_version = None
|
|
||||||
# avoid triggering additional db queries, reuse the prefetched queryset
|
# avoid triggering additional db queries, reuse the prefetched queryset
|
||||||
versions = [v for v in instance.versions.all() if v.is_listed]
|
versions = sorted(
|
||||||
|
[v for v in instance.versions.all() if v.is_listed],
|
||||||
|
key=lambda v: v.date_created,
|
||||||
|
reverse=True,
|
||||||
|
)
|
||||||
if not versions:
|
if not versions:
|
||||||
return None
|
return (None, None)
|
||||||
versions = sorted(versions, key=lambda v: v.date_created, reverse=True)
|
|
||||||
for v in versions:
|
for v in versions:
|
||||||
if self.blender_version and not is_in_version_range(
|
if self.blender_version and not is_in_version_range(
|
||||||
self.blender_version,
|
self.blender_version,
|
||||||
@ -75,14 +77,15 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
|
|||||||
platforms = file.platforms()
|
platforms = file.platforms()
|
||||||
if self.platform and (platforms and self.platform not in platforms):
|
if self.platform and (platforms and self.platform not in platforms):
|
||||||
continue
|
continue
|
||||||
Oleg-Komarov marked this conversation as resolved
Outdated
|
|||||||
# TODO? return all matching files (when no self.platform is passed)?
|
return (file, v)
|
||||||
Oleg-Komarov marked this conversation as resolved
Outdated
Anna Sirota
commented
needs another needs another `break` here
|
|||||||
matching_file = file
|
|
||||||
matching_version = v
|
|
||||||
break
|
|
||||||
|
|
||||||
|
return (None, None)
|
||||||
|
|
||||||
|
def to_representation(self, instance):
|
||||||
|
# TODO? return all matching files (when no self.platform is passed)?
|
||||||
|
matching_file, matching_version = self.find_matching_file_and_version(instance)
|
||||||
if not matching_file:
|
if not matching_file:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'id': instance.extension_id,
|
'id': instance.extension_id,
|
||||||
'schema_version': matching_version.schema_version,
|
'schema_version': matching_version.schema_version,
|
||||||
@ -110,7 +113,6 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
|
|||||||
# TODO: handle copyright
|
# TODO: handle copyright
|
||||||
'tags': [str(tag) for tag in matching_version.tags.all()],
|
'tags': [str(tag) for tag in matching_version.tags.all()],
|
||||||
}
|
}
|
||||||
|
|
||||||
return clean_json_dictionary_from_optional_fields(data)
|
return clean_json_dictionary_from_optional_fields(data)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user
this looks shared with the logic in
public
view that selects which file to pick from storage, and should probable become a utility or method somewhere.