예제 #1
0
def message_ex_old(uid, fid, eid):
    if current_user.id == int(eid):
        m = Message()
        ums = Message.query.filter(Message.uid == uid, Message.fid == fid,
                                   Message.eid == eid).order_by(
                                       Message.timestamp)
        eicon = User.query.filter(User.id == int(eid)).first().icon
        uicon = User.query.filter(User.id == int(uid)).first().icon
        content = request.form.get('text')
        if request.method == 'POST' and content:
            m.fid = int(fid)
            m.uid = int(uid)
            m.eid = int(eid)
            m.name = current_user.username  # 发消息的人
            m.timestamp = time.strftime("%Y-%m-%d %H:%M:%S")  # 发送时间
            f = UserFiles.query.filter(UserFiles.id == int(fid)).first()
            m.title = f.fileTitle
            m.content = content  # 消息内容
            m.expert = True  # 是专家发言
            m.save()
        return render_template('expertcenter/message_old.html',
                               ums=ums,
                               eicon=eicon,
                               uicon=uicon)
    else:
        return render_template('common/nocan.html', u=current_user.username)
예제 #2
0
def message(uid, fid, eid):
    if current_user.id == int(uid):
        # 判断对方是否存在
        if not User.query.filter(User.id == int(eid)).first():
            return render_template('common/nonentity.html')
        else:
            m = Message()
            ums = Message.query.filter(
                Message.uid == int(uid), Message.fid == int(fid),
                Message.eid == int(eid)).order_by(Message.timestamp)

            # 页面最多显示信息条数
            num = 30
            # off 偏移量 跳过这么多数据再去查询
            off = len(ums.all()) - num
            if off > 0:
                showums = ums.offset(off)
            else:
                showums = ums.offset(0)

            content = request.form.get('text')
            eicon = User.query.filter(User.id == int(eid)).first().icon
            uicon = User.query.filter(User.id == int(uid)).first().icon

            if request.method == 'POST' and content:
                m.fid = int(fid)
                m.uid = int(uid)
                m.eid = int(eid)
                m.name = current_user.username  # 发消息的人
                m.timestamp = time.strftime("%Y-%m-%d %H:%M:%S")  # 发送时间
                f = UserFiles.query.filter(UserFiles.id == int(fid)).first()
                m.title = f.fileTitle
                m.content = content  # 消息内容
                m.expert = False  # 不是专家发言
                m.save()
            return render_template('owncenter/message.html',
                                   ums=showums,
                                   eicon=eicon,
                                   uicon=uicon)
    else:
        return render_template('common/nocan.html', u=current_user.username)