def test_confirmed(): if not g.ts.main_raffle_result_visible: return redirect(url_for('raffle.test_completed')) form = request.args if 'selected_confirmed' in form: dancers = StatusInfo.query.filter(StatusInfo.status == SELECTED).all() for dancer in dancers: dancer.set_status(CONFIRMED) db.session.commit() flash(f"All {SELECTED} dancers are now {CONFIRMED}.") if 'confirmed_selected' in form: dancers = StatusInfo.query.filter(StatusInfo.status == CONFIRMED).all() for dancer in dancers: dancer.set_status(SELECTED) db.session.commit() flash(f"All {CONFIRMED} dancers are now {SELECTED}.") raffle_sys = RaffleSystem() if request.method == 'GET': raffle_sys.clear_no_gdpr_dancers_partners() all_teams = competing_teams().all() teams = [{'team': team, 'id': team.name.replace(' ', '-').replace('`', ''), 'id_title': team.name.replace(' ', '-').replace('`', '') + '-title'} for team in all_teams] for t in teams: t['available_dancers'] = [d for d in raffle_sys.registered_dancers if d.contestant_info.team == t['team']] t['selected_dancers'] = [d for d in raffle_sys.selected_dancers if d.contestant_info.team == t['team']] t['confirmed_dancers'] = [d for d in raffle_sys.confirmed_dancers if d.contestant_info.team == t['team']] return render_template('raffle/test_confirmed.html', raffle_sys=raffle_sys, teams=teams) if request.method == 'POST': form = request.form if 'reset_raffle' in form: for dancer in raffle_sys.all_dancers: dancer.status_info.set_status(REGISTERED) g.ts.main_raffle_taken_place = False g.ts.main_raffle_result_visible = False g.ts.raffle_completed_message_sent = False flash('Raffle results cleared.', 'alert-info') elif 'select_marked_dancers' in form: raffle_sys.confirm_selection([d for d in raffle_sys.selected_dancers if str(d.contestant_id) in form]) elif 'remove_marked_dancers' in form: raffle_sys.cancel_selection([d for d in raffle_sys.all_dancers if str(d.contestant_id) in form]) elif 'balance_raffle' in form: raffle_sys.balance_raffle() elif 'finish_raffle' in form: raffle_sys.finish_raffle() elif 'finish_raffle_with_sleeping_spots' in form: raffle_sys.finish_raffle(non_sleeping_hall_dancers=True) elif 'select_random_group' in form: flash(raffle_sys.add_neutral_group()) elif 'select_specific_dancers' in form: flash(raffle_sys.select_specific_dancers(form)) else: flash(raffle_sys.select_single_dancer(form)) db.session.commit() return redirect(url_for('raffle.test_system'))
def user_list(): users = User.query.filter(or_(User.access == ACCESS[TEAM_CAPTAIN], User.access == ACCESS[TREASURER])) \ .order_by(case({True: 0, False: 1}, value=User.is_active), User.team_id).all() teams = competing_teams().all() organizer = db.session.query(User).filter( User.access == ACCESS[ORGANIZER]).first() return render_template('admin/user_list.html', users=users, teams=teams, organizer=organizer)
def completed(): if not g.ts.main_raffle_taken_place: return redirect(url_for('raffle.start')) if g.ts.main_raffle_result_visible: return redirect(url_for('raffle.confirmed')) raffle_sys = RaffleSystem() if request.method == 'GET': all_teams = competing_teams().all() teams = [{'team': team, 'id': team.city, 'id_title': team.city + '-title'} for team in all_teams] for t in teams: t['available_dancers'] = [d for d in raffle_sys.registered_dancers if d.contestant_info.team == t['team']] t['selected_dancers'] = [d for d in raffle_sys.selected_dancers if d.contestant_info.team == t['team']] t['guaranteed_dancers'] = [d for d in raffle_sys.guaranteed_dancers() if d.contestant_info.team == t['team']] return render_template('raffle/completed.html', raffle_sys=raffle_sys, teams=teams) if request.method == 'POST': raffle_sys.clear_no_gdpr_dancers_partners() form = request.form if 'cancel_raffle' in form: for dancer in [d for d in raffle_sys.all_dancers if d.status_info.status != NO_GDPR]: dancer.status_info.set_status(REGISTERED) g.ts.main_raffle_taken_place = False flash('Raffle cancelled.', 'alert-info') elif 'confirm_raffle' in form: for dancer in raffle_sys.selected_dancers: dancer.status_info.set_status(SELECTED) g.ts.main_raffle_result_visible = True flash('Raffle confirmed. The results are now visible to the teamcaptains.', 'alert-success') elif 'balance_raffle' in form: raffle_sys.balance_raffle() elif 'finish_raffle' in form: raffle_sys.finish_raffle() elif 'finish_raffle_with_sleeping_spots' in form: raffle_sys.finish_raffle(non_sleeping_hall_dancers=True) elif 'select_random_group' in form: flash(raffle_sys.add_neutral_group()) elif 'select_specific_dancers' in form: flash(raffle_sys.select_specific_dancers(form)) else: flash(raffle_sys.select_single_dancer(form)) db.session.commit() return redirect(url_for('raffle.system'))
def confirmed(): if not g.ts.main_raffle_result_visible: return redirect(url_for('raffle.completed')) raffle_sys = RaffleSystem() if request.method == 'GET': all_teams = competing_teams().all() teams = [{'team': team, 'id': team.city, 'id_title': team.city + '-title'} for team in all_teams] for t in teams: t['available_dancers'] = [d for d in raffle_sys.registered_dancers if d.contestant_info.team == t['team']] t['selected_dancers'] = [d for d in raffle_sys.selected_dancers if d.contestant_info.team == t['team']] t['confirmed_dancers'] = [d for d in raffle_sys.confirmed_dancers if d.contestant_info.team == t['team']] return render_template('raffle/confirmed.html', raffle_sys=raffle_sys, teams=teams) if request.method == 'POST': raffle_sys.clear_no_gdpr_dancers_partners() form = request.form if 'select_marked_dancers' in form: raffle_sys.confirm_selection([d for d in raffle_sys.selected_dancers if str(d.contestant_id) in form]) elif 'remove_marked_dancers' in form: raffle_sys.cancel_selection([d for d in raffle_sys.all_dancers if str(d.contestant_id) in form]) elif 'balance_raffle' in form: raffle_sys.balance_raffle() elif 'finish_raffle' in form: raffle_sys.finish_raffle() elif 'finish_raffle_with_sleeping_spots' in form: raffle_sys.finish_raffle(non_sleeping_hall_dancers=True) elif 'select_random_group' in form: flash(raffle_sys.add_neutral_group()) elif 'select_specific_dancers' in form: flash(raffle_sys.select_specific_dancers(form)) else: flash(raffle_sys.select_single_dancer(form)) db.session.commit() return redirect(url_for('raffle.system'))
def start(): if g.ts.main_raffle_taken_place: return redirect(url_for('raffle.completed')) raffle_sys = RaffleSystem() if request.method == 'GET': all_teams = competing_teams().all() teams = [{'team': team, 'id': team.city, 'id_title': team.city + '-title'} for team in all_teams] for t in teams: t['teamcaptains'] = [d for d in raffle_sys.registered_dancers if d.contestant_info.team == t['team'] and d.contestant_info.team_captain] t['available_dancers'] = [d for d in raffle_sys.registered_dancers if d.contestant_info.team == t['team']] t['guaranteed_dancers'] = [d for d in raffle_sys.guaranteed_dancers() if d.contestant_info.team == t['team']] return render_template('raffle/start.html', raffle_sys=raffle_sys, teams=teams) if request.method == 'POST': form = request.form if 'start_raffle' in form: raffle_sys.raffle() g.ts.main_raffle_taken_place = True flash('Raffle completed.', 'alert-info') db.session.commit() return redirect(url_for('raffle.system'))