Apply review suggestion

This commit is contained in:
Joachim 2021-10-27 18:13:47 +02:00
parent 9d4e0851a0
commit 35bd4a4071

View file

@ -425,6 +425,10 @@ class ImageField(ActivitypubFieldMixin, models.ImageField):
def field_to_activity(self, value, alt=None): def field_to_activity(self, value, alt=None):
url = self.get_absolute_url(value) url = self.get_absolute_url(value)
if not url:
return None
return activitypub.Document(url=url, name=alt) return activitypub.Document(url=url, name=alt)
def field_from_activity(self, value): def field_from_activity(self, value):
@ -465,7 +469,7 @@ class ImageField(ActivitypubFieldMixin, models.ImageField):
def get_absolute_url(self, value): def get_absolute_url(self, value):
"""returns an absolute URL for the image""" """returns an absolute URL for the image"""
name = getattr(value, "name") name = getattr(value, "name")
if name is None: if not name:
return None return None
url = filepath_to_uri(name) url = filepath_to_uri(name)