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.
-
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.
get_lyrics
(request: <LocalProxy unbound>, exclude_id: int = None)[source]¶ Utility function that returns a Lyrics object containing the song lyrics.
Parameters: - request – request 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.