From: Radek Czajka Date: Thu, 18 Mar 2021 13:58:48 +0000 (+0100) Subject: Support for projects without icons. X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/6eabd357bc96f9c952e759852b1a19d2c5cf6b83 Support for projects without icons. --- diff --git a/src/archive/models.py b/src/archive/models.py index 869641c..1fc033b 100644 --- a/src/archive/models.py +++ b/src/archive/models.py @@ -1,9 +1,11 @@ import io import json import os.path +from urllib.parse import urljoin from django.db import models from time import sleep +from django.contrib.sites.models import Site from django.utils.functional import cached_property from django.utils.timezone import now from django.utils.translation import gettext_lazy as _ @@ -47,6 +49,14 @@ class Project(models.Model): " finansowanego przez %s" % self.sponsors if self.sponsors else "", ) + def get_icon_url(self): + if not self.icon: + return '' + return urljoin( + 'https://' + Site.objects.get_current().domain, + self.icon.url + ) + def source_upload_to(intance, filename): return os.path.join(FILES_SAVE_PATH, filename) # FIXME: what about really long file names? diff --git a/src/archive/tasks.py b/src/archive/tasks.py index 17d98cc..9d236db 100644 --- a/src/archive/tasks.py +++ b/src/archive/tasks.py @@ -83,7 +83,7 @@ class AudioFormatTask(Task): 'project': { 'description': audiobook.project.get_description(), - 'icon': audiobook.project.icon.url, + 'icon': audiobook.project.get_icon_url(), } } with open(path, 'rb') as f: