WIP: API: add icon_url
#122
@ -32,16 +32,6 @@ class ExtensionFactory(DjangoModelFactory):
|
||||
type=FILE_TYPE_CHOICES.IMAGE,
|
||||
size_bytes=1234,
|
||||
)
|
||||
featured_image = factory.SubFactory(
|
||||
'common.tests.factories.files.FileFactory',
|
||||
original_name=factory.Faker('file_name', extension='jpeg'),
|
||||
source='images/fo/foobar.jpeg',
|
||||
original_hash=factory.Faker('lexify', text='hash:??????????????'),
|
||||
hash=factory.Faker('lexify', text='hash:??????????????'),
|
||||
type=FILE_TYPE_CHOICES.IMAGE,
|
||||
size_bytes=4321,
|
||||
metadata={'thumbnails': {'1080p': {'path': 'images/fo/foobar_1920x1080_random7.webp'}}},
|
||||
)
|
||||
support = factory.Faker('url')
|
||||
website = factory.Faker('url')
|
||||
|
||||
|
@ -274,7 +274,6 @@ class SubmitFinaliseTest(TestCase):
|
||||
extension__slug=file_data['metadata']['id'].replace("_", "-"),
|
||||
extension__website=None,
|
||||
extension__icon=None,
|
||||
extension__featured_image=None,
|
||||
tagline=file_data['metadata']['tagline'],
|
||||
version=file_data['metadata']['version'],
|
||||
blender_version_min=file_data['metadata']['blender_version_min'],
|
||||
|
@ -73,10 +73,6 @@ class PublicViewsTest(_BaseTestCase):
|
||||
self.assertEqual(
|
||||
v['icon_url'], 'https://extensions.local:8111/media/images/de/deadbeef.png'
|
||||
)
|
||||
self.assertEqual(
|
||||
v['featured_image_url'],
|
||||
'https://extensions.local:8111/media/images/fo/foobar_1920x1080_random7.webp',
|
||||
)
|
||||
return response
|
||||
|
||||
def test_home_page_view_api(self):
|
||||
|
@ -5,6 +5,7 @@ from rest_framework import serializers
|
||||
from rest_framework.views import APIView
|
||||
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.templatetags.static import static
|
||||
|
||||
from common.compare import is_in_version_range, version
|
||||
from extensions.models import Extension
|
||||
@ -69,11 +70,10 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
|
||||
if not matching_version:
|
||||
return None
|
||||
|
||||
icon_url = featured_image_url = None
|
||||
# Use the same stub image as on the website
|
||||
icon_path = static('common/images/no-icon.png')
|
||||
if instance.icon:
|
||||
icon_url = absolutify(instance.icon.source.url)
|
||||
if instance.featured_image:
|
||||
featured_image_url = absolutify(instance.featured_image.thumbnail_1080p_url)
|
||||
icon_path = instance.icon.source.url
|
||||
data = {
|
||||
'id': instance.extension_id,
|
||||
'schema_version': matching_version.schema_version,
|
||||
@ -93,8 +93,7 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
|
||||
'permissions': [permission.slug for permission in matching_version.permissions.all()],
|
||||
# TODO: handle copyright
|
||||
'tags': [str(tag) for tag in matching_version.tags.all()],
|
||||
'icon_url': icon_url,
|
||||
'featured_image_url': featured_image_url,
|
||||
'icon_url': absolutify(icon_path),
|
||||
}
|
||||
|
||||
return clean_json_dictionary_from_optional_fields(data)
|
||||
@ -117,7 +116,6 @@ class ExtensionsAPIView(APIView):
|
||||
qs = (
|
||||
Extension.objects.listed.select_related(
|
||||
'icon',
|
||||
'featured_image',
|
||||
)
|
||||
.prefetch_related(
|
||||
'authors',
|
||||
|
Loading…
Reference in New Issue
Block a user