Pass model instances into activities instead of json
This commit is contained in:
parent
9225043b5d
commit
92e40e1cec
|
@ -74,14 +74,13 @@ class ActivityObject:
|
||||||
is_subclass = issubclass(field.type, ActivityObject)
|
is_subclass = issubclass(field.type, ActivityObject)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
is_subclass = False
|
is_subclass = False
|
||||||
|
# serialize a model obj
|
||||||
|
if hasattr(value, 'to_activity'):
|
||||||
|
value = value.to_activity()
|
||||||
# parse a dict into the appropriate activity
|
# parse a dict into the appropriate activity
|
||||||
if is_subclass and isinstance(value, dict):
|
elif is_subclass and isinstance(value, dict):
|
||||||
serializer = None
|
|
||||||
if not isinstance(field.type, ActivityObject):
|
|
||||||
# this is generic, gotta figure out the type manually
|
|
||||||
serializer = field.type
|
|
||||||
value = naive_parse(
|
value = naive_parse(
|
||||||
activity_objects, value, serializer=serializer)
|
activity_objects, value, serializer=field.type)
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if field.default == MISSING and \
|
if field.default == MISSING and \
|
||||||
|
|
|
@ -260,7 +260,7 @@ class ObjectMixin(ActivitypubMixin):
|
||||||
actor=user.remote_id,
|
actor=user.remote_id,
|
||||||
to=['%s/followers' % user.remote_id],
|
to=['%s/followers' % user.remote_id],
|
||||||
cc=['https://www.w3.org/ns/activitystreams#Public'],
|
cc=['https://www.w3.org/ns/activitystreams#Public'],
|
||||||
object=self.to_activity(),
|
object=self,
|
||||||
).serialize()
|
).serialize()
|
||||||
|
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ class ObjectMixin(ActivitypubMixin):
|
||||||
id=activity_id,
|
id=activity_id,
|
||||||
actor=user.remote_id,
|
actor=user.remote_id,
|
||||||
to=['https://www.w3.org/ns/activitystreams#Public'],
|
to=['https://www.w3.org/ns/activitystreams#Public'],
|
||||||
object=self.to_activity()
|
object=self
|
||||||
).serialize()
|
).serialize()
|
||||||
|
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ class CollectionItemMixin(ActivitypubMixin):
|
||||||
return activitypub.Add(
|
return activitypub.Add(
|
||||||
id='%s#add' % self.remote_id,
|
id='%s#add' % self.remote_id,
|
||||||
actor=self.user.remote_id,
|
actor=self.user.remote_id,
|
||||||
object=object_field.to_activity(),
|
object=object_field,
|
||||||
target=collection_field.remote_id
|
target=collection_field.remote_id
|
||||||
).serialize()
|
).serialize()
|
||||||
|
|
||||||
|
@ -374,7 +374,7 @@ class CollectionItemMixin(ActivitypubMixin):
|
||||||
return activitypub.Remove(
|
return activitypub.Remove(
|
||||||
id='%s#remove' % self.remote_id,
|
id='%s#remove' % self.remote_id,
|
||||||
actor=self.user.remote_id,
|
actor=self.user.remote_id,
|
||||||
object=object_field.to_activity(),
|
object=object_field,
|
||||||
target=collection_field.remote_id
|
target=collection_field.remote_id
|
||||||
).serialize()
|
).serialize()
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ class ActivityMixin(ActivitypubMixin):
|
||||||
return activitypub.Undo(
|
return activitypub.Undo(
|
||||||
id='%s#undo' % self.remote_id,
|
id='%s#undo' % self.remote_id,
|
||||||
actor=user.remote_id,
|
actor=user.remote_id,
|
||||||
object=self.to_activity()
|
object=self,
|
||||||
).serialize()
|
).serialize()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue