def clean(self): try: parsed_lyrics = parse_lyrics(self.lyrics) transpose_lyrics(parsed_lyrics, 0) except SyntaxError as m: raise ValidationError('Niepoprawny format treści piosenki: ' + str(m)) return super().clean()
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))
def render_lyrics(raw_lyrics, transposition=0, template_name='songs/lyrics.html'): lyrics = transpose_lyrics(parse_lyrics(raw_lyrics), transposition) return loader.get_template(template_name).render({'lyrics': lyrics})
def render_lyrics(raw_lyrics, transposition=0, template_name="songs/lyrics.html"): lyrics = transpose_lyrics( parse_lyrics(raw_lyrics), transposition) return loader.get_template(template_name).render(Context({"lyrics": lyrics}))
def clean(self): try: parsed_lyrics = parse_lyrics(self.lyrics) transpose_lyrics(parsed_lyrics, 0) except SyntaxError as m: raise ValidationError('Lyrics syntax is incorrect: ' + str(m))
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)