Beispiel #1
0
def djpandora_status(request):
    """
    Calls the Pandora service, forms a JSON object and returns it. This function
    should only be called via AJAX calls.
    """
    song_result = utils.get_song(request.user)
    vote_result = utils.song_voting(request.user, song_result['song'])
    poll_results = utils.station_election(request.user)
    json_data = {
        'title': song_result['song_info']['title'],
        'station': song_result['station_name'],
        'station_status': song_result['status'],
        'artist': song_result['song_info']['artist'],
        'album_art': song_result['song_info']['album_art'],
        'time': song_result['song_info']['time'],
        'album': song_result['song_info']['album'],        
        'progress': song_result['song_info']['progress'],
        'length': song_result['song_info']['length'],
        'volume': song_result['volume'],
        'upcoming': song_result['playlist'],
        'recents': song_result['recents'],
        'purchase_itunes': song_result['song_info']['purchase_itunes'],
        'purchase_amazon': song_result['song_info']['purchase_amazon'],
        'voting': vote_result,
        'station_voting': poll_results,
        'status': 'success',
    }
    return HttpResponse(json.dumps(json_data), mimetype='application/json')
Beispiel #2
0
def djpandora_stations(request):
    """
    Gets all the stations for the currently in use Pandora account, and displays
    them. If a vote is in progress, the station being voted on will be shown 
    as such.
    """
    json_serializer = serializers.get_serializer("json")()
    stations = models.Station.objects.filter(account=settings.PANDORA_USER)
    station_data = json_serializer.serialize(stations, ensure_ascii=False)
    station_data = json.loads(station_data)
    poll_results = utils.station_election(request.user)
    polling = False
    for x in station_data:
        station = models.Station.objects.get(id=x['pk'])
        x['fields']['polling'] = station.polling
        if station.polling:
            polling = True
            poll = models.StationPoll.objects.get(active=True)
            x['fields']['vote_total'] = poll.vote_total

    json_data = {'status': 'success', 'poll': polling, 'items': station_data,
        'poll_results': poll_results}
    return HttpResponse(json.dumps(json_data), mimetype="application/json")