def show(tournament_id): tournament = Tournament.query.get(tournament_id) if tournament: if request.method == "GET": return render_template('tournament_show.html', tournament=tournament) elif request.method != "GET" and tournament.submitted == False: method = request.form.get('_method', '').upper() if method: if tournament.submitted == False: if method == "DELETE": db.session.delete(tournament) db.session.commit() # flash('{{ tournament.event_name }} has been deleted') return redirect(url_for('.index')) elif method == "PUT": form = TournamentForm(obj=tournament) if form.validate_on_submit(): form.populate_obj(tournament) db.session.commit() # flash("Tournament successfully edited.") return redirect(url_for('.show', tournament_id=tournament_id)) # flash("Cannot alter submitted record") return redirect(url_for('.index')) else: # flash("Cannot alter submitted record") return redirect(url_for('.index')) else: # flash('Tournament id {{ tournament_id }} does not exist.') return redirect(url_for('.index'))
def tournaments(request, league_slug): page = request.GET.get('page', 1) league = League.objects.get(slug=league_slug) form = TournamentForm(initial={'league': league.id}) tournaments = Tournament.objects.filter(league=league) paginator = Paginator(tournaments, PAGINATE_DEFAULT) try: tournaments = paginator.page(page) except PageNotAnInteger: tournaments = paginator.page(1) except EmptyPage: tournaments = paginator.page(paginator.num_pages) template = 'app/league/tournaments.html' return render( request, template, { 'form': form, 'league': league, 'tournaments': tournaments, 'paginator': paginator })
def Tournament(form: TournamentForm) -> list: if form.validate_on_submit(): probId = form.probId.data startTimeStr = form.start.data id = None try: id = int(probId) if storage.getProblem(id) == None: raise ValueError() except ValueError: return [0, ("No problem with this id!", "message red")] if (startTimeStr == ''): useCasesAPI.makeTournament(id) return [1, ("Tournament Successfully created.", "message green")] else: try: startTime = int(startTimeStr) except ValueError: return [0, ("Incorrect time", "message red")] if (startTime < unixTime()): return [0, ("Too early", "message red")] if (startTime > MaxStartTime): return [0, ("Too late", "message red")] useCasesAPI.createDelayedTournament(id, startTime) return [ 1, ("Looking forward for tournament start", "message green") ] return [0, ("Enter id of problem", "message blue")]
def create_new_tournament(request, league_slug): league = League.objects.get(slug=league_slug) success = False if request.method == 'POST': form = TournamentForm(request.POST) if form.is_valid(): form.save() success = True return JsonResponse({ 'success': success, 'errors': dict(form.errors.items()) })
def index(): form = TournamentForm() if request.method == 'POST': if form.validate_on_submit(): t = Tournament(event_name=form.event_name.data, venue=form.venue.data, venue_address=form.venue_address.data, venue_state=form.venue_state.data, venue_zip=form.venue_zip.data, start_date=form.start_date.data, end_date=form.end_date.data, director=form.director.data, director_phone=form.director_phone.data, director_email=form.director_email.data, director_address=form.director_address.data, sponsor=form.sponsor.data, sponsor_phone=form.sponsor_phone.data, sponsor_email=form.sponsor_email.data, sponsor_website=form.sponsor_website.data, sponsor_address=form.sponsor_address.data, convener=form.convener.data, convener_phone=form.convener_phone.data, convener_email=form.convener_email.data, convener_website=form.convener_website.data, convener_address=form.convener_address.data, pairing=form.pairing.data, rule_set=form.rule_set.data, time_controls=form.time_controls.data, basic_time=form.basic_time.data, overtime_format=form.overtime_format.data, overtime_conditions=form.overtime_conditions.data, komi=form.komi.data, tie_break1=form.tie_break1.data, tie_break2=form.tie_break2.data, submitted=form.submitted.data) db.session.add(t) db.session.commit() # flash("Tournament successfully created.") return redirect(url_for('.index')) tournaments = Tournament.query.all() return render_template('tournament_index.html', tournaments=tournaments)
def add_tournament(): Info = info() if (not Info['admin']): flash("You don't have permission to do this!", 'message red') return redirect("/home") default = request.args.get('probId') if (default == None): default = '' form = TournamentForm() success, message = Tournament(form) flash(message[0], message[1]) if success: return redirect("/home") return render_template("add_tournament.html.j2", title="Add tournament", form=form, default=default, info=Info)
def edit_tournament(tournament_id): tournament = Tournament.query.get(tournament_id) form = TournamentForm(obj=tournament) return render_template('tournament_form.html', form=form, tournament=tournament)
def new_tournament(): form = TournamentForm() return render_template('tournament_form.html', form=form)