예제 #1
0
파일: models.py 프로젝트: fjern/piosenka
def validate_lyrics(value):
    try:
        from songs.parse import parse_lyrics
        from songs.transpose import transpose_lyrics
        lyrics = parse_lyrics(value)
        transpose_lyrics(lyrics, 0)
    except SyntaxError, m:
        raise ValidationError(u'Lyrics syntax is incorrect: ' + unicode(m))
예제 #2
0
파일: views.py 프로젝트: fjern/piosenka
def song(request, song, mode):
    if mode == SongMode.DISPLAY:
        template_name = 'songs/song.html'
    else:
        template_name = 'songs/song_print.html'

    external_links = [(x.artist, x.artist.website) for x in
        ArtistContribution.objects.filter(song=song).select_related('artist') if
        x.artist.website != None and len(x.artist.website) > 0
    ] + [(x.band, x.band.website) for x in
        BandContribution.objects.filter(song=song).select_related('band') if
        x.band.website != None and len(x.band.website) > 0
    ]

    if request.method == "GET" and "t" in request.GET:
        try:
            t = int(request.GET["t"])
            if t >= 0 and t < 12:
                transposition = t
            else:
                transposition = 0
        except ValueError:
            transposition = 0
    else:
        transposition = 0

    trans_up = (transposition + 1) % 12
    trans_down = (transposition + 11) % 12

    lyrics = parse_lyrics(song.lyrics)

    extra = False

    for paragraph in lyrics:
        for text, chords, is_indented, are_chords_extra in paragraph:
            if are_chords_extra:
                extra = True
                break
        if extra:
            break

    context = {
        'song': song,
        'section': 'songs',
        'triggers': mode == SongMode.DISPLAY,
        'extra': extra,
        'trans':  transposition,
        'trans_up': trans_up,
        'trans_down': trans_down,
        'capo': song.capo(),
        'lyrics': render_lyrics(
            transpose_lyrics(
                lyrics,
                transposition
            ),
            mode
        ),
        'textContributions': ArtistContribution.objects.filter(song=song, texted=True),
        'translationContributions': ArtistContribution.objects.filter(song=song, translated=True),
        'musicContributions': ArtistContribution.objects.filter(song=song, composed=True),
        'performanceContributions': ArtistContribution.objects.filter(song=song, performed=True),
        'bandContributions': BandContribution.objects.filter(song=song, performed=True),
        'external_links': external_links,
    }
    return render(request, template_name, context)