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


Python Message.create方法代码示例

本文整理汇总了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')
开发者ID:league,项目名称:cryptodemo,代码行数:10,代码来源:tests.py

示例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)
开发者ID:elamperti,项目名称:bastardbot,代码行数:13,代码来源:url.py

示例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)
开发者ID:LawerenceLee,项目名称:coding_dojo_projects,代码行数:16,代码来源:app.py

示例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)
开发者ID:gkuhn1,项目名称:tornado-and-motor-lab,代码行数:9,代码来源:chat.py

示例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,
        )
开发者ID:bb-js,项目名称:bb-js.org,代码行数:33,代码来源:socket.py

示例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,
        )
开发者ID:fatfan,项目名称:mychat,代码行数:30,代码来源:handlers.py

示例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")
开发者ID:sekenned,项目名称:totb,代码行数:10,代码来源:views.py

示例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
开发者ID:nicodee,项目名称:minc,代码行数:11,代码来源:mailhandler.py

示例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')
开发者ID:coderluka,项目名称:naucilus,代码行数:13,代码来源:views.py

示例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()
开发者ID:league,项目名称:cryptodemo,代码行数:22,代码来源:tests.py

示例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()
开发者ID:league,项目名称:cryptodemo,代码行数:21,代码来源:tests.py

示例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
开发者ID:nicodee,项目名称:meststrikeforce,代码行数:21,代码来源:mailhandler.py

示例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
开发者ID:nicodee,项目名称:mestglobalcommunity,代码行数:24,代码来源:mailhandler.py

示例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)
开发者ID:bb-js,项目名称:bb-js.org,代码行数:25,代码来源:message.py


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