def field_from_activity(self, value): image_slug = value # when it's an inline image (User avatar/icon, Book cover), it's a json # blob, but when it's an attached image, it's just a url if hasattr(image_slug, "url"): url = image_slug.url elif isinstance(image_slug, str): url = image_slug else: return None try: validate_remote_id(url) except ValidationError: return None image_content, extension = get_image(url) if not image_content: return None image_name = f"{uuid4()}.{extension}" return [image_name, image_content]
def field_from_activity(self, value): image_slug = value # when it's an inline image (User avatar/icon, Book cover), it's a json # blob, but when it's an attached image, it's just a url if hasattr(image_slug, "url"): url = image_slug.url elif isinstance(image_slug, str): url = image_slug else: return None try: validate_remote_id(url) except ValidationError: return None response = get_image(url) if not response: return None image_name = str(uuid4()) + "." + url.split(".")[-1] image_content = ContentFile(response.content) return [image_name, image_content]
def field_from_activity(self, value): image_slug = value # when it's an inline image (User avatar/icon, Book cover), it's a json # blob, but when it's an attached image, it's just a url if hasattr(image_slug, "url"): url = image_slug.url elif isinstance(image_slug, str): url = image_slug else: return None try: validate_remote_id(url) except ValidationError: return None response = get_image(url) if not response: return None image_content = ContentFile(response.content) extension = imghdr.what(None, image_content.read()) or "" image_name = "{:s}.{:s}".format(str(uuid4()), extension) return [image_name, image_content]