def score(): statsd.increment('api_calls.score.%s' % request.method) if request.method == 'GET': row = session.query(Score).filter( Score.person_id == g.user._id) res = [] for pt in row: res.append(pt.json_data()) return jsonify({ 'msg': res, 'success': False}) '''post function''' logger.info(request.form) form = ScoreForm(request.form) if not form.validate(): msg = { 'success': False, 'msg': form.errors} return jsonify(msg) session.add(Score(form, g.user._id)) session.commit() msg = { 'success': True, 'msg': 'Added', 'id': form.id.data, } return jsonify(msg)
def home(): if 'email' not in session: return redirect(url_for('login')) user = User.query.filter_by(email=session['email']).first() form = ScoreForm() my_scores = [] #my_scores = Score.query.filter_by(uid=user.uid) my_scores = Score.query.all() print(my_scores) if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form) else: # submit the score into the db newscore = Score(user.uid, form.score.data) db.session.add(newscore) db.session.commit() # return those results return render_template('home.html', form=form, my_scores=my_scores) if request.method == 'GET': return render_template("home.html", form=form, my_scores=my_scores)
def add(): teams = Team.query.all() if not teams: return render_template("no_teams.html") form = ScoreForm() form.team_id.choices = [(t.id, t.number) for t in sortTeamsWithPlaceholder(teams)] # don't allow playoff round options during qualifying, or qualifying during playoffs if any(team.highest_round_reached > 3 for team in teams): form.round_number.choices = [(-1, 'Select'), (1, '1'), (2, '2'), (3, '3'), (4, 'Quarterfinals'), (5, 'Semifinals'), (6, 'Finals')] else: form.round_number.choices = [(-1, 'Select'), (1, '1'), (2, '2'), (3, '3')] # Gather and preset the team ID and round number fields if provided in URL preselected_team = request.args.get('team_id', default=None, type=int) preselected_round = request.args.get('round', default=None, type=int) if preselected_team is not None and request.method == 'GET': form.team_id.data = preselected_team if preselected_round is not None and request.method == 'GET': form.round_number.data = preselected_round repeat = request.args.get('repeat', default=False, type=bool) if request.method == 'POST' and request.form['end'] == 'reset': return redirect(url_for(".add", round=preselected_round, repeat=True)) elif request.method == 'POST' and request.form[ 'end'] == 'submit' and form.validate_on_submit(): score = RobotScore(team=form.team_id.data, round_number=form.round_number.data) populate_score(score, form) db.session.add(score) db.session.commit() if repeat: flash( 'Added score for %s round %s' % (score.team.number, score.round_number), 'success') return redirect( url_for(".add", round=preselected_round, repeat=True)) else: if form.round_number.data <= 3: return redirect(url_for("review")) else: return redirect(url_for(".playoffs")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("scoring/score_form.html", form=form, id=None, repeat=repeat)
def score_edit(request, score_id): scores = Score.objects.all() scores1 = Score.objects.all().filter(category='SCI').order_by('sub_category') scores2 = Score.objects.all().filter(category='P').order_by('sub_category') instance = get_object_or_404(Score, id=score_id) form = ScoreForm(request.POST or None, instance=instance) if form.is_valid(): form.save() return redirect('score_list') return render(request, 'score_edit.html', {'scores1': scores1, 'scores2': scores2, 'form': form, "score_id": instance.id})
def score_add(request): if request.method == 'POST': form = ScoreForm(request.POST) form.save() scores = Score.objects.all() return redirect('score_list') scores1 = Score.objects.all().filter(category='SCI').order_by('sub_category') scores2 = Score.objects.all().filter(category='P').order_by('sub_category') return render(request, 'score_add.html', {'scores1': scores1, 'form': ScoreForm, 'scores2': scores2})
def scores(request): # form = ScoreForm() if request.method == 'POST': form = ScoreForm(request.POST) if form.is_valid(): cd = form.cleaned_data player_name = cd.get('player_name') gender = cd.get('gender') 100m = cd.get('100m') 200m = cd.get('200m') 400m = cd.get('400m') 1500m = cd.get('1500m') 110mH = cd.get('110mH') high_jump = cd.get('high_jump') pole_vault = cd.get('pole_vault') long_jump = cd.get('long_jump') shot = cd.get('shot') discus = cd.get('discus') javeline = cd.get('javeline') 60m = cd.get('60m') 1000m = cd.get('1000m') 60mH = cd.get('60mH') if gender == 'Male': points_100m = 25.4347*((18.00-100m)**1.81) points_200m = 5.8425*((38.00-200m)**1.81) points_400m = 1.53775*((82.00-400m)**1.81) points_1500m = 0.03768*((480.00-1500m)**1.81) points_110mH = 5.74352*((25.50-110mH)**1.81) points_high_jump = 0.8465*((high_jump-75.00)**1.42) points_pole_vault = 0.2797*((pole_vault-100.00)**1.35) points_long_jump = 0.14354*((long_jump-220.00)**1.40) points_shot = 51.39*((shot-1.50)**1.05) points_discus = 12.91*((discus-4.00)**1.10) points_javeline = 10.14*((javelin-7.00)**1.08) points_60m = 58.0150*((11.50-60m)**1.81) points_1000m = 0.08713*((305.50-1000m)**1.85) points_60mH = 20.5173*((15.50-60mH)**1.92) else: points_200m = 4.99087*((42.50-200m)**1.81) points_800m = 0.11193*((254.00-800m)**1.88) points_100mH = 9.23076*((26.70-100mH)**1.835) points_high_jump = 1.84523*((high_jump-75.00)**1.348) points_long_jump = 0.188807*((long_jump-210.00)**1.41) points_shot = 56.0211*((shot-1.50)**1.05) points_javeline = 15.9803*((javelin-3.80)**1.04) points_100m = 17.8570*((21.00-100m)**1.81) points_400m = 1.34285*((91.7-400m)**1.81) points_1500m = 0.02883*((535.00-1500m)**1.88) points_pole_vault = 0.44125*((pole_vault-100.00)**1.35) points_discus = 12.3311*((discus-3.00)**1.10) points_60mH = 20.0479*((17.00-60mH)**1.835)
def add(): teams = Team.query.all() if not teams: return render_template("no_teams.html") form = ScoreForm() form.team_id.choices = [(t.id, t.number) for t in sortTeamsWithPlaceholder(teams)] # don't allow playoff round options during qualifying, or qualifying during playoffs if any(team.highest_round_reached > 3 for team in teams): form.round_number.choices = [(-1, 'Select'), (1, '1'), (2, '2'), (3, '3'), (4, 'Quarterfinals'), (5, 'Semifinals'), (6, 'Finals')] else: form.round_number.choices = [(-1, 'Select'), (1, '1'), (2, '2'), (3, '3')] # Gather and preset the team ID and round number fields if provided in URL preselected_team = request.args.get('team_id', default=None, type=int) preselected_round = request.args.get('round', default=None, type=int) if preselected_team is not None and request.method == 'GET': form.team_id.data = preselected_team if preselected_round is not None and request.method == 'GET': form.round_number.data = preselected_round repeat = request.args.get('repeat', default=False, type=bool) if request.method == 'POST' and request.form['end'] == 'reset': return redirect(url_for(".add", round = preselected_round, repeat = True)) elif request.method == 'POST' and request.form['end'] == 'submit' and form.validate_on_submit(): score = RobotScore(team=form.team_id.data, round_number=form.round_number.data) populate_score(score, form) db.session.add(score) db.session.commit() if repeat: flash('Added score for %s round %s' % (score.team.number, score.round_number), 'success') return redirect(url_for(".add", round = preselected_round, repeat = True)) else: if form.round_number.data <= 3: return redirect(url_for("review")) else: return redirect(url_for(".playoffs")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("scoring/score_form.html", form=form, id=None, repeat=repeat)
def addscore(request, game_id): if request.method == 'POST': form = ScoreForm(request.POST) if form.is_valid(): score = Score() score.score = form.cleaned_data.get("score", "0") score.player = request.user score.game = get_object_or_404(Game, pk=game_id) score.date = datetime.now() score.save() return HttpResponseRedirect(reverse('ranking:index')) else: form = ScoreForm() return render_to_response('ranking/addscore.html', {'form':form, 'game_id':game_id}, context_instance=RequestContext(request))
def course_detail(slug): # check for map variable if request.method == "GET" and request.args.get("map"): session['map_provider'] = request.args.get("map") course = Course.objects.get(slug=slug) # score form form = ScoreForm(request.form) # validate and submit form data if request.method == 'POST' and form.validate(): course_score = ScoreCard( user=g.user, score=form.score.data, baskets=form.baskets.data, course=course ) if course_score.created: course_score.created = form.created.data course_score.save() flash('Thanks for submitting a score!') # TODO: send email to user # TODO: use celery to offload to queue send_mail( to_address=g.user.email, from_address='*****@*****.**', subject='New Dsic Golf Scorecard Score.', plaintext='You just recorded a new score for ' + course.name, html='You just recorded a new score for <b>' + course.name + '</b>' ) # get course data all_scores = ScoreCard.objects.all().filter(course=course).filter( user=g.user ).order_by('-created') # get all the score data we need! data = get_score_data(all_scores) return render_template( 'course_detail.html', title='Course Detail -' + course.name, course=course, form=form, data=data, all_scores=all_scores, )
def addscore(request, game_id): if request.method == "POST": form = ScoreForm(request.POST) if form.is_valid(): score = Score() score.score = form.cleaned_data.get("score", "0") score.player = request.user score.game = get_object_or_404(Game, pk=game_id) score.date = datetime.now() score.save() return HttpResponseRedirect(reverse("ranking:index")) else: form = ScoreForm() return render_to_response( "ranking/addscore.html", {"form": form, "game_id": game_id}, context_instance=RequestContext(request) )
def game_edit(): #---------Edit score for matches---------# form_s = ScoreForm() game_id= request.form['edit_game'] game= model.session.query(model.Game).get(int(game_id)) if form_s.validate_on_submit(): form_s.game_date = game.game_date form_s.home_team = game.home_team form_s.away_team = game.home_team game.home_score = form_s.home_score.data game.away_score = form_s.away_score.data model.session.add(game) model.session.commit() flash('Your changes have been updated. Select \'Save\' to finalize!') return redirect('schedule')
def edit(score_id): score = RobotScore.query.get(score_id) form = ScoreForm(obj=score) del form.team_id del form.round_number if request.method == 'POST' and form.validate_on_submit(): populate_score(score, form) db.session.commit() if score.round_number <= 3: return redirect(url_for("review")) else: return redirect(url_for(".playoffs")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("scoring/score_form.html", form=form, team_id=score.team.number, round_number=score.round_number, id=score.id)
def to_form(self): status_list = ['Won', 'Tied', 'Lost', 'Forfeit'] host_status = status_list[self.host_result] oppoent_status = status_list[self.oppoent_result] date_end = pretty_date(self.end_date) return ScoreForm(host_name = self.host.get().name, host_result = host_status, oppoent_name = self.oppoent.get().name, oppoent_result = oppoent_status, end_date = date_end, game = self.game.urlsafe())
def score_add_update(request, score_id=None): if request.method == 'POST': #Reconstruct a form with the POST data form = ScoreForm(request.POST) if form.is_valid(): new_score = form.save(commit=False) #Make sure it gets owned by the right golfer golfer = Golfer.objects.get(user__id=request.user.id) new_score.golfer = golfer #Finally save the model new_score.save() return HttpResponseRedirect("/score/%i/" % new_score.id) else: return render_to_response('scores/score_form.html', {'form': form}) else: # create form if score_id: form = ScoreForm(instance=Score.objects.get(id=score_id)) else: form = ScoreForm() # create template and pass in form return render_to_response('scores/score_form.html', {'form': form})
def game_edit(): #---------Edit score for matches---------# form_s = ScoreForm() game_id = request.form['edit_game'] game = model.session.query(model.Game).get(int(game_id)) if form_s.validate_on_submit(): form_s.game_date = game.game_date form_s.home_team = game.home_team form_s.away_team = game.home_team game.home_score = form_s.home_score.data game.away_score = form_s.away_score.data model.session.add(game) model.session.commit() flash('Your changes have been updated. Select \'Save\' to finalize!') return redirect('calendar')
def get_calendar(): form = GameForm() today = request.args.get('month') if today == None: today = datetime.date(datetime.now()) print today # --------calendar begins---------# year = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] # by default the calendar begin the week with Monday (day 0) calendar.setfirstweekday(calendar.SUNDAY) #stiringify date and reorganize into integers current = re.split('-', str(today)) current_no = int(current[1]) current_month = year[current_no - 1] current_day = int(re.sub('\A0', '', current[2])) current_yr = int(current[0]) month = calendar.monthcalendar(current_yr, current_no) nweeks = len(month) each_week = [] for w in range(0, nweeks): week = month[w] each_week.append(week) #---------------calender ends-----------# #-----add matches--------# all_teams = model.current_teams() teams = {} for t in all_teams: teams[t.id] = t.teamname # render template to set games form = GameForm() games = model.session.query(model.Game).\ order_by(model.Game.game_date.desc()).all() if form.validate_on_submit(): if form.home_team.data == form.away_team.data: flash("Teams cannot be the same") return redirect('calendar') else: new_game= model.session.\ add(model.Game(game_date = form.game_date.data, home_team = form.home_team.data, away_team = form.away_team.data, home_score = form.home_score.data, away_score = form.away_score.data)) model.session.commit() flash('Game Added!') return redirect('calendar') #----------render form to change score---# form_s = ScoreForm() return render_template('calendar.html', title='Calendar', current_month=current_month, current_yr=current_yr, each_week=each_week, user=current_user, form=form, games=games, form_s=form_s, all_teams=all_teams, teams=teams)
def to_form(self): return ScoreForm(date=str(self.date), player_x=self.player_x.get().name, player_o=self.player_o.get().name, result=self.result)