Exemplo n.º 1
0
def user_videos(aid):
    """获取我的参赛视频(GET&LOGIN)

    :uri: activity/<string:aid>/videos
    :param type: 活动结束时参数(type=end)
    :param device: 终端ID
    :return: {'activity_videos': list, 'activity_config': Object}
    """
    user = request.authed_user
    type = request.values.get('type', None)

    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist
    sort = activity_config.sort

    activity_videos = ActivityVideo.user_compete_video_ids(aid, user._id)
    if not type:
        top_compete_videos = ActivityVideo.top_video_ids(aid, sort)
    videos = list()

    for activity_video in activity_videos:
        avid = str(activity_video['_id'])
        activity_video = ActivityVideo.get_one(avid)
        activity_video = activity_video.format()
        if type:
            videos.append(activity_video)
            continue

        if avid in top_compete_videos:
            top = top_compete_videos.index(avid)
            activity_video['top'] = top + 1
            videos.append(activity_video)
        else:
            continue
    return {
        'activity_videos': videos,
        'activity_config': activity_config.format()
    }
Exemplo n.º 2
0
def compete_videos(aid):
    """获取可参赛视频(GET&LOGIN)

    :uri: /activity/<string:aid>/compete_videos
    :param page: 页数
    :param nbr: 每页数量
    :return: {'videos': list, 'max_video': int, 'end_page': bool}
    """
    params = request.values
    user = request.authed_user
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist

    activity_videos = ActivityVideo.user_compete_video_ids(aid, str(user._id))
    avids = [a['video_id'] for a in activity_videos]

    videos = list()
    gids = GameActivity.game_activity_ids(aid)
    gids = [ObjectId(_gid) for _gid in gids]

    vids = Video.activity_video_ids(str(user._id), pagesize, page, gids,
                                    activity_config)
    vids = [vid for vid in vids]
    videos.extend([v.format() for v in Video.get_list(vids)])
    # 允许参赛最大视频数
    max_video = activity_config.max_video - len(avids)

    return {
        'videos': videos,
        'end_page': len(vids) != pagesize,
        'max_video': max_video
    }