コード例 #1
0
def list_admin():
    """分页列出管理员的信息"""
    form = PageForm().validate_for_api()
    page_data = BaseUser.query.join(Admin, Admin.id == BaseUser.id)
    if form.q.data:
        page_data = page_data.filter(
            or_(BaseUser.id == form.q.data,
                BaseUser.name.like("%" + form.q.data + "%")))
    page_data = page_data.order_by(BaseUser.create_time.desc()). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(form.pagesize.data))
    admins = []
    for i in page_data.items:
        roles = []
        for j in Role.query.join(UserRole, UserRole.role_id == Role.id).filter(
                UserRole.user_id == i.id).all():
            role = {"id": j.id, "name": j.name}
            roles.append(role)
        admin = {
            "id": i.id,
            "account": i.account,
            "name": i.name,
            "gender": i.gender,
            "roles": roles
        }
        admins.append(admin)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "admins": admins
    }
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #2
0
def get_view_history():
    """获取观看历史记录"""
    form = PageForm().validate_for_api()
    page_data = ViewLog.query.filter(
        ViewLog.user_id == current_user.id).order_by(
            ViewLog.update_time.asc()).paginate(error_out=False,
                                                page=int(form.page.data),
                                                per_page=20)
    videos = []
    for i in page_data.items:
        video = Video.query.filter(Video.id == i.video_id).frist()
        baseuser = BaseUser.query.filter(BaseUser.id == video.user_id).first()
        tag = Tag.query.filter(Tag.id == video.tag_id).first()
        tmp = {
            "id": video.id,
            "name": video.name,
            "logo": video.logo,
            "user": {
                "id": baseuser.id,
                "name": baseuser.name,
            } if baseuser else None,
            "tag": tag.name if tag else None,
            "time": i.update_time.strftime("%Y-%m-%d %H:%M:%S")
        }
        videos.append(tmp)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "videos": videos
    }
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #3
0
ファイル: user.py プロジェクト: qw1004901361/pilipili
def list_user():
    """列出用户"""
    form = PageForm().validate_for_api()
    page_data = BaseUser.query
    if form.q.data:
        page_data = page_data.join(User, BaseUser.id == User.id). \
            filter(or_(BaseUser.id == form.q.data, BaseUser.name.like("%" + form.q.data + "%")))
    page_data = page_data.order_by(BaseUser.create_time.desc()). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(form.pagesize.data))
    users = []
    for i in page_data.items:
        user = User.query.filter(User.id == i.id).first()
        one = {
            "id": i.id,
            "name": i.name,
            "account": i.account,
            "gender": i.gender,
            "email": user.email if user else None,
            "phone": user.phone if user else None,
            "info": user.info if user else None,
            "face": user.face if user else None,
            "create_time": i.create_time.strftime("%Y-%m-%d %H:%M:%S"),
        }
        users.append(one)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "users": users
    }
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #4
0
def get_com_history():
    """获取评论记录"""
    form = PageForm().validate_for_api()
    page_data = Comment.query.filter(Comment.user_id == current_user.id). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(current_app.config["PER_PAGE_COM"]))
    comments = []
    for i in page_data.items:
        video = Video.query.filter(Video.id == i.video_id).frist()
        baseuser = BaseUser.query.filter(BaseUser.id == video.user_id).first()
        tag = Tag.query.filter(Tag.id == video.tag_id).first()
        tmp = {
            "id": video.id,
            "name": video.name,
            "logo": video.logo,
            "user": {
                "id": baseuser.id,
                "name": baseuser.name,
            } if baseuser else None,
            "tag": tag.name if tag else None,
            "time": i.update_time.strftime("%Y-%m-%d %H:%M:%S")
        }
        comments.append(tmp)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "comments": comments
    }
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #5
0
def get_bangumicol():
    """获取番剧订阅"""
    form = PageForm().validate_for_api()
    page_data = BangumiCol.query.filter(
        BangumiCol.user_id == current_user.id).order_by(
            BangumiCol.create_time.desc()).paginate(error_out=False,
                                                    page=int(form.page.data),
                                                    per_page=15)
    bangumis = []
    for i in page_data.items:
        bangumi = Bangumi.query.filter(Bangumi.id == i.bangumi_id).first()
        tag = Tag.query.filter(Tag.id == bangumi.tag_id).first()
        tmp = {
            "id": bangumi.id,
            "name": bangumi.name,
            "info": bangumi.info,
            "logo": bangumi.logo,
            "area": bangumi.area,
            "tag": tag.name if tag else "未知"
        }
        bangumis.append(tmp)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "bangumis": bangumis,
        "total": page_data.total
    }
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #6
0
def get_my_video():
    """获取自己上传的视频"""
    form = PageForm().validate_for_api()
    page_data = Video.query.filter(Video.user_id == current_user.id).order_by(
        Video.create_time.desc()).paginate(error_out=False,
                                           page=int(form.page.data),
                                           per_page=20)
    videos = []
    for i in page_data.items:
        baseuser = BaseUser.query.filter(BaseUser.id == i.user_id).first()
        tmp = {
            "id": i.id,
            "name": i.name,
            "playnum": i.playnum,
            "colnum": i.colnum,
            "logo": i.logo,
            "user": {
                "id": baseuser.id,
                "name": baseuser.name,
            },
            "release_time": i.release_time.strftime("%Y-%m-%d %H:%M:%S"),
            "length": i.length,
        }
        videos.append(tmp)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "videos": videos,
        "total": page_data.total
    }
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #7
0
ファイル: animation.py プロジェクト: qw1004901361/pilipili
def list_animation():
    """列出轮播图"""
    form = PageForm().validate_for_api()
    page_data = Animation.query
    if form.tag_id.data == -1:
        pass
    else:
        page_data = page_data.filter(Animation.tag_id == form.tag_id.data)
    if form.q.data:
        page_data = page_data.filter(
            or_(Animation.id == form.q.data,
                Animation.name.like("%" + form.q.data + "%")))
    page_data = page_data.order_by(Animation.create_time.desc()). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(form.pagesize.data))
    animations = []
    for i in page_data.items:
        tag = Tag.query.filter(Tag.id == i.tag_id).first()
        animation = {
            "id": i.id,
            "tag": tag.name if tag else "未知",
            "name": i.name,
            "logo": i.logo,
            "url": i.url
        }
        animations.append(animation)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "animations": animations
    }
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #8
0
ファイル: auth.py プロジェクト: qw1004901361/pilipili
def list_module():
    """列出权限模块"""
    form = PageForm().validate_for_api()
    page_data = AuthModule.query
    if form.q.data:
        page_data = page_data.filter(or_(AuthModule.id == form.q.data, AuthModule.name.like("%" + form.q.data + "%")))
    page_data = page_data.order_by(AuthModule.create_time.desc()). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(form.pagesize.data))
    modules = []
    for i in page_data.items:
        module = {
            "id": i.id,
            "name": i.name,
            "module": i.module,
            "create_time": i.create_time.strftime("%Y-%m-%d %H:%M:%S")
        }
        modules.append(module)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "modules": modules
    }
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #9
0
def list_video():
    form = PageForm().validate_for_api()
    page_data = Video.query
    if form.tag_id.data == -1:
        pass
    else:
        sub_tags = [
            i.id
            for i in Tag.query.filter(Tag.parent_id == form.tag_id.data).all()
        ]
        page_data = page_data.filter(
            or_(Video.tag_id == form.tag_id.data, Video.tag_id.in_(sub_tags)))
    if form.q.data:
        page_data = page_data.filter(
            or_(Video.id == form.q.data,
                Video.name.like("%" + form.q.data + "%")))
    page_data = page_data.order_by(Video.create_time.desc()). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(form.pagesize.data))
    videos = []
    for i in page_data.items:
        tag = Tag.query.filter(Tag.id == i.tag_id).first()
        video = {
            "id": i.id,
            "name": i.name,
            "logo": i.logo,
            "playnum": i.playnum,
            "commentnum": i.commentnum,
            "danmunum": i.danmunum,
            "colnum": i.colnum,
            "url": i.url,
            "info": i.info,
            "tag": {
                "id": tag.id if tag else "未知",
                "name": tag.name if tag else "未知",
            },
            "release_time": i.release_time.strftime("%Y-%m-%d %H:%M:%S"),
        }
        videos.append(video)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "videos": videos
    }
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #10
0
ファイル: tag.py プロジェクト: qw1004901361/pilipili
def list_tag():
    form = PageForm().validate_for_api()
    page_data = Tag.query
    if form.q.data:
        page_data = page_data.filter(or_(Tag.id == form.q.data, Tag.name.like("%" + form.q.data + "%")))
    page_data = page_data.filter(Tag.parent_id == 0).order_by(Tag.create_time.desc()). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(form.pagesize.data))
    tags = []
    for i in page_data.items:
        sub_tags = Tag.query.filter(Tag.parent_id == i.id).all()
        subs = []
        for j in sub_tags:
            sub = {
                "id": j.id,
                "name": j.name,
                "info": j.info,
                "create_time": j.create_time.strftime("%Y-%m-%d %H:%M:%S"),
            }
            subs.append(sub)
        tag = {
            "id": i.id,
            "name": i.name,
            "info": i.info,
            "children": subs,
            "create_time": i.create_time.strftime("%Y-%m-%d %H:%M:%S"),
            "total": len(sub_tags)
        }
        tags.append(tag)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "tags": tags,
    }
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #11
0
def list_role():
    """列出角色列表"""
    form = PageForm().validate_for_api()
    page_data = Role.query
    if form.q.data:
        page_data = page_data.filter(or_(Role.id == form.q.data, Role.name.like("%" + form.q.data + "%")))
    page_data = page_data.order_by(Role.create_time.desc()). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(form.pagesize.data))
    roles = []
    for i in page_data.items:
        auths = []
        for j in AuthModule.query.join(RoleAuth, RoleAuth.auth_id == AuthModule.id). \
                filter(RoleAuth.role_id == i.id).all():
            auth = {
                "id": j.id,
                "name": j.name,
                "module": j.module,
            }
            auths.append(auth)
        role = {
            "id": i.id,
            "name": i.name,
            "auths": auths,
            "create_time": i.create_time.strftime("%Y-%m-%d %H:%M:%S")
        }
        roles.append(role)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "roles": roles
    }
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #12
0
def list_bangumi():
    form = PageForm().validate_for_api()
    page_data = Bangumi.query
    if form.tag_id.data == -1:
        pass
    else:
        page_data = page_data.filter(Bangumi.tag_id == form.tag_id.data)
    if form.q.data:
        page_data = page_data.filter(
            or_(Bangumi.id == form.q.data,
                Bangumi.name.like("%" + form.q.data + "%")))
    page_data = page_data.order_by(Bangumi.create_time.desc()). \
        paginate(error_out=False, page=int(form.page.data), per_page=int(form.pagesize.data))
    bangumis = []
    for i in page_data.items:
        videos = [{
            "video_id": i.video_id,
            "piece": i.piece
        } for i in Episode.query.filter(Episode.bangumi_id == i.id).all()]
        episodes = []
        for j in videos:
            video = Video.query.filter(Video.id == j["video_id"]).first()
            episode = {
                "id": video.id,
                "piece": j["piece"],
                "name": video.name,
                "logo": video.logo,
                "url": video.url,
            } if video else None
            episodes.append(episode)
        tag = "国产" if i.tag_id == 1 else ("日漫" if i.tag_id == 2 else "其他")
        bangumi = {
            "id": i.id,
            "name": i.name,
            "logo": i.logo,
            "playnum": i.playnum,
            "commentnum": i.commentnum,
            "danmunum": i.danmunum,
            "colnum": i.colnum,
            "fannum": i.fannum,
            "status": i.status,
            "voice_actors": i.voice_actors,
            "staff": i.staff,
            "score": i.score,
            "info": i.info,
            "start_date": i.start_date.strftime("%Y-%m-%d"),
            "update_time": i.update_time.strftime("%H:%M:%S"),
            "update_weekday": i.update_weekday,
            "is_finish": i.is_finish,
            "season": i.season,
            "area": i.area,
            "new_piece": i.new_piece,
            "tag": tag,
            "episodes": episodes,
            "grade": i.grade,
        }
        bangumis.append(bangumi)
    r = {
        "has_next": page_data.has_next,
        "has_prev": page_data.has_prev,
        "pages": page_data.pages,
        "page": page_data.page,
        "total": page_data.total,
        "bangumis": bangumis
    }
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)