示例#1
0
文件: like.py 项目: xzFunter/1nfinite
def like():
    if is_login():
        user = get_login_user()
        return render_template('/like.html',
                               login=True,
                               admin=is_admin(),
                               username=user.username,
                               channel_name=user.channel_name)
    else:
        return redirect('/')
示例#2
0
def person_info():
    if is_login():
        user = get_login_user()
        avatar = user.avatar
        if avatar == 0:
            avatar = '/web/static/asset/chisec/avator.jpg'
        return render_template('person_info.html',
                               username=user.username,
                               avatar=avatar,
                               channel_name=user.channel_name,
                               create_time=user.create_time)
    else:
        return redirect('/')
示例#3
0
def index():
    if is_login():
        user = get_login_user()
        return render_template('/index.html',
                               login=True,
                               admin=is_admin(),
                               username=user.username,
                               channel_name=user.channel_name)
    else:
        return render_template('/index.html',
                               login=False,
                               admin=False,
                               username=None)
示例#4
0
def person_about():
    return render_template('person_about.html', login=is_login())
示例#5
0
def person_like():
    return render_template('person_like.html', login=is_login())
示例#6
0
def person_follow():
    return render_template('person_follow.html', login=is_login())
示例#7
0
def discovery():
    if not is_login():
        return redirect('/web')
    return render_template('/discovery.html',
                           login=is_login(),
                           admin=is_admin())
示例#8
0
def list_follow():
    user = get_login_user()
    page = request.values.get('page', default=1, type=int)
    db = DBSession()
    try:
        # 取本人订阅的频道主的最近消息
        query = db.query(Channel) \
            .join(Follow, Channel.user_id == Follow.channel_user_id) \
            .filter(Follow.user_id == user.id)

        count = query.count()
        channels = query.order_by(Channel.id.desc()).limit(10).offset((page - 1) * 10).all()
        is_end = (page * 10 >= count)

        data = []
        for channel in channels:
            user = db.query(User).filter(User.id == channel.user_id).first()
            avatar = None
            if user.avatar != '0':
                # image = db.query(Image).filter(Image.id == user.avatar_id).first()
                avatar = user.avatar
            if user.avatar == '0':
                avatar = '/web/static/asset/chisec/avator.jpg'
            media = None
            if channel.image_id is not None and channel.image_id is not '':
                image = db.query(Image).filter(Image.id == channel.image_id).first()
                media = image.url

            like_count = db.query(Like) \
                .filter(Like.channel_id == channel.id) \
                .count()
            if is_login():
                liked = db.query(Like) \
                    .filter(Like.channel_id == channel.id, Like.user_id == user.id) \
                    .count()
                if liked > 0:
                    liked = True
                else:
                    liked = False
            else:
                liked = 0

            data.append({
                'id': channel.id,
                'user_id': user.id,
                'content': channel.content,
                'channel_name': user.channel_name,
                'username': user.username,
                'avatar': avatar,
                'media': media,
                'like_count': like_count,
                'liked': liked,
                'count': count,
                'create_time': pd_time(channel.create_time)
            })

        db.close()
        if is_end:
            return jsonify({
                'status': 2,
                'message': '没有更多消息了',
                'data': data
            })
        else:
            return jsonify({
                'status': 0,
                'message': 'ok',
                'data': data
            })
    except Exception as e:
        db.close()
        return jsonify({
            'status': 1,
            'message': '拉取失败',
            'error_message': str(e)
        })