Exemplo n.º 1
0
def all_playlists_for_project(
    project_id,
    for_client=False,
    page=1,
    sort_by="updated_at",
    task_type_id=None,
):
    """
    Return all playlists created for given project.
    """
    result = []
    query = Playlist.query.filter(Playlist.project_id == project_id)
    if for_client:
        query = query.filter(Playlist.for_client)

    if task_type_id is not None and len(task_type_id) > 0:
        query = query.filter(Playlist.task_type_id == task_type_id)

    query = query_utils.apply_sort_by(Playlist, query, sort_by)
    if page < 1:
        page = 1
    limit = 20
    offset = (page - 1) * limit
    query = query.limit(limit)
    query = query.offset(offset)
    playlists = query.all()
    for playlist in playlists:
        playlist_dict = build_playlist_dict(playlist)
        result.append(playlist_dict)
    return result
Exemplo n.º 2
0
def all_playlists_for_episode(project_id,
                              episode_id,
                              for_client=False,
                              sort_by="updated_at",
                              task_type_id=None):
    """
    Return all playlists created for given episode.
    """
    result = []
    query = Playlist.query
    if for_client:
        query = query.filter(Playlist.for_client)

    if task_type_id is not None and len(task_type_id) > 0:
        query = query.filter(Playlist.task_type_id == task_type_id)

    if episode_id == "main":
        query = (query.filter(Playlist.episode_id == None).filter(
            Playlist.project_id == project_id).filter(
                or_(Playlist.is_for_all is None,
                    Playlist.is_for_all == False)))
    elif episode_id == "all":
        query = (query.filter(Playlist.episode_id == None).filter(
            Playlist.project_id == project_id).filter(
                Playlist.is_for_all == True))
    else:
        query = query.filter(Playlist.episode_id == episode_id)

    query = query_utils.apply_sort_by(Playlist, query, sort_by)
    playlists = query.all()
    for playlist in playlists:
        playlist_dict = build_playlist_dict(playlist)
        result.append(playlist_dict)
    return result