Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #292 from WordPress/audioset_thumb
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Oct 11, 2021
2 parents 76bd815 + c12360c commit 65a624f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
18 changes: 18 additions & 0 deletions openverse_api/catalog/api/migrations/0039_audio_set_thumbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.7 on 2021-10-11 15:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0038_filetypes'),
]

operations = [
migrations.AddField(
model_name='audioset',
name='thumbnail',
field=models.URLField(blank=True, help_text='The thumbnail for the media.', max_length=1000, null=True),
),
]
28 changes: 28 additions & 0 deletions openverse_api/catalog/api/migrations/0040_nullable_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.7 on 2021-10-11 15:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0039_audio_set_thumbs'),
]

operations = [
migrations.AlterField(
model_name='audio',
name='url',
field=models.URLField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True),
),
migrations.AlterField(
model_name='audioset',
name='url',
field=models.URLField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True),
),
migrations.AlterField(
model_name='image',
name='url',
field=models.URLField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True),
),
]
4 changes: 0 additions & 4 deletions openverse_api/catalog/api/models/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class AbstractMedia(IdentifierMixin, MediaMixin, OpenLedgerModel):
information common to all media types indexed by Openverse.
"""

thumbnail = models.URLField(
max_length=1000, blank=True, null=True, help_text="The thumbnail for the media."
)

watermarked = models.BooleanField(blank=True, null=True)

license = models.CharField(max_length=50)
Expand Down
11 changes: 10 additions & 1 deletion openverse_api/catalog/api/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class MediaMixin(models.Model):
creator = models.CharField(max_length=2000, blank=True, null=True)
creator_url = models.URLField(max_length=2000, blank=True, null=True)

# Because all forms of media have a thumbnail for visual representation
thumbnail = models.URLField(
max_length=1000, blank=True, null=True, help_text="The thumbnail for the media."
)

class Meta:
abstract = True

Expand All @@ -64,7 +69,11 @@ class FileMixin(models.Model):
"""

url = models.URLField(
unique=True, max_length=1000, help_text="The actual URL to the media file."
unique=True,
max_length=1000,
help_text="The actual URL to the media file.",
blank=True,
null=True,
)
filesize = models.IntegerField(
blank=True,
Expand Down
2 changes: 1 addition & 1 deletion openverse_api/catalog/api/views/audio_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def thumbnail(self, request, *_, **__):
image_url = None
if thumbnail := audio.thumbnail:
image_url = thumbnail
elif audio.audio_set and (thumbnail := audio.audio_set.url):
elif audio.audio_set and (thumbnail := audio.audio_set.thumbnail):
image_url = thumbnail
if not image_url:
raise get_api_exception("Could not find artwork.", 404)
Expand Down

0 comments on commit 65a624f

Please sign in to comment.