models.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:closedverse 作者: ariankordi 项目源码 文件源码
def give_notification(user, type, to, post=None, comment=None):
        # Just keeping this simple for now, might want to make it better later
        # If the user sent a notification to this user at least 5 seconds ago, return False
        # Or if user is to
        # Or if yeah notifications are off and this is a yeah notification
        user_is_self_unk = (not type == 3 and user == to)
        is_notification_too_fast = (user.notification_sender.filter(created__gt=timezone.now() - timedelta(seconds=5), type=type).exclude(type=4) and not type == 3)
        user_no_yeahnotif = (not to.let_yeahnotifs() and (type == 0 or type == 1))
        if user_is_self_unk or is_notification_too_fast or user_no_yeahnotif:
            return False
        # Search for my own notifiaction. If it exists, set it as unread.
        merge_own = user.notification_sender.filter(created__gt=timezone.now() - timedelta(hours=8), to=to, type=type, context_post=post, context_comment=comment)
        if merge_own:
            # If it's merged, don't unread that one, but unread what it's merging.
            return merge_own.first().set_unread()
        # Search for a notification already there so we can merge with it if it exists
        merge_s = Notification.objects.filter(created__gt=timezone.now() - timedelta(hours=8), to=to, type=type, context_post=post, context_comment=comment)
        # If it exists, merge with it. Else, create a new notification.
        if merge_s:
            return merge_s.first().merge(user)
        else:
            return user.notification_sender.create(source=user, type=type, to=to, context_post=post, context_comment=comment)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号