Utility Functions API

class app.utils.Lyrics[source]

Data model for a song’s lyrics. :attr sections: A key-value pairing of section to lyrics.

add_section(section, lyrics)[source]

Adds a section to the Lyrics object. :param section: The name of the section. (e.g. V1, A, Chorus

etc.)
Parameters:lyrics (str) – The lyrics of that section.
to_dict()[source]
Returns:a dict representation of the Lyrics object.
app.utils.allowed_file(filename)[source]
Utility function that checks that the filename has an allowed extension.
Used when uploading the file. Checks the module-level variable ALLOWED_EXTENSIONS for allowed uploads.
Parameters:filename (str) – The name of the file that is being uploaded.
Example:
>>> ALLOWED_EXTENSIONS = ['.pdf', '.jpg']  # module-level variable
>>> file1 = 'my_file.txt'
>>> allowed_file(file1)
False
>>> file2 = 'my_file'
>>> allowed_file(file2)
False
>>> file3 = 'my_file.jpg'
>>> allowed_file(file3)
True
app.utils.clean_arrangement(arrangement)[source]

Cleans the song arrangement and turns it into a list.

Example:
>>> str_arr = 'V, C, V, C'
>>> clean_arrangement(str_arr)
['V', 'C', 'V', 'C']
Parameters:
  • arrangement (str) – a comma-delimited string containing the arrangement of the song.
  • song_data (dict) – a data dictionary. Keys are the data model fields as specified in datamodels.py. One of the keys has to be “lyrics”.
Returns:

arrangement a list of strings, each of which is a key in song’s lyrics dictionary.

Return type:

list(str)

app.utils.clean_lyrics(song)[source]

Cleans the lyrics in a song object.

app.utils.get_lyrics(request: <LocalProxy unbound>, exclude_id: int = None)[source]

Utility function that returns a Lyrics object containing the song lyrics.

Parameters:
  • requestrequest object from the Flask app.
  • exclude_id – an integer identifying which lyrics section to exclude.
Returns:

A Lyrics object containing the song’s lyrics in a structured format.

app.utils.lyrics_plaintext(song)[source]

Get lyrics as plaintext.

app.utils.validate_song(song)[source]

Converts song fields from None to ‘’ for string outputs.