Example #1
0
def song(request, song_slug):
    if request.method == 'POST':
        form = SongForm(request.POST)
        if form.is_valid():
            song = Song.objects.get(slug=song_slug)
            song.title = form.cleaned_data['title']
            song.release_date = form.cleaned_data["release_date"]
            song.release_date_string = form.cleaned_data["release_date_string"]
            song.artist_name = form.cleaned_data["artist_name"]
            song.album = form.cleaned_data["album"]
            song.lyrics = form.cleaned_data["lyrics"]
            song.release_date_verified = form.cleaned_data["release_date_verified"]
            song.save()

    song = get_list_or_404(Song, slug=song_slug)[0]
    published_entries = Entry.objects.filter(publish=True).values_list('headword', flat=True)
    template = loader.get_template('dictionary/song.html')
    same_dates = [
        {
            'title': s.title,
            'artist_name': reformat_name(s.artist_name),
            'artist_slug': s.artist_slug,
            'slug': s.slug
        } for s in Song.objects.filter(release_date=song.release_date).order_by('artist_name') if s != song]
    image = check_for_image(song.artist_slug, 'artists', 'full')
    thumb = check_for_image(song.artist_slug, 'artists', 'thumb')
    form = SongForm(instance=song)
    context = {
        "title": song.title,
        "slug": song.slug,
        "image": image,
        "thumb": thumb,
        "artist_name": reformat_name(song.artist_name),
        "artist_slug": song.artist_slug,
        "primary_artist": [build_artist(a) for a in song.artist.all()],
        "featured_artists": [build_artist(a) for a in song.feat_artist.all()],
        "release_date": song.release_date,
        "release_date_string": song.release_date_string,
        "album": song.album,
        "examples": [build_example(example, published_entries, rf=True) for example in song.examples.all()],
        "same_dates": same_dates,
        "form": None
    }

    if request.user.is_authenticated():
        context['form'] = form

    return HttpResponse(template.render(context, request))
Example #2
0
def sense_artists(request, sense_id):
    results = Sense.objects.filter(xml_id=sense_id)
    if results:
        sense_object = results[0]
        data = {'senses': [build_artist(artist, require_origin=True) for artist in sense_object.cites_artists.all()]}
        return Response(data)
    else:
        return Response({})
Example #3
0
def artist(request, artist_slug):
    results = Artist.objects.filter(slug=artist_slug)
    if results:
        data = {
            'user': str(request.user),
            'auth': str(request.auth),
            'artists': [build_artist(artist) for artist in results]
        }
        return Response(data)
    else:
        return Response({})
Example #4
0
def artists(request):
    results = Artist.objects.order_by("slug")
    if results:
        data = {
            'user': str(request.user),
            'auth': str(request.auth),
            'artists': [build_artist(artist) for artist in results]
        }
        return Response(data)
    else:
        return Response({})