本文整理汇总了Python中models.User.User.add_new_conversation方法的典型用法代码示例。如果您正苦于以下问题:Python User.add_new_conversation方法的具体用法?Python User.add_new_conversation怎么用?Python User.add_new_conversation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User.User
的用法示例。
在下文中一共展示了User.add_new_conversation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_new_conversation [as 别名]
def post(self, conv_id, msg_id):
sender = username = self.get_cookie("username")
receiver = self.request.get('receiver')
title = self.request.get('title')
content = self.request.get('content')
sender = sender.lower()
receiver = receiver.lower()
vr, err = check_valid_receiver(receiver)
if vr:
# Adds a new message to conversation
if conv_id and msg_id:
msg = Conversation.add_new_message(sender, content, conv_id=conv_id)
self.notify_user(sender, conv_id, msg)
# Adds a new conversation with first message
elif receiver and title and content:
(conv, msg) = User.add_new_conversation(sender, receiver, title, content)
self.notify_user(sender, conv.key.id(), msg)
else:
self.response.out.write("Error in Messages.post()")
if self.request.path.startswith('/messages'):
self.redirect('/messages?show=all')
else:
self.redirect(self.request.referer)
else:
self.show_form_for_new_message(errors=err)
示例2: testDeleteWithoutOwner
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_new_conversation [as 别名]
def testDeleteWithoutOwner(self):
c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
title_plain_text,
content_plain_text)
m = Conversation.add_new_message(self.u2.username_norm,
content_plain_text2, conv_key=c.key)
Conversation.add_new_message(self.u1.username_norm,
content_plain_text, conv_key=c.key)
# c.put()
self.assertEqual(len(c.messages_list), 3, "Length of messages list != 3")
Conversation.delete_message(self.u2.username_norm, c.key.id(), m.key.id())
self.assertEqual(len(c.messages_list), 3, "Length of messages list != 3 after deletion")
deleted = m.key.get()
self.assertIsNotNone(deleted, "Message is None")
self.assertEqual(deleted.deleted_for, self.u2.username_norm, "Deleted for is incorrect")
for k in c.messages_list:
msg = k.get()
if k != deleted.key:
self.assertIsNone(msg.deleted_for, "deleted_for was not None for a message other than deleted")
示例3: testCreateConversation
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_new_conversation [as 别名]
def testCreateConversation(self):
c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
title_plain_text,
content_plain_text)
conv = c.key.get()
self.assertEqual(conv.title, title_plain_text, 'new conversation title')
self.assertEqual(conv.messages[0].content, content_plain_text, 'new conversation message')
示例4: testAddNewMessage
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_new_conversation [as 别名]
def testAddNewMessage(self):
c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
title_plain_text,
content_plain_text)
m = Conversation.add_new_message(self.u2.username_norm,
content_plain_text2, conv_key=c.key)
# c.put()
self.assertEqual(len(c.messages_list), 2, "Length of message list %s != %s" % (len(c.messages_list), 2))
test_cont = (content_plain_text, content_plain_text2)
for i, msg in enumerate(c.messages_list):
newmsg = msg.get()
self.assertEqual(newmsg.content, test_cont[i], "Message Content")
示例5: testDeleteConversationWithOneMsgAndOwner
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_new_conversation [as 别名]
def testDeleteConversationWithOneMsgAndOwner(self):
c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
title_plain_text,
content_plain_text)
self.assertEqual(len(c.messages_list), 1, "1ength of messages list != 1")
m = c.messages_list[0]
Conversation.delete_message(self.u1.username_norm, c.key.id(), m.id())
conv = c.key.get()
msg = m.get()
self.assertIsNone(conv, "Conversation was not deleted")
self.assertIsNone(msg, "Message was not deleted")
示例6: testDeleteOneMessageWithOwner
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_new_conversation [as 别名]
def testDeleteOneMessageWithOwner(self):
c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
title_plain_text,
content_plain_text)
m = Conversation.add_new_message(self.u2.username_norm,
content_plain_text2, conv_key=c.key)
Conversation.add_new_message(self.u1.username_norm,
content_plain_text, conv_key=c.key)
# c.put()
self.assertEqual(len(c.messages_list), 3, "Length of messages list != 3")
Conversation.delete_message(self.u1.username_norm, c.key.id(), m.key.id())
self.assertEqual(len(c.messages_list), 2, "Length of messages list != 2 after deletion")
deleted = m.key.get()
self.assertIsNone(deleted, "Message was not deleted")
示例7: testDeleteConversationWithoutOwner
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_new_conversation [as 别名]
def testDeleteConversationWithoutOwner(self):
c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
title_plain_text,
content_plain_text)
m = Conversation.add_new_message(self.u2.username_norm,
content_plain_text2, conv_key=c.key)
# c.put()
Conversation.delete_conversation(self.u2.username_norm, key=c.key)
conv = c.key.get()
self.assertIsNotNone(conv, "Conversation is None")
self.assertEqual(conv.deleted_for, self.u2.username_norm,
"Conversation not deleted for %s" % self.u2.username_norm)
for m in conv.messages:
self.assertEqual(m.deleted_for, self.u2.username_norm,
"Message not deleted for %s" % self.u2.username_norm)
示例8: testDeleteConversationWithOwner
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_new_conversation [as 别名]
def testDeleteConversationWithOwner(self):
c, msg = User.add_new_conversation(self.u1.username_norm, self.u2.username_norm,
title_plain_text,
content_plain_text)
m = Conversation.add_new_message(self.u2.username_norm,
content_plain_text2, conv_key=c.key)
message_keys = deepcopy(c.messages_list)
# c.put()
Conversation.delete_conversation(self.u1.username_norm, key=c.key)
conv = c.key.get()
self.assertIsNone(conv, "Conversation is not None")
for k in message_keys:
msg = k.get()
self.assertIsNone(msg, "Message is not None")