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


Python Message.to_user方法代码示例

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


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

示例1: send

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import to_user [as 别名]
def send(request):
    if request.method == 'POST':
        if len(request.POST[u'message_to_random_user']):
            message = Message()
            message.from_user = request.user
            message.to_user = get_random_user(request.user)
            message.message = request.POST[u'message_to_random_user']
            message.date = datetime.now()
            message.save()
    return render(request, 'send.html', {'rand_user': get_random_user(request.user)})
开发者ID:kosiovekilski,项目名称:chatter,代码行数:12,代码来源:views.py

示例2: send_broadcast

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import to_user [as 别名]
def send_broadcast(request, event_id=None):

    me = request.user
    to = request.DATA.get("to")
    title = request.DATA.get("title")
    msg = request.DATA.get("message")

    event = Event.objects.filter(id=event_id).first()
    if not event:
        return Response({
            "status": HTTP_404_NOT_FOUND,
            "message": "Event not found"
        }, status=HTTP_404_NOT_FOUND)

    event_organization = event.owner
    user_organization = OrganizationMember.user_organization(me)
    if event_organization != user_organization:
        return Response({
            "status": HTTP_401_UNAUTHORIZED,
            "message": "You are not an authorized member of the event's organization"
        }, status=HTTP_401_UNAUTHORIZED)

    if not OrganizationMember.user_is_admin(user_organization, me):
        return Response({
            "status": HTTP_401_UNAUTHORIZED,
            "message": "You must be an administrator to broadcast messages"
        }, status=HTTP_401_UNAUTHORIZED)

    if to == "ALL":
        recipients = User.objects.all()
    elif to == "CASTING":
        recipients = User.objects.filter(my_user__type='C')
    else:
        recipients = User.objects.filter(my_user__type='T')

    for recipient in recipients:
        message = Message()
        message.from_user = me
        message.to_user = recipient
        message.title = title
        message.message = msg
        message.save()
        create_notification("MSG", message.id, me, recipient, message=msg)

    serializer = PlainMessageSerializer({
        "status": HTTP_200_OK,
        "message": "Broadcast sent."
    })
    return Response(serializer.data)
开发者ID:aftabaig,项目名称:py_castm,代码行数:51,代码来源:views.py

示例3: send_message

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import to_user [as 别名]
def send_message(request):
    """
    Sends a message to a linked user.
    Allowed HTTP methods are:\n
        1. POST to send\n
            Accepts following hash:\n
            . {\n
                "to": [user_id],\n
                "title": [message_title],\n
                "message": [the_message]\n
            }\n
            Returns:\n
            . Newly created message
    Status:\n
        1. 200 on success
        2. 400 if some error occurs
        3. 401 if un-authorized
        4. 404 if user not found
    Notes:\n
        1. Require user's token to be sent in the header as:\n
            Authorization: Token [token]\n
    """
    me = request.user
    to_id = request.DATA.get("to")
    title = request.DATA.get("title")
    msg = request.DATA.get("message")
    to = User.objects.filter(id=to_id).first()

    if to:
        if Link.is_already_link(me, to):
            message = Message()
            message.from_user = me
            message.to_user = to
            message.title = title
            message.message = msg
            message.save()
            create_notification("MSG", message.id, me, to, message=msg)
            serializer = PlainMessageSerializer(message.plain())
            return Response(serializer.data)
        return Response({
            "status": HTTP_400_BAD_REQUEST,
            "message": "Cannot send message to a non-link"
        }, status=HTTP_400_BAD_REQUEST)
    return Response({
        "status": HTTP_404_NOT_FOUND,
        "message": "User not found"
    }, status=HTTP_404_NOT_FOUND)
开发者ID:aftabaig,项目名称:py_castm,代码行数:49,代码来源:views.py


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