本文整理汇总了Python中models.Message.from_user方法的典型用法代码示例。如果您正苦于以下问题:Python Message.from_user方法的具体用法?Python Message.from_user怎么用?Python Message.from_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.from_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import from_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)})
示例2: send_broadcast
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import from_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)
示例3: send_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import from_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)