utils.py 文件源码

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

项目:amadeuslms 作者: amadeusproject 项目源码 文件源码
def brodcast_dificulties(request, message, subject):
    msg = TalkMessages()
    msg.text = message
    msg.user = request.user
    msg.subject = subject

    simple_notify = textwrap.shorten(strip_tags(msg.text), width = 30, placeholder = "...")

    for p in subject.professor.all():
        talks = Conversation.objects.filter((Q(user_one = request.user) & Q(user_two__email = p.email)) | (Q(user_two = request.user) & Q(user_one__email = p.email)))

        if talks.count() > 0:
            msg.talk = talks[0]
        else:
            msg.talk = Conversation.objects.create(user_one = request.user, user_two = p)

        msg.save()

        notification = {
            "type": "chat",
            "subtype": subject.slug,
            "space": "subject",
            "user_icon": request.user.image_url,
            "notify_title": str(request.user),
            "simple_notify": simple_notify,
            "view_url": reverse("chat:view_message", args = (msg.id, ), kwargs = {}),
            "complete": render_to_string("chat/_message.html", {"talk_msg": msg}, request),
            "container": "chat-" + str(request.user.id),
            "last_date": _("Last message in %s")%(formats.date_format(msg.create_date, "SHORT_DATETIME_FORMAT"))
        }

        notification = json.dumps(notification)

        Group("user-%s" % p.id).send({'text': notification})

        sendChatPushNotification(p, msg)

        ChatVisualizations.objects.create(viewed = False, message = msg, user = p)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号