当前位置: 首页>>代码示例>>Python>>正文


Python Comment.is_reply_comment方法代码示例

本文整理汇总了Python中django.contrib.comments.models.Comment.is_reply_comment方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.is_reply_comment方法的具体用法?Python Comment.is_reply_comment怎么用?Python Comment.is_reply_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.comments.models.Comment的用法示例。


在下文中一共展示了Comment.is_reply_comment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: comment_reply_post_create_handler

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import is_reply_comment [as 别名]
def comment_reply_post_create_handler(sender, instance, action, model, pk_set,
    using, **kwargs):
    if action == 'post_add':
        for replied_to_comment in instance.replied_to_comments.all():
            moderator_settings = getattr(settings, 'MODERATOR', None)
            offset_timedelta = timedelta(seconds=1)
            if moderator_settings:
                if 'REPLY_BEFORE_COMMENT' in moderator_settings:
                    if moderator_settings['REPLY_BEFORE_COMMENT']:
                        offset_timedelta = timedelta(seconds=-1)

            created = False
            # We use try except DoesNotExist instead of get or create to
            # allow us to add a is_reply_comment to a newly created comment
            # which facilitates realtime_comment_classifier below to distinguish
            # between normal comments and reply comments.
            try:
                comment_obj = Comment.objects.get(
                    content_type=replied_to_comment.content_type,
                    object_pk=replied_to_comment.object_pk,
                    site=replied_to_comment.site,
                    submit_date=replied_to_comment.submit_date + offset_timedelta,
                    user=instance.user,
                )
            except Comment.DoesNotExist:
                comment_obj = Comment(
                    content_type=replied_to_comment.content_type,
                    object_pk=replied_to_comment.object_pk,
                    site=replied_to_comment.site,
                    submit_date=replied_to_comment.submit_date + offset_timedelta,
                    user=instance.user,
                    comment=instance.comment_text,
                )
                comment_obj.is_reply_comment = True
                comment_obj.save()
                created = True

            if not created:
                comment_obj.comment = instance.comment_text
                comment_obj.save()

            if comment_obj not in instance.reply_comments.all():
                instance.reply_comments.add(comment_obj)
开发者ID:praekelt,项目名称:django-moderator,代码行数:45,代码来源:models.py


注:本文中的django.contrib.comments.models.Comment.is_reply_comment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。