Exemplo n.º 1
0
def index(request):
    log('routes weibo index')
    u = current_user(request)

    weibos = Weibo.all(user_id=u.id)

    return html_response('weibo_index.html', weibos=weibos, user=u)
Exemplo n.º 2
0
def all_weibo(request):
    """
    返回所有 todo
    """
    ms = Weibo.all()  # 单纯地从Weibo.txt中生成Weibo对象
    # 要转换为 dict 格式才行
    data = [m.json() for m in ms]  # 把属于Weibo对象的所有comments加入到Weibo
    return json_response(data)
Exemplo n.º 3
0
def index(request):
    """
    weibo 页的路由函数, 返回 weibo 页面
    """
    weibos = Weibo.all()
    # 替换模板文件中的标记字符串
    body = SeizerTemplate.render('weibo_index0.html')
    return html_response(body)
Exemplo n.º 4
0
def index():
    """
    weibo 首页的路由函数
    """
    u = current_user()
    weibos = Weibo.all(user_id=u.id)
    # 替换模板文件中的标记字符串
    return render_template('weibo_index.html', weibos=weibos, user=u)
Exemplo n.º 5
0
def all_weibo(request):
    """
    返回所有 weibo
    """
    ms = Weibo.all()
    # 要转换为 dict 格式才行
    data = [m.json() for m in ms]
    return json_response(data)
Exemplo n.º 6
0
def index(request):
    """
    weibo 首页的路由函数
    """
    u = current_user(request)
    weibos = Weibo.all(user_id=u.id)
    # 替换模板文件中的标记字符串
    return html_response('weibo_index.html', weibos=weibos, user=u)
Exemplo n.º 7
0
def index(request):
    author_id = int(request.query.get('user_id', -1))
    user = current_user(request)
    if author_id == -1:
        author_id = user.id

    weibos = Weibo.all()
    body = template('weibo_index.html', weibos=weibos, user=user)
    return http_response(body)
Exemplo n.º 8
0
def all(request):
    """
    返回所有 weibo
    """
    ms = Weibo.all()
    # 要转换为 dict 格式才行
    ms = [m.json() for m in ms]
    print(ms)
    return json_response(ms)
Exemplo n.º 9
0
def index(request):
    """
    weibo 页的路由函数, 返回 weibo 页面
    """
    u = current_user(request)
    weibos = Weibo.all()
    # 替换模板文件中的标记字符串
    body = HtmlTemplate.render('weibo_index.html', username=u.username)
    return html_response(body)
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
def index(request):

    # if 'id' in request.query:
    #   user_id = int(request.query['id'])
    #   u = User.one(id=user_id)
    # else:
    #   u = current_user(request)

    weibos = Weibo.all()
    return html_response('weibo_index.html', weibos=weibos)
def index(request):
    """
    weibo 首页的路由函数
    """
    if 'user_id' in request.query:
        user_id = int(request.query['user_id'])
    else:
        u = current_user(request)
        user_id = u.id
    weibos = Weibo.all(user_id=user_id)
    return html_response('weibo_index.html', weibos=weibos)
Exemplo n.º 13
0
def index(request):
    """
    todo 首页的路由函数
    """
    if 'user_id' in request.query:
        user_id = int(request.query['user_id'])
        user = User.one(id=user_id)
    else:
        user = current_user(request)
    weibos = Weibo.all(user_id=user.id)
    return html_response('weibo_index.html', weibos=weibos, user=user)
Exemplo n.º 14
0
def all(request):
    Weibos = Weibo.all()
    w = []
    for weibo in Weibos:
        c = {'comments': [comment.json() for comment in weibo.comments()]}
        log('F_weibo_all{}'.format(c))
        c['weibo'] = weibo.json()
        # w.append({weibo.id: c})
        w.append(c)

    # log('<F aip_weibo all> Weibos, comments', w)
    return json_response(w)
Exemplo n.º 15
0
def index():
    u = current_user()
    weibos = Weibo.all(user_id=u.id)
    # weibos = Weibo.find_all()
    # 替换模板文件中的标记字符串
    log('所有微博', weibos)
    # body = GuaTemplate.render('weibo_index.html', weibos=weibos, user=u)
    return render_template(
        'weibo_index.html',
        weibos=weibos,
        user=u,
    )
Exemplo n.º 16
0
def weibo_index(request):
    """
    weibo 首页的路由函数
    """
    data = request.query
    if 'user_id' in data:
        u = User.one(id=int(data['user_id']))
    else:
        u = current_user(request)
    weibos = Weibo.all(user_id=u.id)
    body = JinjaTemplate.render('weibo_index_ajax.html', weibos=weibos, user=u)
    return html_response(body)
Exemplo n.º 17
0
def index(request):
    """
    weibo 首页的路由函数
    """
    if 'id' in request.query:
        user_id = int(request.query['id'])
        u = User.one(id=user_id)
    else:
        u = current_user(request)

    weibos = Weibo.all(user_id=u.id)
    # 替换模板文件中的标记字符串
    return html_response('weibo_index.html', weibos=weibos, user=u)
Exemplo n.º 18
0
def index(request):
    """
    weibo 首页的路由函数
    """
    if 'user_id' in request.query:
        user_id = int(request.query['user_id'])
    else:
        u = current_user(request)
        user_id = u.id
    weibos = Weibo.all(user_id=user_id)
    for w in weibos:
        print('w.dict', w.__dict__)
    # 替换模板文件中的标记字符串
    return html_response('weibo_index.html', weibos=weibos)
Exemplo n.º 19
0
def all():
    """
    weibo 首页的路由函数
    """
    weibo_list = []
    weibos = Weibo.all()
    for weibo in weibos:
        form = weibo.json()
        comments = Comment.find_all(weibo_id=int(form['id']))
        comments = [comment.json() for comment in comments]
        form['comments'] = comments
        weibo_list.append(form)
    log('json weibo_list in weibo all', weibo_list)
    return jsonify(weibo_list)
Exemplo n.º 20
0
def index():
    """
    weibo 首页的路由函数
    """
    # u = current_user()
    # weibos = Weibo.all(user_id=u.id)
    # # 替换模板文件中的标记字符串
    # return html_response('weibo_index.html', weibos=weibos, user=u)
    if 'id' in request.args:
        user_id = int(request.args['id'])
        u = User.one(id=user_id)
    else:
        u = current_user()

    weibos = Weibo.all(user_id=u.id)
    return render_template('weibo_index.html', weibos=weibos, user=u)
Exemplo n.º 21
0
def all(request):
    # weibos = Weibo.all_json()
    weibos = Weibo.all()
    ws = []
    for weibo in weibos:
        comments = weibo.comments()
        list = []
        for comment in comments:
            comment.username = comment.user().username
            list.append(comment.json())
        w = dict(
            content=weibo.content,
            created_time=weibo.created_time,
            updated_time=weibo.updated_time,
            id=weibo.id,
            comments=list,
        )
        ws.append(w)
    return json_response(ws)
Exemplo n.º 22
0
def all():
    weibos = []
    ws = Weibo.all()
    for w in ws:
        # 获得每个weibo对应的评论
        cs = w.comments()
        comments = []
        w_username = w.user().username
        # 序列化comment并为每个评论添加用户名
        for c in cs:
            username = c.user().username
            c = c.json()
            c['username'] = username
            comments.append(c)

        w = w.json()
        # 将评论插入到对应的微博字典中
        w['comments'] = comments
        w['username'] = w_username
        weibos.append(w)

    return jsonify(weibos)
Exemplo n.º 23
0
def all(request):
    weibo_list = Weibo.all()
    # 要转换为 dict 格式才行
    weibos = [t.json() for t in weibo_list]
    return json_response(weibos)
Exemplo n.º 24
0
def all_weibo(request):
    ms = Weibo.all()
    data = [m.json() for m in ms]
    return json_response(data)
Exemplo n.º 25
0
def index(request):
    u = current_user(request)
    weibos = Weibo.all(user_id=u.id)
    log('weibos', weibos)
    return html_response('weibo_index.html', weibos=weibos, user=u)
Exemplo n.º 26
0
def all_weibo(request):
    weibo_list = Weibo.all()
    weibos = [weibo.json() for weibo in weibo_list]
    return json_response(weibos)
Exemplo n.º 27
0
def index(request):
    u = current_user(request)
    weibos = Weibo.all()
    body = template('weibo_index.html', weibos=weibos, user=u)
    return http_response(body)