Exemplo n.º 1
0
def bootstrap(request):
    # Don't create dummy playlist tracks if playlist tracks already exist!
    pl_tracks = PlaylistTrack.all().fetch(1)
    if len(pl_tracks) > 0:
        return HttpResponse(status=404)

    playlist = ChirpBroadcast()

    minutes = 0
    tracks = Track.all().fetch(100)
    for track in tracks:
        pl_track = PlaylistTrack(
            playlist=playlist,
            selector=request.user,
            established=datetime.now() - timedelta(minutes=minutes),
            artist=track.album.album_artist,
            album=track.album,
            track=track,
        )
        pl_track.put()
        if minutes > 0 and minutes % 25 == 0:
            pl_break = PlaylistBreak(playlist=playlist, established=datetime.now() - timedelta(minutes=minutes - 1))
            pl_break.put()
        minutes += 5

    return HttpResponseRedirect("/playlists/")
Exemplo n.º 2
0
    def test_add_track_linked_to_library(self, fake_tq):
        fake_tq.is_a_stub()
        stevie = Artist.all().filter("name =", "Stevie Wonder")[0]
        talking_book = Album.all().filter("title =", "Talking Book")[0]
        sunshine = Track.all().filter("title =", "You Are The Sunshine Of My Life")[0]

        resp = self.client.post(reverse('playlists_add_event'), {
            'artist_key': stevie.key(),
            'artist': stevie.name,
            'song': "You Are The Sunshine Of My Life",
            'song_key': sunshine.key(),
            'album_key': talking_book.key(),
            'album': talking_book.title,
            'label': "Tamla",
            'label_key': 'Blah'
        })

        self.assertNoFormErrors(resp)
        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Stevie Wonder")
        self.assertEquals(tracks[0].artist.key(), stevie.key())
        self.assertEquals(tracks[0].album_title, "Talking Book")
        self.assertEquals(tracks[0].album.key(), talking_book.key())
        self.assertEquals(tracks[0].track_title, "You Are The Sunshine Of My Life")
        self.assertEquals(tracks[0].track.key(), sunshine.key())
Exemplo n.º 3
0
    def test_add_track_linked_to_library(self, fake_tq):
        fake_tq.is_a_stub()
        stevie = Artist.all().filter("name =", "Stevie Wonder")[0]
        talking_book = Album.all().filter("title =", "Talking Book")[0]
        sunshine = Track.all().filter("title =", "You Are The Sunshine Of My Life")[0]

        resp = self.client.post(reverse('playlists_add_event'), {
            'artist_key': stevie.key(),
            'artist': stevie.name,
            'song': "You Are The Sunshine Of My Life",
            'song_key': sunshine.key(),
            'album_key': talking_book.key(),
            'album': talking_book.title,
            'label': "Tamla",
            'label_key': 'Blah'
        })

        self.assertNoFormErrors(resp)
        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Stevie Wonder")
        self.assertEquals(tracks[0].artist.key(), stevie.key())
        self.assertEquals(tracks[0].album_title, "Talking Book")
        self.assertEquals(tracks[0].album.key(), talking_book.key())
        self.assertEquals(tracks[0].track_title, "You Are The Sunshine Of My Life")
        self.assertEquals(tracks[0].track.key(), sunshine.key())
Exemplo n.º 4
0
def bootstrap(request):
    # Don't create dummy playlist tracks if playlist tracks already exist!
    pl_tracks = PlaylistTrack.all().fetch(1)
    if len(pl_tracks) > 0:
        return HttpResponse(status=404)

    playlist = ChirpBroadcast()

    minutes = 0
    tracks = Track.all().fetch(100)
    for track in tracks:
        pl_track = PlaylistTrack(playlist=playlist,
                                 selector=request.user,
                                 established=datetime.now() -
                                 timedelta(minutes=minutes),
                                 artist=track.album.album_artist,
                                 album=track.album,
                                 track=track)
        pl_track.put()
        if minutes > 0 and minutes % 25 == 0:
            pl_break = PlaylistBreak(playlist=playlist,
                                     established=datetime.now() -
                                     timedelta(minutes=minutes - 1))
            pl_break.put()
        minutes += 5

    return HttpResponseRedirect("/playlists/")
Exemplo n.º 5
0
def play_count(request):
    """View for keeping track of play counts"""
    track_key = request.POST['id']
    track = PlaylistEvent.get(track_key)
    artist_name = track.artist_name
    album = track.album
    if not album:
        # Try to find a compilation album based on track name.
        qs = Track.all().filter('title =', track.track_title)
        for candidate in qs.run():
            if (candidate.track_artist and
                candidate.album.title == track.album_title and
                candidate.track_artist.name == track.artist_name):
                album = candidate.album
                break
        if not album:
            log.info('No album for %s / %s / %s'
                     % (track.artist_name, track.track_title,
                        track.album_title))
    if album and album.is_compilation:
        artist_name = 'Various'

    count = PlayCount.query(artist_name, track.album_title)
    if not count:
        count = PlayCount.create_first(artist_name,
                                       track.album_title,
                                       track.label)

    @db.transactional
    def increment(key):
        ob = db.get(key)
        ob.play_count += 1
        ob.put()

    increment(count.key())

    # See also:
    # https://developers.google.com/appengine/articles/sharding_counters
    return HttpResponse("OK")