本文整理汇总了Python中models.Message.create方法的典型用法代码示例。如果您正苦于以下问题:Python Message.create方法的具体用法?Python Message.create怎么用?Python Message.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def setUp(self):
self.n1, self.n2 = uuid.uuid4().hex, uuid.uuid4().hex
self.k1, self.k2 = fakePublicKey(), fakePublicKey()
self.u1 = User.create(self.n1, self.k1)
self.u2 = User.create(self.n2, self.k2)
self.m1 = Message.create(self.u1, self.u2, 'u1->u2')
self.m2 = Message.create(self.u2, self.u1, 'u2->u1')
self.m3 = Message.create(self.u1, self.u2, 'u1=>u2')
示例2: apply
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def apply(self, *args, **kwargs):
db_conv = Conversation.get(Conversation.conv_id == kwargs.get('conversation_id'))
db_author = User.get(User.gaia_id == kwargs.get('author'))
timestamp = kwargs.get('timestamp')
url_matches = self._url_pattern.match(kwargs.get('message'))
if url_matches:
urls = url_matches.groups()
for url in urls:
if url:
Message.create(content=url, conversation=db_conv, author=db_author, message_type=2, date_created=timestamp)
示例3: ajax_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def ajax_message():
Message.create(
user_id=session['user_id'],
content=request.form["message_text"]
)
message = Message.get(Message.content == request.form["message_text"])
message_info = session['first_name'] + " " + session['last_name'] + " - "
message_info += message.created_at.strftime("%B %d %Y")
message_dict = {
"message": message.content,
"message_info": message_info,
"message_id": message.id,
}
return jsonify(message_dict)
示例4: create_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def create_message(message):
"""
Creates a new message and sent it to all connected clients
"""
msg = Message.create(message=message)
for c in clients:
c.write_message(msg.to_json)
示例5: on_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def on_message(self, model):
user = self.environ['user']
if user is None:
# 手动从store中取出user
session_id = self.environ['session_id']
_data = session.store[session_id]
user = _data['user']
model.update({
"user_id": user.id,
"created_time": datetime.now(),
})
m_id = Message.create(**model)
raw_content = model.get('content')
model.update({
"content": markdown.markdown(raw_content),
"raw_content": raw_content,
"user_name": user.username,
'id': m_id,
'created_time': display_time(model['created_time']),
'is_mine': True,
})
# 发送回客户端
self.emit('message', model)
# 发送给其他人
model['is_mine'] = False
self.emit_to_room(
self.socket.session['room'],
'message',
model,
)
示例6: on_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def on_message(self, model):
user = self.environ['user']
if user is None:
# 手动从store中取出user
session_id = self.environ['session_id']
_data = session.store[session_id]
user = _data['user']
model.update({
"user_id": user.id,
"created_time": datetime.now(),
})
m_id = Message.create(**model)
model.update({
"user_name": user.username,
'id': m_id,
'created_time': str(model['created_time']),
'is_mine': True,
})
# 发送回客户端
self.emit('message', model)
# 发送给其他人
model['is_mine'] = False
self.emit_to_room(
self.socket.session['room'],
'message',
model,
)
示例7: create
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def create():
user = auth.get_logged_in_user()
if request.method == "POST" and request.form["content"]:
message = Message.create(user=user, content=request.form["content"])
flash("Your message has been created")
return redirect(url_for("homepage"))
return render_template("create.html")
示例8: composeNewMail
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def composeNewMail(message):
result = outBoundMail(message)
user = message.get('sender')
notify = message.get('notification_email')
msg = Message.create(message)
user.notify_mail = notify
user.put()
print user.notify_mail
return result
示例9: create
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def create():
user = auth.get_logged_in_user()
if request.method == 'POST' and request.form['content']:
message = Message.create(
user=user,
content=request.form['content'],
)
flash('Your post has been created')
return redirect(url_for('user_detail', username=user.username))
return render_template('create.html')
示例10: testCron
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def testCron(self):
n3 = uuid.uuid4().hex
u3 = User.create(n3, fakePublicKey())
u3.timestamp = datetime.now() - timedelta(LIMITS['DAYS']+1)
u3.put() # Pretend u3 is old.
u4 = User.create(uuid.uuid4().hex, fakePublicKey())
m34 = Message.create(u3, u4, 'one')
m43 = Message.create(u4, u3, 'two')
self.assertEqual(1, len([m for m in u4.inbox]))
self.assertEqual(1, len([m for m in u4.outbox]))
status, result = views.cron() # Should delete u4 and both messages.
self.assertEqual(200, status)
nu, nm = json.loads(result)
self.assertEqual(1, nu)
self.assertEqual(2, nm)
self.assertEqual(0, len([m for m in u4.inbox]))
self.assertEqual(0, len([m for m in u4.outbox]))
self.assertEqual(None, User.get(n3))
self.assertEqual(u4.public_key, User.get(u4.name).public_key)
u4.delete()
示例11: testGetAllMessagesLimit
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def testGetAllMessagesLimit(self):
n3, k3 = uuid.uuid4().hex, fakePublicKey()
u3 = User.create(n3, k3)
ms = [Message.create(u3, u3, uuid.uuid4().hex)
for i in range(LIMITS['MESSAGES']+1)]
status, result = views.getAllMessages()
self.assertEqual(200, status)
ms1 = json.loads(result)
self.assertEqual(LIMITS['MESSAGES'], len(ms1))
status, result = views.getMyMessages(n3)
self.assertEqual(200, status)
ms2 = json.loads(result)
self.assertEqual(LIMITS['MESSAGES'], len(ms2))
# Clean up
for m in ms:
m.delete()
u3.delete()
示例12: composeNewMail
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def composeNewMail(message):
user = message.get("sender")
notify = message.get("notification_email")
result = False
try:
result = outBoundMail(message)
except:
return False
if result != False:
try:
msg = Message.create(message)
user.notify_mail = notify
user.put()
# print user.notify_mail
return result
except:
return False
else:
return False
示例13: sendReply
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def sendReply(user, msg_id, msg, msg_raw, subject, recipient_name, notify):
message = Message.get_by_id(int(msg_id))
new_message = {}
new_message['sender'] = user
new_message['subject'] = subject
new_message['sender_name'] = user.first_name + " " + user.last_name
new_message['sender_email'] = user.alias
new_message['receiver'] = message.sender
new_message['receiver_name'] = recipient_name
new_message['receiver_email'] = message.sender.email
new_message['content'] = msg_raw
new_message['type'] = 'reply_to'
new_message['category'] = message.sender.user_profile
new_message['date'] = strftime("%a, %d %b %Y %X +0000", gmtime())
result = outBoundMail(new_message)
msg = Message.create(new_message)
new_notify = sendCopy(new_message, notify)
user.notify_mail = notify
user.put()
print new_notify
print result
return msg
示例14: POST
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import create [as 别名]
def POST(self):
data = web.data()
data = json.loads(data)
if not session.user or session.user.id is None:
return bad_request("请先登录!")
message_data = {
"content": data.get("content"),
"topic_id": data.get("topic_id"),
"user_id": session.user.id,
"created_time": datetime.now(),
}
m_id = Message.create(**message_data)
result = {
"id": m_id,
"content": message_data.get("content"),
"topic_id": message_data.get("topic_id"),
"user_id": session.user.id,
"user_name": session.user.username,
"created_time": display_time(message_data.get("created_time")),
"is_mine": True,
}
return json.dumps(result)