コード例 #1
0
 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))
コード例 #2
0
 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))
コード例 #3
0
 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,
     }
コード例 #4
0
ファイル: test_models.py プロジェクト: jaywink/socialhome
 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))
コード例 #5
0
ファイル: test_models.py プロジェクト: jaywink/socialhome
 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))
コード例 #6
0
ファイル: serializers.py プロジェクト: vchslv13/socialhome
 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
コード例 #7
0
ファイル: content.py プロジェクト: takumab/socialhome
def has_shared(content, user):
    if not hasattr(user, "profile"):
        return False
    return Content.has_shared(content.id, user.profile.id)
コード例 #8
0
ファイル: serializers.py プロジェクト: jaywink/socialhome
 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