def admin_team_new(): if not current_user.is_admin: return abort(403) form = NewTeamForm() if form.validate_on_submit(): try: team = Team(number=form.number.data, name=form.name.data) db.session.add(team) db.session.commit() except IntegrityError as e: app.logger.exception(e) db.session.rollback() flash( 'The name or number requested is already in use. Please use another one.' ) except Exception as e: app.logger.exception(e) db.session.rollback() flash( 'An unknown error occurred. See the logs for more information') else: flash('Team details successfully updated') return redirect(url_for('admin_team')) return render_template('admin/team_new.html', title='New Team', form=form)
def init_app(admin_password, judge_password): click.echo('Initialising application...') db.create_all() click.echo('Database created.') admin = 'Admin' judge = 'Judge' admin_user = User(username=admin, password=bcrypt.hashpw(admin_password.encode('utf-8'), bcrypt.gensalt()), is_admin=True) db.session.add(admin_user) judge_user = User(username=judge, password=bcrypt.hashpw(judge_password.encode('utf-8'), bcrypt.gensalt()), is_judge=True) db.session.add(judge_user) practice_team = Team(number=-1, name='Practice', is_practice=True) db.session.add(practice_team) db.session.commit() click.echo('Default users created.') click.echo('Practice team created.') _set_stage()
def _add_teams(file: str): for line in file: line = line.strip() if not line: continue number, name = line.split(',', 2) name = name.strip() try: number = int(number.strip()) assert number > 0 except (ValueError, AssertionError): click.echo('Invalid number: {!s}'.format(number)) return click.echo('Adding team: {!s} (number: {!s}).'.format(name, number)) team = Team(number=number, name=name) db.session.add(team) try: db.session.commit() except: click.echo('ERROR: ONE OR MORE TEAMS/TEAM_NUM ALREADY EXIST') click.echo(' ') click.echo('Have you tried \'flask reset-teams\'? ') return else: click.echo('Team successfully added.')
def init_app(): click.echo('Initialising application...') db.create_all() click.echo('Database created.') admin = 'Admin' admin_pword = 'admin' # admin_pword = _request_password(admin, default='admin') judge = 'Judge' judge_pword = 'judge' # judge_pword = _request_password(judge, default='judge') admin_user = User(username=admin, password=admin_pword, is_admin=True) db.session.add(admin_user) judge_user = User(username=judge, password=judge_pword, is_judge=True) db.session.add(judge_user) practice_team = Team(number=-1, name='Practice', is_practice=True) db.session.add(practice_team) db.session.commit() click.echo('Default users created.') click.echo('Practice team created.') _set_stage()