def voting_console(): now = datetime.datetime.now() config = Config.query.first() errors = [] if now < config.voting_end_date and not config.voting_started: errors.append("The voting period has not opened yet") if not errors and config.voting_started and current_user.voted: errors.append("You have already voted. Thank you!") if not errors and now > config.voting_end_date: errors.append("The voting period has ended") if current_user.voted: results, write_ins, totals = get_results() else: results, write_ins, totals = (None, None, None) return render_template( 'consoles/voting.html', success=not errors, errors=errors, positions=[i.serialize for i in Position.query.all()], end_date=Config.query.first().voting_end_date, results=results, write_ins=write_ins, totals=totals )
def results(): results, write_ins, totals = get_results() return jsonify(success=True, results=results, write_ins=write_ins)