move image activity to its own file

This commit is contained in:
Mouse Reeve
2020-11-27 17:58:21 -08:00
parent 624ff71a11
commit 4ae785a7f7
6 changed files with 21 additions and 21 deletions

View File

@ -23,13 +23,6 @@ class ActivityEncoder(JSONEncoder):
return o.__dict__
@dataclass
class Image:
''' image block '''
url: str
type: str = 'Image'
@dataclass
class Link():
''' for tagging a book in a status '''
@ -146,6 +139,7 @@ class ActivityObject:
for (model_key, value) in image_fields.items():
if not value:
continue
#formatted_value = image_formatter(value)
getattr(instance, model_key).save(*value, save=True)
# add one to many fields
@ -212,16 +206,9 @@ def tag_formatter(tags, tag_type):
def image_formatter(image_json):
''' helper function to load images and format them for a model '''
if isinstance(image_json, list):
try:
image_json = image_json[0]
except IndexError:
return None
if not image_json or not hasattr(image_json, 'url'):
url = image.get('url')
if not url:
return None
url = image_json.get('url')
try:
response = requests.get(url)
except ConnectionError: