def share(self, profile):
"""Share this content as the profile given."""
if self.content_type != ContentType.CONTENT:
# TODO: support sharing replies too
raise ValidationError("Can only share top level content.")
if self.author == profile:
raise ValidationError("Cannot share own content")
if not self.visible_for_user(profile.user):
raise ValidationError("Content to be shared is not visible to sharer.")
if self.shares.filter(author=profile).exists():
raise ValidationError("Profile has already shared this content.")
# Use get or created as a safety to stop duplicates
share, _created = Content.objects.get_or_create(author=profile, share_of=self, defaults={
"visibility": self.visibility,
})
delete_memoized(Content.has_shared, self.id, profile.id)
return share
评论列表
文章目录