コード例 #1
0
def comment_post_save(instance, **kwargs):
    if hasattr(instance, '__pub_info'):
        is_public = instance.is_public and not instance.is_removed
        was_public = instance.__pub_info['is_public'] and not instance.__pub_info['is_removed']

        # Base queryset for public comments
        public_comments = comments.get_model()._default_manager.filter(
            content_type=instance.content_type_id,
            object_pk=instance.object_pk,
            is_public=True,
            is_removed=False
        )

        # If the comment's "publicity" was modified in any way, update the count key
        if (was_public and not is_public) or (not was_public and is_public):
            client.set(
                COMCOUNT_KEY % (instance.content_type_id, instance.object_pk),
                public_comments.count()
            )
        # If no change to the "publicity" of the comment was made, return
        else:
            return

        # Update the last comment info
        last_keu = LASTCOM_KEY % (instance.content_type_id, instance.object_pk)
        try:
            last_com = public_comments.latest('submit_date')
            client.hmset(last_keu, {
                'submit_date': repr(to_timestamp(last_com.submit_date)),
                'user_id': last_com.user_id or '',
                'username': last_com.user_name,
                'comment': last_com.comment,
                'url': last_com.url,
            })
        except comments.get_model().DoesNotExist:
            client.delete(last_keu)

        # update the listing handlers
        obj = instance.content_object
        if isinstance(obj, Publishable) and obj.is_published():
            publishable_published(obj)
コード例 #2
0
 def test_comment_count_for_article_is_picked_up_through_article(self):
     create_comment(self.publishable, self.publishable.content_type)
     # put some value directly to redis, so we know it was taken from there
     client.set(COMCOUNT_KEY % (self.publishable.content_type.pk, self.publishable.pk), '10')
     t = template.Template('''{% load ellacomments_tags %}{% get_comment_count for obj as var_name%}{{ var_name }}''')
     tools.assert_equals('10', t.render(template.Context({'obj': self.publishable})))