def get_upcomming_matches(): football_pool = CAFootballPool.all().filter("privacy =", True).fetch(1)[0] return ( CAMatch.all() .filter("football_pool =", football_pool) .filter("date >=", datetime.datetime.now()) .order("date") .fetch(3) )
def post(self): update_session_time() session = get_current_session() check_session_status() if session.is_active(): if session.has_key('active_user'): football_pool_name = self.request.get('football-pool-name') active_user = session['active_user'] active_user_football_pool = CAFootballPool(user=active_user, name=football_pool_name, privacy=False) active_user_football_pool.put() original_pool = CAFootballPool.all().filter("privacy =", True).fetch(1)[0] first_round_matches = eval(self.request.get('first-round-matches')) original_first_round_matches = original_pool.first_round_matches.fetch(18) counter = 0 for match_results in first_round_matches: initials = match_results[0].partition('-') team0_initials = initials[0] initials = initials[2].partition('-') team1_initials = initials[0] team0 = CATeam.all().filter("name =", get_team_whole_name(team0_initials)).fetch(1)[0] team1 = CATeam.all().filter("name =", get_team_whole_name(team1_initials)).fetch(1)[0] teams_list = [team0.key(), team1.key()] original_match = original_first_round_matches[counter] active_user_match = CAMatch(date=original_match.date, goals_team1=int(match_results[1]), goals_team2=int(match_results[3]), teams=teams_list, football_pool=active_user_football_pool) active_user_match.put() counter += 1 second_round_matches = eval(self.request.get('second-round-matches')) original_second_round_matches = original_pool.second_round_matches.fetch(8) for i in range(0, len(original_second_round_matches)): initials = second_round_matches[i][0].partition('-') initials = initials[2].partition('-') team0_initials = initials[0] initials = initials[2].partition('-') team1_initials = initials[0] team0 = CATeam.all().filter("name =", get_team_whole_name(team0_initials)).fetch(1)[0] team1 = CATeam.all().filter("name =", get_team_whole_name(team1_initials)).fetch(1)[0] #print team0.name + ' ' + second_round_matches[i][1] + ' ' + second_round_matches[i][3] + ' ' + team1.name teams_list = [team0.key(), team1.key()] original_match = original_second_round_matches[i] active_user_match = CAMatch(date=original_match.date, goals_team1=int(second_round_matches[i][1]), goals_team2=int(second_round_matches[i][3]), teams=teams_list, football_pool=active_user_football_pool) active_user_match.put() # template_values = { # 'session_status': True, # 'user': session['active_user'], # 'top_scorers': get_top_scorers(), # 'top_users': get_top_users_global_ranking(), # 'last_jackpot': get_last_jackpot() # } # # render_template(self, 'home.html', template_values) self.redirect('/list/football-pools/view') else: self.redirect('/')