Receive and save incoming images
This commit is contained in:
@ -7,7 +7,7 @@ from .connector import Connector
|
||||
from .relationship import UserFollows, UserFollowRequest, UserBlocks
|
||||
from .shelf import Shelf, ShelfBook
|
||||
from .status import Status, GeneratedNote, Review, Comment, Quotation
|
||||
from .status import Favorite, Boost, Notification, ReadThrough
|
||||
from .status import Attachment, Favorite, Boost, Notification, ReadThrough
|
||||
from .tag import Tag
|
||||
from .user import User
|
||||
from .federated_server import FederatedServer
|
||||
|
@ -276,10 +276,5 @@ def image_formatter(image, default_path=None):
|
||||
|
||||
|
||||
def image_attachments_formatter(images):
|
||||
''' create a list of image attachemnts '''
|
||||
if not isinstance(images, list):
|
||||
images = [images]
|
||||
attachments = []
|
||||
for image in images:
|
||||
attachments.append(image_formatter(image))
|
||||
return attachments
|
||||
''' create a list of image attachments '''
|
||||
return [image_formatter(i) for i in images]
|
||||
|
@ -100,7 +100,9 @@ class Book(ActivitypubMixin, BookWyrmModel):
|
||||
ActivityMapping('editions', 'editions_path'),
|
||||
ActivityMapping(
|
||||
'attachment', 'cover',
|
||||
image_attachments_formatter
|
||||
# this expects an iterable and the field is just an image
|
||||
lambda x: image_attachments_formatter([x]),
|
||||
lambda x: activitypub.image_attachments_formatter(x)[0]
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -7,7 +7,7 @@ from model_utils.managers import InheritanceManager
|
||||
from bookwyrm import activitypub
|
||||
from .base_model import ActivitypubMixin, OrderedCollectionPageMixin
|
||||
from .base_model import ActivityMapping, BookWyrmModel, PrivacyLevels
|
||||
from .base_model import tag_formatter
|
||||
from .base_model import tag_formatter, image_attachments_formatter
|
||||
|
||||
|
||||
class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||
@ -80,13 +80,18 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||
ActivityMapping(
|
||||
'tag', 'mention_books',
|
||||
lambda x: tag_formatter(x, 'title', 'Book'),
|
||||
activitypub.tag_formatter
|
||||
lambda x: activitypub.tag_formatter(x, 'Book')
|
||||
),
|
||||
ActivityMapping(
|
||||
'tag', 'mention_users',
|
||||
lambda x: tag_formatter(x, 'username', 'Mention'),
|
||||
activitypub.tag_formatter
|
||||
lambda x: activitypub.tag_formatter(x, 'Mention')
|
||||
),
|
||||
ActivityMapping(
|
||||
'attachment', 'attachments',
|
||||
lambda x: image_attachments_formatter(x.all()),
|
||||
activitypub.image_attachments_formatter
|
||||
)
|
||||
]
|
||||
|
||||
# serializing to bookwyrm expanded activitypub
|
||||
@ -140,9 +145,10 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
''' update user active time '''
|
||||
self.user.last_active_date = timezone.now()
|
||||
self.user.save()
|
||||
super().save(*args, **kwargs)
|
||||
if self.user.local:
|
||||
self.user.last_active_date = timezone.now()
|
||||
self.user.save()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class Attachment(BookWyrmModel):
|
||||
@ -150,7 +156,7 @@ class Attachment(BookWyrmModel):
|
||||
status = models.ForeignKey(
|
||||
'Status',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='items'
|
||||
related_name='attachments'
|
||||
)
|
||||
image = models.ImageField(upload_to='status/', null=True, blank=True)
|
||||
|
||||
|
Reference in New Issue
Block a user