コード例 #1
0
def del_video():
    form = IdForm().validate_for_api()
    video = Video.query.get_or_404(form.id.data, "找不到该视频")
    with db.auto_commit():
        db.session.delete(video)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #2
0
ファイル: tag.py プロジェクト: qw1004901361/pilipili
def del_tag():
    form = IdForm().validate_for_api()
    tag = Tag.query.filter(Tag.id == form.id.data).first_or_404("找不到该标签")
    with db.auto_commit():
        db.session.delete(tag)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #3
0
ファイル: comment.py プロジェクト: qw1004901361/pilipili
def del_comment():
    """删除评论"""
    form = IdForm().validate_for_api()
    comment = Comment.query.filter(Comment.id == form.id.data).first_or_404(description="找不到该评论")
    with db.auto_commit():
        db.session.delete(comment)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #4
0
ファイル: animation.py プロジェクト: qw1004901361/pilipili
def del_animation():
    """删除轮播图"""
    form = IdForm().validate_for_api()
    animation = Animation.query.get_or_404(form.id.data, "找不到该轮播图")
    with db.auto_commit():
        db.session.delete(animation)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #5
0
ファイル: comment.py プロジェクト: qw1004901361/pilipili
def del_by_video():
    """根据视频id删除该视频的所有评论"""
    form = IdForm().validate_for_api()
    comments = Comment.query.filter(Comment.video_id == form.id.data).all()
    with db.auto_commit():
        for i in comments:
            db.session.delete(i)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #6
0
ファイル: comment.py プロジェクト: qw1004901361/pilipili
def del_comment():
    form = IdForm().validate_for_api()
    comment = Comment.query.filter(Comment.id == int(form.id.data), Comment.user_id == current_user.id). \
        first_or_404(description="找不到该评论")
    with db.auto_commit():
        # for i in Comment.query.filter(Comment.root_id == comment.id):
        #     db.session.delete(i)
        # 软删除
        comment.status = 0
        db.session.add(comment)
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #7
0
ファイル: video.py プロジェクト: qw1004901361/pilipili
def change_videocol():
    """视频收藏(点击为添加,再点击为取消)"""
    form = IdForm().validate_for_api()
    with db.auto_commit():
        videocol = VideoCol.query.filter(VideoCol.user_id == current_user.id,
                                         VideoCol.video_id == form.id.data).first()
        if videocol:
            videocol.status = 0 if videocol.status else 1
        else:
            videocol = VideoCol(user_id=current_user.id, video_id=form.id.data)
        db.session.add(videocol)
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #8
0
def del_bangumi():
    form = IdForm().validate_for_api()
    bangumi = Bangumi.query.get_or_404(form.id.data, "找不到该番剧")
    with db.auto_commit():
        # 将状态设为0,下架
        if form.status.data == 1:
            bangumi.status = 1
        elif form.status.data == 0:
            bangumi.status = 0
        db.session.add(bangumi)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #9
0
def change_follow():
    """关注(点击为关注,再点击为取关)"""
    form = IdForm().validate_for_api()
    with db.auto_commit():
        follow = Follow.query.filter(Follow.user_id == current_user.id,
                                     Follow.follow_id == form.id.data).first()
        if follow:
            follow.status = 0 if follow.status else 1
        else:
            follow = Follow(user_id=current_user.id, follow_id=form.id.data)
        db.session.add(follow)
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #10
0
ファイル: auth.py プロジェクト: qw1004901361/pilipili
def del_module():
    """删除权限模块"""
    form = IdForm().validate_for_api()
    authmodule = AuthModule.query.filter(AuthModule.id == form.id.data). \
        first_or_404("找不到该权限模块")
    with db.auto_commit():
        # 先删除该模块的下所有接口
        for i in AuthApi.query.filter(AuthApi.module_id == authmodule.id).all():
            db.session.delete(i)
        # 再删除该模块
        db.session.delete(authmodule)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #11
0
def del_role():
    form = IdForm().validate_for_api()
    role = Role.query.filter(Role.id == form.id.data).first_or_404(description="找不到该角色")
    with db.auto_commit():
        # 删除该角色所拥有的权限关联
        for role_auth in RoleAuth.query.filter(RoleAuth.role_id == role.id).all():
            db.session.delete(role_auth)
        # 删除拥有该角色的用户关联
        for user_role in UserRole.query.filter(UserRole.role_id == role.id).all():
            db.session.delete(user_role)
        # 删除该角色
        db.session.delete(role)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #12
0
ファイル: bangumi.py プロジェクト: qw1004901361/pilipili
def change_bangumicol():
    """追番(点击为添加,再点击为取消)"""
    form = IdForm().validate_for_api()
    with db.auto_commit():
        bangumicol = BangumiCol.query.filter(
            BangumiCol.user_id == current_user.id,
            BangumiCol.bangumi_id == form.id.data).first()
        if bangumicol:
            bangumicol.status = 0 if bangumicol.status else 1
        else:
            bangumicol = BangumiCol(user_id=current_user.id,
                                    bangumi_id=form.id.data)
        db.session.add(bangumicol)
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #13
0
ファイル: video.py プロジェクト: qw1004901361/pilipili
def get_one():
    """通过视频id获取视频信息"""
    form = IdForm().validate_for_api()
    video = Video.query.filter(Video.id == form.id.data).first_or_404(description="找不到该视频资源")
    baseuser = BaseUser.query.filter(BaseUser.id == video.user_id).first()
    user = User.query.filter(User.id == baseuser.id).first() if baseuser else None
    # 子标签
    sub = Tag.query.filter(Tag.id == video.tag_id).first()
    # 父标签
    index = Tag.query.filter(Tag.id == sub.parent_id).first() if sub else None
    r = {
        "id": video.id,
        "name": video.name,
        "url": video.url,
        "logo": video.logo,
        "info": video.info,
        "user": {
            "id": baseuser.id,
            "name": baseuser.name,
            "face": user.face,
            "fannum": num_assign(Follow.query.filter(Follow.follow_id == baseuser.id).count()),
            "follownum": num_assign(Follow.query.filter(Follow.user_id == baseuser.id).count()),
            "info": user.info
        } if baseuser else None,
        "tag": {
            "id": index.id if index else None,
            "name": index.name if index else None,
            "sub_id": sub.id if sub else None,
            "sub_name": sub.name if sub else None
        },
        "is_bangumi": False,
        "playnum": num_assign(video.playnum),
        "commentnum": num_assign(video.commentnum),
        "colnum": num_assign(video.colnum),
        "release_time": video.release_time.strftime("%Y-%m-%d %H:%M:%S")
    }
    with db.auto_commit():
        viewlog = ViewLog.query.filter(ViewLog.user_id == current_user.id,
                                       ViewLog.video_id == video.id).first()
        if not viewlog:
            viewlog = ViewLog()
            viewlog.user_id = current_user.id
            viewlog.video_id = video.id
        viewlog.update_time = datetime.datetime.now()
        db.session.add(viewlog)
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)
コード例 #14
0
ファイル: user.py プロジェクト: qw1004901361/pilipili
def del_user():
    """删除用户"""
    form = IdForm().validate_for_api()
    user = User.query.get_or_404(form.id.data, "找不到该用户")
    admin = Admin.query.filter(Admin.id == user.id).first()
    if admin:
        return ReturnObj.get_response(ReturnEnum.ADMIN_DEL_ERROR.value,
                                      "该用户也是管理员,不能删除")
    with db.auto_commit():
        # 删除用户的角色关联
        user_role = UserRole.query.filter(UserRole.user_id == user.id).all()
        for i in user_role:
            db.session.delete(i)
        # 删除用户额外信息
        db.session.delete(user)
        # 删除用户基本信息
        baseuser = BaseUser.query.filter(BaseUser.id == user.id).first()
        db.session.delete(baseuser)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #15
0
def del_admin():
    """删除管理员"""
    form = IdForm().validate_for_api()
    baseuser = BaseUser.query.join(Admin, Admin.id == BaseUser.id).filter(Admin.id == form.id.data). \
        first_or_404(description="找不到该用户")
    with db.auto_commit():
        # 删除管理员关联的角色
        for user_role in UserRole.query.filter(
                UserRole.user_id == baseuser.id).all():
            db.session.delete(user_role)
        # 删除管理员额外信息
        admin = Admin.query.filter(Admin.id == baseuser.id).first()
        if admin:
            db.session.delete(admin)
            # 如果管理员还有用户的角色,删除
            user = User.query.filter(User.id == baseuser.id).first()
            if user:
                db.session.delete(user)
        # 删除基本信息
        db.session.delete(baseuser)
    write_oplog()
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
コード例 #16
0
ファイル: bangumi.py プロジェクト: qw1004901361/pilipili
def get_one():
    """通过bangumi的id获取信息"""
    form = IdForm().validate_for_api()
    bangumi = Bangumi.query.filter(Bangumi.id == form.id.data, Bangumi.status == 1). \
        first_or_404(description="找不到该番剧")
    videos = [{
        "video_id": i.video_id,
        "piece": i.piece
    } for i in Episode.query.filter(Episode.bangumi_id == bangumi.id).all()]
    episodes = []
    for i in videos:
        video = Video.query.filter(Video.id == i["video_id"]).first()
        episode = {
            "id": video.id,
            "piece": i["piece"],
            "name": video.name,
            "logo": video.logo,
            "is_bangumi": True
        }
        episodes.append(episode)
    r = {
        "id": bangumi.id,
        "name": bangumi.name,
        "logo": bangumi.logo,
        "info": bangumi.info,
        "playnum": num_assign(bangumi.playnum),
        "commentnum": num_assign(bangumi.commentnum),
        "colnum": num_assign(bangumi.colnum),
        "fannum": num_assign(bangumi.fannum),
        "grade": bangumi.grade,
        "voice_actors": bangumi.voice_actors,
        "staff": bangumi.staff,
        "episodes": episodes,
        "is_finish": bangumi.is_finish,
        "start_date": bangumi.start_date.strftime("%Y-%m-%d"),
        "update_time": bangumi.update_time.strftime("%H:%M:%S"),
        "update_weekday": bangumi.update_weekday
    }
    return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success", data=r)