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


Python Message.sent_at方法代码示例

本文整理汇总了Python中models.Message.sent_at方法的典型用法代码示例。如果您正苦于以下问题:Python Message.sent_at方法的具体用法?Python Message.sent_at怎么用?Python Message.sent_at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Message的用法示例。


在下文中一共展示了Message.sent_at方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: conversation

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import sent_at [as 别名]
def conversation(sender_id, receiver_id):
    """
    Show a conversation between two users.
    """
    form = ConversationForm()
    sender = User.query.filter_by(id=sender_id).first()
    receiver = User.query.filter_by(id=receiver_id).first()

    if not sender or not receiver:
        return no_perms("One of the users provided does not exist!")

    if sender.id != g.user.id:
        receiver = sender

    conv = Conversation.query.filter_by(
                    sender_id=sender_id
                ).filter_by(
                    receiver_id=receiver_id
                ).first() or \
           Conversation.query.filter_by(
                    sender_id=receiver_id
                ).filter_by(
                    receiver_id=sender_id
                ).first()

    if request.method == "POST":
        if not conv:
            if form.content.data and form.subject.data:
                conv = Conversation(sender_id=sender_id,
                                    receiver_id=receiver_id,
                                    subject=form.subject.data)
                db.session.add(conv)
                db.session.commit()

                msg = Message(conversation_id=conv.id,
                              sender=g.user.id,
                              content=form.content.data)
                db.session.add(msg)
                db.session.commit()
            else:
                return no_perms("You didn't input a subject or message!")

        elif form.content.data:
            msg = Message(conversation_id=conv.id,
                          sender=g.user.id,
                          content=form.content.data)
            db.session.add(msg)
            db.session.commit()
        else:
            return no_perms("You didn't input a message!")
    if conv:
        for msg in conv.messages:
            msg.sent_at = msg.sent_at.strftime("%b %d, %Y")
        conv.messages = Message.query.filter_by(conversation_id=conv.id).all()

    return render_template("conversation.html", form=form, conversation=conv,
                            receiver=receiver)
开发者ID:dean,项目名称:Organization-File-Sharer,代码行数:59,代码来源:controllers.py


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