def organizer_account(): organizer = db.session.query(User).filter( User.access == ACCESS[ORGANIZER]).first() if organizer is None: form = CreateOrganizerForm() if form.validate_on_submit(): if request.method == "POST": user = User() user.username = form.username.data user.email = form.email.data user.set_password(form.password.data) user.access = ACCESS[ORGANIZER] user.send_messages_email = bool(form.send_email.data) db.session.add(user) db.session.commit() flash(f"Organizer account \"{user.username}\" created.", 'alert-success') return redirect(url_for('self_admin.user_list')) else: form = EditOrganizerForm() form.username.data = organizer.username form.email.data = organizer.email form.send_email.data = TF[organizer.send_new_messages_email] if request.method == "POST": if form.validate_on_submit(): organizer.email = form.email.data if form.password.data != '': organizer.set_password(form.password.data) organizer.send_messages_email = bool(form.send_email.data) db.session.commit() flash(f"Organizer account \"{organizer.username}\" updated.", 'alert-success') return redirect(url_for('self_admin.user_list')) return render_template('admin/organizer_account.html', form=form)
def create_teamcaptains(): for t in data.TEAMS: team = Team.query.filter_by(city=t['city']).first() if team is not None: tc = User() tc.username = f"Teamcaptain{t['city']}" tc.access = data.ACCESS[data.TEAM_CAPTAIN] tc.team = team db.session.add(tc) treasurer = User() treasurer.username = f"Treasurer{t['city']}" treasurer.access = data.ACCESS[data.TREASURER] treasurer.team = team db.session.add(treasurer) db.session.commit()
def create_organization(): organisation = User() organisation.username = '******' organisation.email = '*****@*****.**' organisation.set_password('password') organisation.access = ACCESS[ORGANIZER] organisation.is_active = True db.session.add(organisation) db.session.commit()
def create_admin(): admin = User() admin.username = '******' admin.email = '*****@*****.**' admin.set_password('password') admin.access = ACCESS[ADMIN] admin.is_active = True db.session.add(admin) db.session.commit()
def create_admin(email, password): if len( User.query.filter( User.access == data.ACCESS[data.ADMIN]).all()) == 0: a = User() a.username = '******' a.email = email a.set_password(password) a.access = data.ACCESS[data.ADMIN] a.is_active = True db.session.add(a) db.session.commit()
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('main.index')) user = User.verify_reset_password_token(token) if not user: return redirect(url_for('main.index')) if user == 'error': flash('Not a valid token.', 'alert-danger') return redirect(url_for('main.index')) form = ResetPasswordForm() if form.validate_on_submit(): user.set_password(form.password.data) db.session.commit() flash('Your password has been reset.', 'alert-success') return redirect(url_for('main.index')) return render_template('auth/reset_password.html', form=form, user=user)
def create_super_volunteer_user_account(form, super_volunteer, external_adjudicator=False): super_volunteer_account = User() super_volunteer_account.username = form.email.data super_volunteer_account.email = form.email.data super_volunteer_account_password = random_password() super_volunteer_account.set_password(super_volunteer_account_password) super_volunteer_account.access = ACCESS[SUPER_VOLUNTEER] super_volunteer_account.is_active = True super_volunteer_account.send_new_messages_email = True super_volunteer_account.super_volunteer = super_volunteer if current_user.is_organizer(): super_volunteer_account.team = Team.query.filter(Team.name == TEAM_ORGANIZATION).first() elif external_adjudicator: super_volunteer_account.team = Team.query.filter(Team.name == TEAM_ADJUDICATOR).first() else: super_volunteer_account.team = Team.query.filter(Team.name == TEAM_SUPER_VOLUNTEER).first() db.session.add(super_volunteer_account) db.session.commit() send_super_volunteer_user_account_email(super_volunteer_account, super_volunteer.get_full_name(), super_volunteer_account_password)
def create_dancer_user_account(contestant): dancer_account = User() dancer_account.team = current_user.team dancer_account.username = contestant.email dancer_account.email = contestant.email dancer_account_password = random_password() dancer_account.set_password(dancer_account_password) dancer_account.access = ACCESS[DANCER] dancer_account.is_active = True dancer_account.send_new_messages_email = True dancer_account.dancer = contestant db.session.add(dancer_account) db.session.commit() send_dancer_user_account_email(dancer_account, contestant.get_full_name(), dancer_account_password)
def create_teams(): for value in TEAM_CAPTAINS: team = Team() team.country = value['country'] team.city = value['city'] team.name = value['team'] db.session.add(team) tc = User() tc.username = value['username'] tc.email = value['email'] tc.set_password(value['password']) tc.access = ACCESS[TEAM_CAPTAIN] tc.is_active = True if value['email'] is not None else False tc.team = team db.session.add(tc) for value in TREASURERS: treasurer = User() treasurer.username = value['username'] treasurer.access = ACCESS[TREASURER] treasurer.is_active = False treasurer.team = db.session.query(Team).filter_by(city=value['city']).first() db.session.add(treasurer) db.session.commit()
def create_configuration(): if len( User.query.filter( User.access == data.ACCESS[data.ORGANIZER]).all()) == 0: organisation = User() organisation.username = '******' organisation.email = '*****@*****.**' organisation.set_password(random_password()) organisation.access = data.ACCESS[data.ORGANIZER] organisation.is_active = False db.session.add(organisation) db.session.commit() for a in data.ASSISTANTS: if len(User.query.filter(User.username == a).all()) == 0: assistant = User() assistant.username = a assistant.set_password(random_password()) assistant.access = data.ACCESS[data.ASSISTANTS[a]] assistant.is_active = False db.session.add(assistant) db.session.commit() if len(Team.query.filter( Team.name == data.TEAM_ORGANIZATION).all()) == 0: db.session.add( Team(name=data.TEAM_ORGANIZATION, country=data.NETHERLANDS, city=data.WIERDEN)) db.session.commit() if len( Team.query.filter( Team.name == data.TEAM_SUPER_VOLUNTEER).all()) == 0: db.session.add( Team(name=data.TEAM_SUPER_VOLUNTEER, country=data.NETHERLANDS, city=data.WIERDEN)) db.session.commit() if len(Team.query.filter( Team.name == data.TEAM_ADJUDICATOR).all()) == 0: db.session.add( Team(name=data.TEAM_ADJUDICATOR, country=data.NETHERLANDS, city=data.WIERDEN)) db.session.commit() if len(TournamentState.query.all()) == 0: db.session.add(TournamentState()) if len(SystemConfiguration.query.all()) == 0: db.session.add(SystemConfiguration(website_accessible=True)) if len(RaffleConfiguration.query.all()) == 0: db.session.add(RaffleConfiguration()) db.session.commit()
def populate_test_data(tournament=None): if tournament is None: return False if tournament not in PAST_TOURNAMENTS: return False test_contestants = [] test_configuration = {} reset_tournament_state() g.ts.organizer_account_set = True g.ts.system_configured = True if tournament == "NTDS 2018 Enschede": test_contestants = ntds2018enschede test_configuration = ntds2018enschede_configuration if tournament == "ETDS 2018 Brno": test_contestants = etds2018brno test_configuration = etds2018brno_configuration if tournament == "NTDS 2019 Nijmengen": test_contestants = ntds2019nijmegen test_configuration = ntds2019nijmegen_configuration User.query.filter(User.access >= ACCESS[ORGANIZER], User.access < ACCESS[TEAM_CAPTAIN])\ .update({User.is_active: True}) g.sc.tournament = test_configuration["tournament"] g.sc.number_of_teamcaptains = test_configuration["number_of_teamcaptains"] g.sc.beginners_level = test_configuration["beginners_level"] g.sc.closed_level = test_configuration["closed_level"] g.sc.breitensport_obliged_blind_date = test_configuration[ "breitensport_obliged_blind_date"] g.sc.salsa_competition = test_configuration["salsa_competition"] g.sc.polka_competition = test_configuration["polka_competition"] g.sc.student_price = test_configuration["student_price"] g.sc.non_student_price = test_configuration["non_student_price"] g.sc.phd_student_category = test_configuration["phd_student_category"] g.sc.phd_student_price = test_configuration["phd_student_price"] g.sc.first_time_ask = test_configuration["first_time_ask"] g.sc.ask_adult = test_configuration["ask_adult"] g.sc.ask_diet_allergies = test_configuration["ask_diet_allergies"] g.sc.ask_volunteer = test_configuration["ask_volunteer"] g.sc.ask_first_aid = test_configuration["ask_first_aid"] g.sc.ask_emergency_response_officer = test_configuration[ "ask_emergency_response_officer"] g.sc.ask_adjudicator_highest_achieved_level = test_configuration[ "ask_adjudicator_highest_achieved_level"] g.sc.ask_adjudicator_certification = test_configuration[ "ask_adjudicator_certification"] for merchandise in test_configuration["merchandise"]: if merchandise["shirt"]: item = MerchandiseItem(description=merchandise["description"], shirt=merchandise["shirt"], price=merchandise["price"]) for size in SHIRT_SIZES: MerchandiseItemVariant(merchandise_item=item, variant=size) db.session.add(item) else: item = MerchandiseItem(description=merchandise["description"], shirt=merchandise["shirt"], price=merchandise["price"]) for variant in merchandise["variants"]: MerchandiseItemVariant(merchandise_item=item, variant=variant) db.session.add(item) g.sc.finances_refund = test_configuration["finances_refund"] g.sc.finances_refund_percentage = test_configuration[ "finances_refund_percentage"] now = datetime.datetime.now() now = datetime.datetime(year=now.year, month=now.month, day=now.day) refund_date = now + datetime.timedelta((2 - now.weekday()) % 7) merchandise_date = refund_date + datetime.timedelta(days=8) tournament_start_date = merchandise_date + datetime.timedelta(days=8) g.sc.tournament_starting_date = int(tournament_start_date.timestamp()) g.sc.finances_refund_date = int(refund_date.timestamp()) g.sc.merchandise_closing_date = int(merchandise_date.timestamp()) db.session.commit() for test_c in test_contestants: c = Contestant() c.contestant_id = test_c['contestant_id'] c.first_name = test_c['first_name'] if 'prefixes' in test_c: c.prefixes = test_c['prefixes'] c.last_name = test_c['last_name'] print('... Adding {}'.format(c.get_full_name())) c.email = test_c['email'] db.session.add(c) c_info = ContestantInfo() c_info.number = test_c['number'] c_info.team_captain = test_c['team_captain'] c_info.student = test_c['student'] c_info.first_time = test_c['first_time'] c_info.diet_allergies = test_c['diet_allergies'] c_info.team = db.session.query(Team).filter_by( city=test_c['team']).first() c_info.contestant = c for di in test_c['dancing_info']: d_info = DancingInfo() d_info.contestant = c d_info.competition = di['competition'] d_info.level = di['level'] d_info.role = di['role'] d_info.blind_date = di['blind_date'] d_info.partner = di['partner'] db.session.add(d_info) v_info = VolunteerInfo() v_info.volunteer = test_c['volunteer'] v_info.first_aid = test_c['first_aid'] v_info.emergency_response_officer = test_c[ 'emergency_response_officer'] v_info.jury_ballroom = test_c['jury_ballroom'] v_info.jury_latin = test_c['jury_latin'] v_info.license_jury_ballroom = test_c['license_ballroom'] v_info.license_jury_latin = test_c['license_latin'] v_info.level_ballroom = test_c['ballroom_highest_level'] v_info.level_latin = test_c['latin_highest_level'] v_info.jury_salsa = test_c['jury_latin'] v_info.jury_polka = test_c['jury_latin'] v_info.contestant = c a_info = AdditionalInfo() a_info.sleeping_arrangements = test_c['sleeping_arrangements'] a_info.contestant = c s_info = StatusInfo() s_info.guaranteed_entry = test_c['guaranteed_entry'] s_info.contestant = c m_info = MerchandiseInfo() m_info.contestant = c for p in test_c['merchandise']: if test_c['merchandise'][p] != NO: variant = MerchandiseItemVariant.query.join(MerchandiseItem)\ .filter(MerchandiseItemVariant.variant == test_c['merchandise'][p], MerchandiseItem.description == p).first() MerchandisePurchase(merchandise_info=m_info, merchandise_item_variant=variant) p_info = PaymentInfo() p_info.contestant = c dancer_account = User() dancer_account.team = db.session.query(Team).filter_by( city=test_c['team']).first() dancer_account.username = test_c['email'] dancer_account.email = test_c['email'] dancer_account.set_password('test') dancer_account.access = ACCESS[DANCER] dancer_account.is_active = True dancer_account.send_new_messages_email = False dancer_account.dancer = c db.session.commit() return True