本文整理汇总了Python中models.Message.conversation方法的典型用法代码示例。如果您正苦于以下问题:Python Message.conversation方法的具体用法?Python Message.conversation怎么用?Python Message.conversation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.conversation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detail_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import conversation [as 别名]
def detail_message(request, conv_id):
"""
view untuk menampilkan detail pesan
beserta percakapan
"""
conv = get_object_or_404(Conversation, id=conv_id, users=request.user, membership__deleted=False)
list_messages = Message.objects.filter(conversation=conv)
msg = list_messages[0]
if request.POST:
form = SendConversationForm(request.POST)
if form.is_valid():
msg = Message()
msg.conversation = conv
msg.user = request.user
msg.content = form.cleaned_data['content']
msg.save()
to2 = list(conv.users.all())
to2.remove(request.user)
notification.send(to2, 'new_message', {'user': request.user, 'message': conv})
messages.info(request, _('Message sent'))
return HttpResponseRedirect(conv.get_absolute_url())
else:
form = SendConversationForm()
return render_to_response('message/detail_message.html',
{"conv": conv,
'form': form,
'msg': msg,
'list_messages': list_messages},
context_instance=RequestContext(request))
示例2: save_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import conversation [as 别名]
def save_message(user_id, message):
type_name = message.get('type_name')
args = message.get('args')
file = message.get('file', '')
conversation_id = message.get('conversation_id')
mt = MessageType.select().where(MessageType.name == type_name).first()
u = User.select().where(User.id == user_id).first()
cps = ConversationParty.select().where(ConversationParty.conversation == conversation_id)
number_of_conversationees = cps.count()
if not mt or not u or not cps or not number_of_conversationees:
raise InvalidMessageDataException('Couldn\'t save message: invalid message data')
m = Message()
with database.transaction():
m.conversation = conversation_id
m.message_type = mt
m.sender_id = user_id
m.ts = datetime.now()
m.file = file
m.content, m.display_content = __save_content(args, mt, user_id, cps)
m.save()
update_conversation(conversation_id=conversation_id,
last_message=m)
mark_message_as_read(user_id=user_id,
message=m,
conversation_id=conversation_id)
message_object = get_message_json(message=m)
message_object['recipient_ids'] = [cp.user.id for cp in cps]
return json.dumps(message_object)
示例3: on_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import conversation [as 别名]
def on_message(self, message):
message = Message(**json.loads(message))
message.author = self.current_user
message.created_at = datetime.utcnow()
message.conversation = self.conversation
self.db.add(message)
self.db.commit()
for user in self.conversation.connected_users:
user.write_message(json.dumps(message.as_json()))
示例4: create_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import conversation [as 别名]
def create_message(request, username=None):
"""
view untuk menampilkan pembuatan pesan
"""
to = []
if username:
to.append(username)
if request.POST:
to = request.POST.getlist('to')
form = CreateMessageForm(request.POST)
if form.is_valid():
title = form.cleaned_data['title']
message = form.cleaned_data['content']
location = form.cleaned_data['location']
conv = Conversation()
conv.title = title
conv.origin = request.user
conv.location = location
conv.save()
Membership.objects.create(user=request.user,
conversation=conv)
to2 = []
for person in to:
to_person = User.objects.get(username=person)
to2.append(to_person)
Membership.objects.create(user=to_person,
conversation=conv)
msg = Message()
msg.conversation = conv
msg.content = message
msg.user = request.user
msg.save()
notification.send(to2, 'new_message',
{'user': request.user, 'message': conv})
messages.info(request, _('Message sent'))
return HttpResponseRedirect(reverse('message_list'))
else:
form = CreateMessageForm()
return render_to_response('message/create_message.html',
{'form': form,
'to': to},
context_instance=(RequestContext(request)))
示例5: Message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import conversation [as 别名]
from models import BaseModel, User, Conversation, ConversationParty, Message, MessageType, database
from datetime import datetime
# Messages
m = Message()
m.conversation = Conversation.get(Conversation.id==1)
m.sender = User.get(User.id==1)
m.message_type = MessageType.get(MessageType.name=='directive_quotation_mt')
m.ts = datetime.now()
args = {'currency':'R$',
'per_day_beneficiary_value':'20.50',
'number_of_beneficiaries':'5',
'company_name':'VR',
'company_picture':''
}
with database.transaction():
m.save()
m.run_constructor(args)
m.save()