Skip to content

Commit

Permalink
feat: Handle shifting chords with JS
Browse files Browse the repository at this point in the history
  • Loading branch information
matiusz committed Dec 7, 2023
1 parent 262b7e9 commit 99cf029
Show file tree
Hide file tree
Showing 5 changed files with 1,109 additions and 60 deletions.
3 changes: 1 addition & 2 deletions frozen_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def start():
sb = Songbook()
for cat in sb.sb:
for sng in sb.sb[cat]:
for i in range(0, 12):
yield {'category': cat, 'song': sng.title, 'chordShift': i}
yield {'category': cat, 'song': sng.title}

if __name__ == '__main__':
freezer.freeze()
18 changes: 11 additions & 7 deletions src/flask/flask.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from flask import Flask, render_template, send_from_directory, redirect
from flask import Flask, render_template, make_response

from src.flask.forms.forms import FilterForm
from flask import request

from src.tools.chordShift import shiftChords
from src.obj.Songbook import Songbook
from src.obj.Song import Song
import json
import os
import markdown2
import re
Expand All @@ -26,15 +26,19 @@ def __init__(self):

sb = Songbook()


@app.route("/serve_js/app.js")
def serve_js():
categories = json.dumps(list(sb.sb))
response = make_response(render_template("app.js", categories = categories))
response.headers['Content-Type'] = 'text/javascript'
return response

@app.route("/")
@app.route("/<category>/<song>/<chordShift>.html")
def start(category = None, song = None, chordShift = 0):
@app.route("/<category>/<song>.html")
def start(category = None, song = None):
filter = FilterForm()
filter.validate_on_submit()
filterString = request.args.get("filter")
chordShift = int(chordShift)
if filterString:
songs = sb.filteredSongs(filterString)
else:
Expand All @@ -54,4 +58,4 @@ def start(category = None, song = None, chordShift = 0):
changelog = markdown2.markdown(text)
except Exception as ex:
changelog = "<p></p>"
return render_template("page.html", songList = songs, filter = filter, filterString = filterString, song = song, chordShift = chordShift, shiftChords = shiftChords, changelog = changelog, hasattr=hasattr)
return render_template("page.html", songList = songs, filter = filter, filterString = filterString, song = song, changelog = changelog, hasattr=hasattr)
Loading

0 comments on commit 99cf029

Please sign in to comment.