def test_unshare_removes_a_share(self): self.public_content.share(self.local_user.profile) assert Content.has_shared(self.public_content.id, self.local_user.profile.id) self.public_content.unshare(self.local_user.profile) self.assertFalse( Content.has_shared(self.public_content.id, self.local_user.id))
def test_has_shared(self): self.assertFalse( Content.has_shared(self.public_content.id, self.local_user.profile.id)) # Do a share self.public_content.share(self.local_user.profile) self.assertTrue( Content.has_shared(self.public_content.id, self.local_user.profile.id))
def dump_content(content): is_user_author = (content.author == request_user_profile) return { "htmlSafe": content.rendered, "author": { "guid": content.author.guid, "name": content.author.name if content.author.name else content.author.handle, "handle": content.author.handle, "imageUrlSmall": content.author.safer_image_url_small, "absoluteUrl": content.author.get_absolute_url(), "homeUrl": content.author.home_url, "isUserFollowingAuthor": (content.author.id in getattr(request_user_profile, "following_ids", [])) }, "id": content.id, "timestamp": content.timestamp, "humanizedTimestamp": content.humanized_timestamp, "edited": bool(content.edited), "repliesCount": content.reply_count, "sharesCount": content.shares_count, "isUserLocal": bool(content.author.user), "contentUrl": content.get_absolute_url(), "isUserAuthor": is_user_author, "hasShared": Content.has_shared(content.id, request_user_profile.id) if request_user_profile else False, }
def test_has_shared(self): self.assertFalse(Content.has_shared(self.public_content.id, self.local_user.profile.id)) # Do a share self.public_content.share(self.local_user.profile) self.assertTrue(Content.has_shared(self.public_content.id, self.local_user.profile.id))
def test_unshare_removes_a_share(self): self.public_content.share(self.local_user.profile) assert Content.has_shared(self.public_content.id, self.local_user.profile.id) self.public_content.unshare(self.local_user.profile) self.assertFalse(Content.has_shared(self.public_content.id, self.local_user.id))
def get_user_has_shared(self, obj): request = self.context.get("request") if not request: return False return Content.has_shared(obj.id, request.user.profile.id) if hasattr(request.user, "profile") else False
def has_shared(content, user): if not hasattr(user, "profile"): return False return Content.has_shared(content.id, user.profile.id)