Exemplo n.º 1
0
def index():
    u = current_user()
    # 这里是游客查看全部weibo
    if u is None:
        # 这里是全部用户的索引
        user_list = User.query.all()
        all_weibo = Weibo.query.filter_by(hidden=0).all()
        fix_all_weibo = User.change_uid_to_uname(User, all_weibo)
        # fix_all_weibo = copy.deepcopy(all_weibo)
        # for ws in fix_all_weibo:
        #     wu = User.query.filter_by(id=ws.user_id).first()
        #     ws.user_id = wu.username
        fix_ws_comment = Weibo.inser_comment_to_weibo(Weibo, fix_all_weibo)
        return render_template('timeline.html', users=user_list, weibos=fix_ws_comment)
    else:
        # return redirect('/weibo/timeline/{}'.format(u.username))
        # 上面是直接写网址,下面是url_for带参数的写法
        return redirect(url_for('.timeline_view', username=u.username))
Exemplo n.º 2
0
def timeline_view(username):
    u = User.query.filter_by(username=username).first()
    if u is None:
        # abort(404)
        return '查无此人'
    else:
        # 这里是全部用户的索引
        us = User.query.all()
        # 这里是自己查看自己的weibo
        # ws = Weibo.query.filter_by(user_id=u.id).all()
        ws = u.weibos()
        # 这里把ID显示成用户名
        fix_ws = User.change_uid_to_uname(User, ws)
        # fix_ws = copy.deepcopy(ws)
        # for fws in fix_ws:
        #     wu = User.query.filter_by(id=fws.user_id).first()
        #     fws.user_id = wu.username
        # 下面是把当前微博的comment_list动态添加进每个weibo字典里
        #     fws.cs = Comment.query.filter_by(weibo_id=fws.id).all()   (旧)下面是抽出来放到weibo model里了
        fix_ws_comment = Weibo.inser_comment_to_weibo(Weibo, fix_ws)
        return render_template('timeline.html', users=us, weibos=fix_ws_comment)