Ejemplo n.º 1
0
def user_playlist(request, user_id):
    playlist = None
    if user_id is "master":
        playlist = Playlist.get_or_create_master_playlist()
    else:
        playlist = Playlist.get_or_create(user_id)
    items = PlaylistItem.objects.filter(playlist=playlist, active=True).order_by('position')
        
    playlist_html = render_to_string('playlists/partial/playlist.html',
        {
            'items' : items,
        },
         context_instance=RequestContext(request)
    )
    if request.is_ajax():
        output = {
            'html' : playlist_html,
        }
        return HttpResponse(simplejson.dumps(output))
    else:
        return render_to_response('playlists/user_playlist.html',
        {
            'playlist_html' : playlist_html,
        },
        context_instance=RequestContext(request))
Ejemplo n.º 2
0
def remove_item_from_master_playlist(request, item_id):
    item = PlaylistItem.objects.get(id=item_id)
    owner_playlist = Playlist.get_or_create(item.owner.id)

    owner_playlist.add_item(item)

    return master_playlist(request, internal=True)
Ejemplo n.º 3
0
def remove_item_from_master_playlist(request, item_id):
    item = PlaylistItem.objects.get(id=item_id)
    owner_playlist = Playlist.get_or_create(item.owner.id)
    
    owner_playlist.add_item(item)

    return master_playlist(request, internal=True)
Ejemplo n.º 4
0
def master_playlist(request, internal=False):
    playlist = Playlist.get_or_create_master_playlist()
    items = PlaylistItem.objects.filter(playlist=playlist, active=True).order_by('position')
    playlist_html = render_to_string('playlists/partial/mini_playlist.html',
        {
            'items' : items,
        },
         context_instance=RequestContext(request)
    )
    
    playlists = Playlist.objects.filter(user__is_active=True).annotate(num_items=Count('playlistitem'))
    playlists = playlists.filter(num_items__gt=0).order_by('name')
    playlists_html = render_to_string('playlists/partial/playlists_list.html',
        {
            'playlists' : playlists,
        },
         context_instance=RequestContext(request)
    )

    if request.is_ajax() or internal:
        output = {
            'html' : playlist_html,
        }
        return HttpResponse(simplejson.dumps(output))
    else:
        return render_to_response('playlists/master_playlist.html',
        {
            'playlists':playlists_html,
            'master_playlist':playlist_html,
        },
        context_instance=RequestContext(request))
Ejemplo n.º 5
0
def user_playlist(request, user_id):
    playlist = None
    if user_id is "master":
        playlist = Playlist.get_or_create_master_playlist()
    else:
        playlist = Playlist.get_or_create(user_id)
    items = PlaylistItem.objects.filter(playlist=playlist,
                                        active=True).order_by('position')

    playlist_html = render_to_string('playlists/partial/playlist.html', {
        'items': items,
    },
                                     context_instance=RequestContext(request))
    if request.is_ajax():
        output = {
            'html': playlist_html,
        }
        return HttpResponse(simplejson.dumps(output))
    else:
        return render_to_response('playlists/user_playlist.html', {
            'playlist_html': playlist_html,
        },
                                  context_instance=RequestContext(request))
Ejemplo n.º 6
0
def master_add_playlist(request, user_id):
    playlist = Playlist.get_or_create(user_id)
    items = playlist.playlistitem_set.filter(active=True).order_by('position')

    playlist_html = render_to_string(
        'playlists/partial/master_add_playlist.html', {
            'items': items,
        },
        context_instance=RequestContext(request))

    output = {
        'html': playlist_html,
    }
    return HttpResponse(simplejson.dumps(output))
Ejemplo n.º 7
0
def master_add_playlist(request, user_id):
    playlist = Playlist.get_or_create(user_id)
    items = playlist.playlistitem_set.filter(active=True).order_by('position')
    
    playlist_html = render_to_string('playlists/partial/master_add_playlist.html',
        {
            'items' : items,
        },
         context_instance=RequestContext(request)
    )
    
    output = {
        'html' : playlist_html,
    }
    return HttpResponse(simplejson.dumps(output))
Ejemplo n.º 8
0
def song_detail(request, song_id, innerCall=False):
    song = Song.objects.get(id=song_id)
    try:
        rating = Rating.objects.get(user=request.user, song=song_id)
    except:
        rating = "unknown"

    value = ""
    if rating is not "unknown":
        value = rating.value.lower()
    else:
        value = rating

    song_detail_html = render_to_string(
        "songs/partial/song_detail.html",
        {"song": song, "rating": value, "in_playlist": Playlist.get_or_create(request.user.id).contains_song(song.id)},
        context_instance=RequestContext(request),
    )

    if request.is_ajax() or innerCall:
        output = {"html": song_detail_html}
        return HttpResponse(simplejson.dumps(output))
    else:
        pass
Ejemplo n.º 9
0
def move_item_down(request, item_id):
    playlist = Playlist.get_or_create(request.user.id)
    item = PlaylistItem.objects.get(id=item_id)
    item.move_down()

    return user_playlist(request, request.user.id)
Ejemplo n.º 10
0
def add_song_to_playlist(request, song_id):
    playlist = Playlist.get_or_create(request.user.id)
    playlist.add_song(Song.objects.get(id=song_id), request.user)

    return song_detail(request, song_id, True)
Ejemplo n.º 11
0
def remove_item_from_playlist(request, item_id):
    playlist = Playlist.get_or_create(request.user.id)
    playlist.remove_item(PlaylistItem.objects.get(id=item_id))

    return user_playlist(request, request.user.id)
Ejemplo n.º 12
0
def add_song_to_playlist(request, song_id):
    playlist = Playlist.get_or_create(request.user.id)
    playlist.add_song(Song.objects.get(id=song_id), request.user)
    
    return song_detail(request, song_id, True)
Ejemplo n.º 13
0
def move_item_down_on_master_list(request, item_id):
    playlist = Playlist.get_or_create_master_playlist()
    item = PlaylistItem.objects.get(id=item_id)
    item.move_down()

    return master_playlist(request, internal=True)
Ejemplo n.º 14
0
def move_item_down_on_master_list(request, item_id):
    playlist = Playlist.get_or_create_master_playlist()
    item = PlaylistItem.objects.get(id=item_id)
    item.move_down()

    return master_playlist(request, internal=True)
Ejemplo n.º 15
0
def add_item_to_master_playlist(request, item_id):
    playlist = Playlist.get_or_create_master_playlist()
    item = PlaylistItem.objects.get(id=item_id)
    playlist.add_item(item)

    return master_playlist(request, internal=True)
Ejemplo n.º 16
0
def add_item_to_master_playlist(request, item_id):
    playlist = Playlist.get_or_create_master_playlist()
    item = PlaylistItem.objects.get(id=item_id)
    playlist.add_item(item)
        
    return master_playlist(request, internal=True)
Ejemplo n.º 17
0
def remove_item_from_playlist(request, item_id):
    playlist = Playlist.get_or_create(request.user.id)
    playlist.remove_item(PlaylistItem.objects.get(id=item_id))

    return user_playlist(request, request.user.id)
Ejemplo n.º 18
0
def move_item_down(request, item_id):
    playlist = Playlist.get_or_create(request.user.id)
    item = PlaylistItem.objects.get(id=item_id)
    item.move_down()

    return user_playlist(request, request.user.id)