WIP: API: add icon_url #122

Closed
Anna Sirota wants to merge 5 commits from api-icon-and-featured-image-url into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 5 additions and 22 deletions
Showing only changes of commit dee031ecd2 - Show all commits

View File

@ -32,16 +32,6 @@ class ExtensionFactory(DjangoModelFactory):
type=FILE_TYPE_CHOICES.IMAGE, type=FILE_TYPE_CHOICES.IMAGE,
size_bytes=1234, 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') support = factory.Faker('url')
website = factory.Faker('url') website = factory.Faker('url')

View File

@ -274,7 +274,6 @@ class SubmitFinaliseTest(TestCase):
extension__slug=file_data['metadata']['id'].replace("_", "-"), extension__slug=file_data['metadata']['id'].replace("_", "-"),
extension__website=None, extension__website=None,
extension__icon=None, extension__icon=None,
extension__featured_image=None,
tagline=file_data['metadata']['tagline'], tagline=file_data['metadata']['tagline'],
version=file_data['metadata']['version'], version=file_data['metadata']['version'],
blender_version_min=file_data['metadata']['blender_version_min'], blender_version_min=file_data['metadata']['blender_version_min'],

View File

@ -73,10 +73,6 @@ class PublicViewsTest(_BaseTestCase):
self.assertEqual( self.assertEqual(
v['icon_url'], 'https://extensions.local:8111/media/images/de/deadbeef.png' 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 return response
def test_home_page_view_api(self): def test_home_page_view_api(self):

View File

@ -5,6 +5,7 @@ from rest_framework import serializers
from rest_framework.views import APIView from rest_framework.views import APIView
from drf_spectacular.utils import OpenApiParameter, extend_schema from drf_spectacular.utils import OpenApiParameter, extend_schema
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.templatetags.static import static
from common.compare import is_in_version_range, version from common.compare import is_in_version_range, version
from extensions.models import Extension from extensions.models import Extension
@ -69,11 +70,10 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
if not matching_version: if not matching_version:
return None 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: if instance.icon:
icon_url = absolutify(instance.icon.source.url) icon_path = instance.icon.source.url
if instance.featured_image:
featured_image_url = absolutify(instance.featured_image.thumbnail_1080p_url)
data = { data = {
'id': instance.extension_id, 'id': instance.extension_id,
'schema_version': matching_version.schema_version, 'schema_version': matching_version.schema_version,
@ -93,8 +93,7 @@ class ListedExtensionsSerializer(serializers.ModelSerializer):
'permissions': [permission.slug for permission in matching_version.permissions.all()], 'permissions': [permission.slug for permission in matching_version.permissions.all()],
# 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()],
'icon_url': icon_url, 'icon_url': absolutify(icon_path),
'featured_image_url': featured_image_url,
} }
return clean_json_dictionary_from_optional_fields(data) return clean_json_dictionary_from_optional_fields(data)
@ -117,7 +116,6 @@ class ExtensionsAPIView(APIView):
qs = ( qs = (
Extension.objects.listed.select_related( Extension.objects.listed.select_related(
'icon', 'icon',
'featured_image',
) )
.prefetch_related( .prefetch_related(
'authors', 'authors',