From 9241e1c0f73e189fd14cf40091bf04c461acfd50 Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Fri, 3 Feb 2023 16:06:06 +0000 Subject: [PATCH] Added club suggestion auto-complete --- .../quiz/templates/quiz/components/base.html | 2 ++ .../app/quiz/templates/quiz/start_quiz.html | 8 ++++++++ ref-test/app/quiz/views.py | 19 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ref-test/app/quiz/templates/quiz/components/base.html b/ref-test/app/quiz/templates/quiz/components/base.html index cea4c72..957397c 100644 --- a/ref-test/app/quiz/templates/quiz/components/base.html +++ b/ref-test/app/quiz/templates/quiz/components/base.html @@ -56,6 +56,8 @@ integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous" > + + {% endblock %} \ No newline at end of file diff --git a/ref-test/app/quiz/views.py b/ref-test/app/quiz/views.py index 11edaab..9b1f382 100644 --- a/ref-test/app/quiz/views.py +++ b/ref-test/app/quiz/views.py @@ -29,6 +29,23 @@ def _instructions(): @quiz.route('/start/', methods=['GET', 'POST']) def _start(): + clubs = [ + 'Dundee Korfball Club', + 'Edinburgh City Korfball Club', + 'Edinburgh Mavericks Korfball Club', + 'Edinburgh University Korfball Club', + 'Glasgow Korfball Club', + 'Saint Andrews University Korfball Club', + 'Strathclyde University Korfball Club' + ] + try: entries = Entry.query.all() + except Exception as exception: + write('system.log', f'Database error when processing request \'{request.url}\': {exception}') + return abort(500) + for entry in entries: clubs.append(entry.get_club()) + clubs = list(set(clubs)) + try: clubs.remove('') + except: pass form = StartQuiz() if request.method == 'POST': if form.validate_on_submit(): @@ -58,7 +75,7 @@ def _start(): }), 200 return jsonify({'error': 'There was an error processing the user test and/or user codes.'}), 400 return send_errors_to_client(form=form) - return render_template('/quiz/start_quiz.html', form = form) + return render_template('/quiz/start_quiz.html', form = form, clubs = clubs) @quiz.route('/quiz/') def _quiz():