Ejemplo n.º 1
0
def artist_network(request, artist_slug):
    results = Artist.objects.filter(slug=artist_slug)
    if results:
        a = results[0]
        primary_examples = a.primary_examples.all()
        featured_examples = a.featured_examples.all()

        network = []
        artist_cache = dict()
        example_cache = dict()

        for example in primary_examples:
            if example.song_title not in example_cache:
                example_cache[example.song_title] = 1
                for ar in example.feat_artist.all():
                    if ar not in artist_cache:
                        artist_cache[ar] = 1
                    else:
                        artist_cache[ar] += 1

        for example in featured_examples:
            if example.song_title not in example_cache:
                example_cache[example.song_title] = 1
                for ar in example.artist.all():
                    if ar not in artist_cache:
                        artist_cache[ar] = 1
                    else:
                        artist_cache[ar] += 1
                for ar in example.feat_artist.exclude(slug=a.slug):
                    if ar is not a:
                        if ar not in artist_cache:
                            artist_cache[ar] = 1
                        else:
                            artist_cache[ar] += 1

        for artist in artist_cache:
            img = check_for_image(artist.slug)
            if 'none' not in img:
                artist_object = {
                  "name": reformat_name(artist.name),
                  "link": "/artists/" + artist.slug,
                  "img":  img,
                  "size": artist_cache[artist]
                }
                network.append(artist_object)

        data = {
            'name': reformat_name(a.name),
            'img': check_for_image(a.slug),
            'link': "/artists/" + a.slug,
            'size': 5,
            'children': network
        }
        return Response(data)
    else:
        return Response({})
Ejemplo n.º 2
0
def song_artist_network(request, song_slug):
    results = Song.objects.filter(slug=song_slug)
    if results:
        song = results[0]
        network = []
        artist_cache = dict()

        a = song.artist.first()

        for ar in song.feat_artist.all():
            if ar not in artist_cache:
                artist_cache[ar] = 5
            else:
                artist_cache[ar] += 1

        for artist in artist_cache:
            img = check_for_image(artist.slug)
            artist_object = {
              "name": reformat_name(artist.name),
              "link": "/artists/" + artist.slug,
              "img":  img,
              "size": artist_cache[artist]
            }
            network.append(artist_object)

        if a:
            data = {
                'name': reformat_name(a.name),
                'img': check_for_image(a.slug),
                'link': "/artists/" + a.slug,
                'size': 5,
                'children': network
            }
            return Response(data)
        else:
            return Response({})
    else:
        return Response({})
Ejemplo n.º 3
0
def song_release_date_tree(request, song_slug):
    results = Song.objects.filter(slug=song_slug)
    if results:
        song = results[0]

        network = dict()
        cache = set()
        for s in Song.objects.filter(release_date=song.release_date, examples__isnull=False).order_by('artist_name'):
            if s != song and s.slug not in cache:
                cache.add(s.slug)
                artist_name = s.artist_name
                if artist_name not in network:
                    network[artist_name] = [(s.title, s.slug)]
                else:
                    network[artist_name].extend([(s.title, s.slug)])

        if network:
            data = {
                'name': song.release_date_string,
                'children': [
                    {
                        'name': reformat_name(s),
                        "link": "/artists/" + slugify(s),
                        'children': [
                            {
                                'name': t[0],
                                'link': "/songs/" + t[1]
                            } for t in network[s]]
                     } for s in network
                ]
            }
            return Response(data)
        else:
            return Response({})
    else:
        return Response({})