| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -11,7 +11,8 @@ quiz = Blueprint(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    name='quiz',
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    import_name=__name__,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    template_folder='templates',
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    static_folder='static'
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    static_folder='static',
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    static_url_path='/quiz/static'
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@quiz.route('/')
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -24,7 +25,7 @@ def _home():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				def _instructions():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return render_template('/quiz/instructions.html')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@quiz.route('/start/')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@quiz.route('/start/', methods=['GET', 'POST'])
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				def _start():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    form = StartQuiz()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if request.method == 'POST':
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -33,8 +34,9 @@ def _start():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            entry.set_first_name(request.form.get('first_name'))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            entry.set_surname(request.form.get('surname'))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            entry.set_club(request.form.get('club'))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            entry.set_email(request.form.get('email'))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            code = request.form.get('test_code').replace('—', '').lower()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            test = Test.query.filter_by(code=code)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            test = Test.query.filter_by(code=code).first()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            entry.test = test
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            entry.user_code = request.form.get('user_code')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            entry.user_code = None if entry.user_code == '' else entry.user_code.lower()
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -42,7 +44,7 @@ def _start():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            if entry.user_code and entry.user_code not in test.adjustments: return jsonify({'error': f'The user code you entered is not valid.'}), 400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            if test.end_date < datetime.now(): return jsonify({'error': f'The exam code you entered expired on {test["expiry_date"].strftime("%d %b %Y %H:%M")}.'}), 400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            if test.start_date > datetime.now(): return jsonify({'error': f'The exam has not yet opened. Your exam code will be valid from {test["start_date"].strftime("%d %b %Y %H:%M")}.'}), 400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            success, message = entry.start()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            success, message = entry.ready()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            if success:
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                session['id'] = entry.id
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                return jsonify({
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -52,36 +54,36 @@ def _start():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            return jsonify({'error': 'There was an error processing the user test and/or user codes.'}), 400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        errors = [*form.test_code.errors, *form.user_code.errors, *form.first_name.errors, *form.surname.errors, *form.email.errors, *form.club.errors]
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return jsonify({ 'error': errors}), 400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    render_template('/quiz/start_quiz.html', form = form)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return render_template('/quiz/start_quiz.html', form = form)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@quiz.route('/quiz/')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				def _quiz():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    id = session.get('id')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if not id or not Entry.query.filter_by(id=id).first():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        flash('Your session was not recognised. Please sign in to the quiz again.', 'error')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        session.pop('id')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return redirect(url_for('quiz_views.start'))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        session.pop('id', None)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return redirect(url_for('quiz._start'))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return render_template('/quiz/client.html')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@quiz.route('/result/')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				def _result():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    id = session.get('id')
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    entry = Entry.query.filter_by('id').first()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if not entry:
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return abort(404)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    score = round(100*entry.results['score']/entry.results['max'])
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    tags_low = { tag: tag_result['max'] - tag_result['scored'] for tag, tag_result in entry.results['tags'].items() }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    entry = Entry.query.filter_by(id=id).first()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if not entry: return abort(404)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    session.pop('id',None)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    score = round(100*entry.result['score']/entry.result['max'])
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    tags_low = { tag: tag_result['max'] - tag_result['scored'] for tag, tag_result in entry.result['tags'].items() }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    sorted_low_tags = sorted(tags_low.items(), key=lambda x: x[1], reverse=True)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    tag_output = [ tag[0] for tag in sorted_low_tags[0:3] if tag[1] > 3]
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    revision_plain = ''
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    revision_html = ''
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if entry.results['grade'] == 'pass':
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if entry.result['grade'] == 'pass':
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        flavour_text_plain = """Well done on successfully completing the refereeing theory exam. We really appreciate members of our community taking the time to get qualified to referee.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        """
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    elif entry.results['grade'] == 'merit':
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    elif entry.result['grade'] == 'merit':
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        flavour_text_plain = """Congratulations on achieving a merit in the refereeing exam. We are delighted that members of our community work so hard with refereeing.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        """
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    elif entry.results['grade'] == 'fail':
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    elif entry.result['grade'] == 'fail':
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        flavour_text_plain = """Unfortunately, you were not successful in passing the theory exam in this attempt. We hope that this does not dissuade you, and that you try again in the future.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        """
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        revision_plain = f"""Based on your answers, we would also suggest you brush up on the following topics for your next attempt:\n\n
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -92,6 +94,6 @@ def _result():
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            <li>{'</li><li>'.join(tag_output)}</li>
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            </ul>
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        """
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if not entry['status'] == 'late':
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if not entry.status == 'late':
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        pass
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return render_template('/quiz/result.html', entry=entry, score=score, tag_output=tag_output)
 |