mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-31 11:22:21 +00:00
move image activity to its own file
This commit is contained in:
parent
624ff71a11
commit
4ae785a7f7
6 changed files with 21 additions and 21 deletions
|
@ -2,11 +2,12 @@
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .base_activity import ActivityEncoder, Image, PublicKey, Signature
|
from .base_activity import ActivityEncoder, PublicKey, Signature
|
||||||
from .base_activity import Link, Mention
|
from .base_activity import Link, Mention
|
||||||
from .base_activity import ActivitySerializerError
|
from .base_activity import ActivitySerializerError
|
||||||
from .base_activity import tag_formatter
|
from .base_activity import tag_formatter
|
||||||
from .base_activity import image_formatter, image_attachments_formatter
|
from .base_activity import image_formatter, image_attachments_formatter
|
||||||
|
from .image import Image
|
||||||
from .note import Note, GeneratedNote, Article, Comment, Review, Quotation
|
from .note import Note, GeneratedNote, Article, Comment, Review, Quotation
|
||||||
from .note import Tombstone
|
from .note import Tombstone
|
||||||
from .interaction import Boost, Like
|
from .interaction import Boost, Like
|
||||||
|
|
|
@ -23,13 +23,6 @@ class ActivityEncoder(JSONEncoder):
|
||||||
return o.__dict__
|
return o.__dict__
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Image:
|
|
||||||
''' image block '''
|
|
||||||
url: str
|
|
||||||
type: str = 'Image'
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Link():
|
class Link():
|
||||||
''' for tagging a book in a status '''
|
''' for tagging a book in a status '''
|
||||||
|
@ -146,6 +139,7 @@ class ActivityObject:
|
||||||
for (model_key, value) in image_fields.items():
|
for (model_key, value) in image_fields.items():
|
||||||
if not value:
|
if not value:
|
||||||
continue
|
continue
|
||||||
|
#formatted_value = image_formatter(value)
|
||||||
getattr(instance, model_key).save(*value, save=True)
|
getattr(instance, model_key).save(*value, save=True)
|
||||||
|
|
||||||
# add one to many fields
|
# add one to many fields
|
||||||
|
@ -212,16 +206,9 @@ def tag_formatter(tags, tag_type):
|
||||||
|
|
||||||
def image_formatter(image_json):
|
def image_formatter(image_json):
|
||||||
''' helper function to load images and format them for a model '''
|
''' helper function to load images and format them for a model '''
|
||||||
if isinstance(image_json, list):
|
url = image.get('url')
|
||||||
try:
|
if not url:
|
||||||
image_json = image_json[0]
|
|
||||||
except IndexError:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not image_json or not hasattr(image_json, 'url'):
|
|
||||||
return None
|
|
||||||
url = image_json.get('url')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from .base_activity import ActivityObject, Image
|
from .base_activity import ActivityObject
|
||||||
|
from .image import Image
|
||||||
|
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
class Book(ActivityObject):
|
class Book(ActivityObject):
|
||||||
|
@ -25,7 +26,7 @@ class Book(ActivityObject):
|
||||||
librarythingKey: str = ''
|
librarythingKey: str = ''
|
||||||
goodreadsKey: str = ''
|
goodreadsKey: str = ''
|
||||||
|
|
||||||
attachment: List[Image] = field(default_factory=lambda: [])
|
cover: Image = field(default_factory=lambda: {})
|
||||||
type: str = 'Book'
|
type: str = 'Book'
|
||||||
|
|
||||||
|
|
||||||
|
|
9
bookwyrm/activitypub/image.py
Normal file
9
bookwyrm/activitypub/image.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
''' an image, nothing fancy '''
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Image:
|
||||||
|
''' image block '''
|
||||||
|
url: str
|
||||||
|
name: str = ''
|
||||||
|
type: str = 'Image'
|
|
@ -2,7 +2,8 @@
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from .base_activity import ActivityObject, Image, Link
|
from .base_activity import ActivityObject, Link
|
||||||
|
from .image import Image
|
||||||
|
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
class Tombstone(ActivityObject):
|
class Tombstone(ActivityObject):
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from .base_activity import ActivityObject, Image, PublicKey
|
from .base_activity import ActivityObject, PublicKey
|
||||||
|
from .image import Image
|
||||||
|
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
class Person(ActivityObject):
|
class Person(ActivityObject):
|
||||||
|
|
Loading…
Reference in a new issue