Пример #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()
    }
Пример #2
0
def get_activity_video(vid):
    """获取参赛视频信息(GET&LOGIN)

    :uri: activity/video/<string:vid>
    :param device: 终端ID
    :return: {'activity_video': Object, 'activity_config': Object}
    """

    activity_video = ActivityVideo.get_activity_video_by_vid(vid)
    if not activity_video:
        return error.ActivityVideoNotExist
    activity_config = ActivityConfig.get_one(activity_video['activity_id'])
    top_compete_videos = ActivityVideo.top_video_ids(
        activity_video['activity_id'], activity_config.sort)

    top = top_compete_videos.index(str(activity_video['_id']))
    activity_video = activity_video.format()
    activity_video['top'] = top + 1

    return {
        'activity_video': activity_video,
        'activity_config': activity_config.format()
    }