playlists/tasks.py
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")
View for keeping track of play counts
View for keeping track of play counts
View for keeping track of play counts
def play_count(request):
    track_key = request.POST['id']
    track = PlaylistEvent.get(track_key)
    artist_name = track.artist_name
    album = track.album
    if not album:
        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())
    return HttpResponse("OK")
def play_count ( request ) : track_key = request . POST [ 'id' ] track = PlaylistEvent . get ( track_key ) artist_name = track . artist_name album = track . album if not album : 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 ( ) ) return HttpResponse ( "OK" )
View for keeping track of play counts
View for keeping track of play counts
"""View for keeping track of play counts""" # Try to find a compilation album based on track name. # See also: # https://developers.google.com/appengine/articles/sharding_counters
request