def all(request): weibos = Weibo.all_json() # 下面是 weibo 的 all 路由只看到自己 weibo 的方法 # u = current_user(request) # weibos = Weibo.find_all(user_id=u.id) # weibos = [w.json() for w in weibos] weibo_list = [] for i in range(len(weibos)): weibo_list.append( dict(id=weibos[i]['id'], content=weibos[i]['content'], user_id=weibos[i]['user_id'], weibo_user=User.find_by(id=weibos[i]['user_id']).username)) weibos = weibo_list for weibo in weibos: comments = Comment.find_all(weibo_id=weibo['id']) comment_list = [] for i in range(len(comments)): comment_list.append( dict(id=comments[i].id, content=comments[i].content, user_id=comments[i].user_id, weibo_id=comments[i].weibo_id, comment_user=User.find_by( id=comments[i].user_id).username)) weibo['comments'] = comment_list log('allweibos', weibos) return json_response(weibos)
def all(request): weibos = Weibo.all_json() for weibo in weibos: # 用该函数拿到指定数据的字典 weibo = useful_weibos(weibo) # log('routes all 函数 weibos', weibos) return json_response(weibos)
def weibo_all(): weibos = Weibo.all_json() print('weibo all json = <{}>'.format(weibos)) for w in weibos: print('w=<{}>'.format(w)) u = User.find_one(id=w['user_id']) w['username'] = u.username print('weibo all json add username = <{}>'.format(weibos)) return jsonify(weibos)
def all(request): w = Weibo.all() for i in w: c = Comment.all(weibo_id=i.id) x = [t.json() for t in c] s = json.dumps(x, ensure_ascii=False) i.comment = s i.save(i.__dict__) weibos = Weibo.all_json() return json_response(weibos)
def all(request): weibos = Weibo.all_json() comments = Comment.all_json() for w in weibos: w['comments'] = [] for c in comments: if c['weibo_id'] == w['id']: w['comments'].append(c) return json_response(weibos)
def all(request): weibos = Weibo.all_json() for w in weibos: u = User.find_by(id=w['user_id']) w['username'] = u.username comments = Comment.find_all(weibo_id=w['id']) w['comments'] = [coment.json() for coment in comments] for c in w['comments']: u = User.find_by(id=c['user_id']) c['username'] = u.username return json_response(weibos)
def all(request): weibos = Weibo.all_json() for w in weibos: weibo_id = w['id'] comment = Comment.find_all(weibo_id=weibo_id) c = [c.json() for c in comment] w['comments'] = c # user_id = w['user_id'] # user = User.find_by(id=user_id) # uname = user.username # w['user'] = uname return json_response(weibos)
def all(): weibos = Weibo.all_json() comments = Comment.all_json() for weibo in weibos: weibo['comments'] = [] for comment in comments: if weibo['id'] == comment['weibo_id']: weibo['comments'].append(comment) log('这是一个微博', weibo, type(weibo)) weibo['username'] = User.one_for_id(id=weibo['user_id']).username log('这是U', User.one_for_id(id=weibo['user_id']).username) log('这是comm', weibos) return jsonify(weibos)
def all(): log('执行 all 函数') weibos = Weibo.all_json() # log('weibos---', weibos) for weibo in weibos: u = User.find_by(id=weibo['user_id']) weibo['username'] = u.username cs = Comment.find_all(weibo_id=weibo['id']) cs = [c.json() for c in cs] weibo['comments'] = [] for c in cs: u = User.find_by(id=c['user_id']) c['username'] = u.username weibo['comments'].append(c) # log('weibo---', weibos) return jsonify(weibos)
def add(request): form = request.json() u = current_user(request) w = Weibo(form) w.user_id = u.id w.save() weibos = w.all_json() weibo_list = [] for i in range(len(weibos)): weibo_list.append( dict(id=weibos[i]['id'], content=weibos[i]['content'], user_id=weibos[i]['user_id'], weibo_user=User.find_by(id=weibos[i]['user_id']).username)) weibos = weibo_list[-1] # 把创建好的 weibo 返回给浏览器 return json_response(weibos)
def all(request): user = current_user(request) # log('user is',u, 'user type is', type(u)) u = dict( id=user.id, username=user.username, ) weibos = Weibo.all_json() for weibo in weibos: weibo['username'] = User.find_by(id=weibo['user_id']).username comments = Comment.find_all(weibo_id=weibo['id']) cms = [] for m in comments: m.username = m.user().username cms.append(m.json()) weibo['comments'] = cms weibos.insert(0, u) log('weibo with comments', weibos) return json_response(weibos)
def all(request): weibos = Weibo.all_json() comments = Comment.all_json() weibo_all = [] for w in weibos: dvyyweibo = {} dvyyweibo['weibo'] = w list = [] u = User.find_by(id=w['user_id']) dvyyweibo['username'] = u.username for c in comments: if w['id'] == c['weibo_id']: list.append(c) dvyyweibo['comment'] = list log('w_c', dvyyweibo) weibo_all.append(dvyyweibo) log('qrbuweibo', weibo_all) form = { 'weibo_comment': weibo_all, } log('xnzidm', form) return json_response(form)
def all(request): weibos = Weibo.all_json() return json_response(weibos)
def all(): weibos = Weibo.all_json() return jsonify(weibos)
def all(request): weibos = Weibo.all_json() comments = Comment.all_json() all = (weibos, comments) return json_response(all)