コード例 #1
0
 def test_get_rendered_contents_for_user(self):
     qs = Content.objects.filter(
         id__in=[self.public_content.id, self.site_content.id])
     contents = Content.get_rendered_contents(qs)
     self.assertEqual(
         contents,
         [{
             "id": self.public_content.id,
             "guid": self.public_content.guid,
             "author": self.public_content.author_id,
             "author_image":
             self.public_content.author.safer_image_url_small,
             "author_name": self.public_content.author.name,
             "rendered": "<p><strong>Foobar</strong></p>",
             "humanized_timestamp": self.public_content.humanized_timestamp,
             "formatted_timestamp": self.public_content.formatted_timestamp,
         }, {
             "id": self.site_content.id,
             "guid": self.site_content.guid,
             "author": self.site_content.author_id,
             "author_image": self.site_content.author.safer_image_url_small,
             "author_name": self.site_content.author.handle,
             "rendered": "<p><em>Foobar</em></p>",
             "humanized_timestamp": self.site_content.humanized_timestamp,
             "formatted_timestamp": self.site_content.formatted_timestamp,
         }])
コード例 #2
0
ファイル: test_models.py プロジェクト: jcooter/socialhome
 def test_get_rendered_contents__with_throughs(self):
     qs = Content.objects.filter(
         id__in=[self.public_content.id, self.site_content.id])
     contents = Content.get_rendered_contents(
         qs, self.user2, throughs={self.site_content.id: 123})
     self.assertEqual(contents[0].get("through"), self.public_content.id)
     self.assertEqual(contents[1].get("through"), 123)
コード例 #3
0
 def handle_load_more(self, data):
     """Load more content to the stream."""
     last_id = data.get("last_id")
     if not last_id:
         return
     qs = self._get_stream_qs()
     qs = qs.filter(id__lt=last_id)[:20]
     contents = Content.get_rendered_contents(qs)
     payload = self.make_payload(contents, "appended")
     self.send(payload)
コード例 #4
0
 def handle_load_content(self, data):
     """Send back the requested content."""
     ids = data.get("ids")
     if not ids:
         return
     qs = self._get_stream_qs()
     qs = qs.filter(id__in=ids)
     contents = Content.get_rendered_contents(qs)
     payload = self.make_payload(contents, "prepended")
     self.send(payload)
コード例 #5
0
 def handle_load_children(self, data):
     content_id = data.get("content_id")
     if not content_id:
         return
     # TODO: get recursively
     qs = Content.objects.children(content_id, self.message.user)
     contents = Content.get_rendered_contents(qs, self.message.user)
     payload = self.make_payload(contents, "children")
     payload["parent_id"] = content_id
     self.send_payload(payload)
コード例 #6
0
ファイル: test_models.py プロジェクト: dissolve/socialhome
 def test_get_rendered_contents_for_user(self):
     qs = Content.objects.filter(id__in=[self.public_content.id, self.site_content.id])
     contents = Content.get_rendered_contents(qs, self.user2)
     self.assertEqual(contents, [
         {
             "id": self.public_content.id,
             "guid": self.public_content.guid,
             "author": self.public_content.author_id,
             "author_guid": self.public_content.author.guid,
             "author_image": self.public_content.author.safer_image_url_small,
             "author_name": self.public_content.author.handle,
             "author_profile_url": self.public_content.author.get_absolute_url(),
             "author_home_url": self.public_content.author.home_url,
             "author_is_local": bool(self.public_content.author.user),
             "rendered": "<p><strong>Foobar</strong></p>",
             "humanized_timestamp": self.public_content.humanized_timestamp,
             "formatted_timestamp": self.public_content.formatted_timestamp,
             "author_handle": self.public_content.author.handle,
             "is_author": False,
             "is_following_author": False,
             "slug": self.public_content.slug,
             "update_url": "",
             "delete_url": "",
             "reply_url": "",
             "child_count": 0,
             "is_authenticated": False,
             "parent": "",
             "profile_id": "",
         },
         {
             "id": self.site_content.id,
             "guid": self.site_content.guid,
             "author": self.site_content.author_id,
             "author_guid": self.site_content.author.guid,
             "author_image": self.site_content.author.safer_image_url_small,
             "author_name": self.site_content.author.handle,
             "author_profile_url": self.site_content.author.get_absolute_url(),
             "author_home_url": self.site_content.author.home_url,
             "author_is_local": bool(self.site_content.author.user),
             "rendered": "<p><em>Foobar</em></p>",
             "humanized_timestamp": self.site_content.humanized_timestamp,
             "formatted_timestamp": self.site_content.formatted_timestamp,
             "author_handle": self.site_content.author.handle,
             "is_author": False,
             "is_following_author": False,
             "slug": self.site_content.slug,
             "update_url": "",
             "delete_url": "",
             "reply_url": "",
             "child_count": 0,
             "is_authenticated": False,
             "parent": "",
             "profile_id": "",
         }
     ])
コード例 #7
0
ファイル: consumers.py プロジェクト: subkrish/socialhome
 def handle_load_more(self, data):
     """Load more content to the stream."""
     last_id = data.get("last_id")
     if not last_id:
         return
     qs, throughs = self._get_stream_qs(last_id=last_id)
     contents = Content.get_rendered_contents(qs,
                                              self.message.user,
                                              throughs=throughs)
     payload = self.make_payload(contents, "appended")
     self.send_payload(payload)