def get(self): session = get_current_session() check_session_status() if session.is_active(): active_user = session['active_user'] active_user_football_pools = CAFootballPool.all().filter("user ="******"privacy =", False).fetch(1000) football_pools_info = [] for football_pool in active_user_football_pools: if not football_pool.payment: football_pools_info.append((football_pool.name, 'Por Pagar', '-')) else: if football_pool.payment.status: football_pools_info.append((football_pool.name, 'Pagada', str(get_total_points(football_pool)))) else: football_pools_info.append((football_pool.name, 'Esperando Confirmación de Pago', '-')) template_values = { 'session_status': True, 'user': session['active_user'], 'football_pools_info': football_pools_info, 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot() } render_template(self, 'user_profile.html', template_values) else: self.redirect('/')
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(): original_pool = CAFootballPool.all().filter("privacy =", True).fetch(1)[0] first_round_matches = original_pool.first_round_matches.fetch(18) final_matches = [] for match in first_round_matches: team_list = db.get(match.teams) match_list = [] key0 = team_list[0].name[:3] key1 = team_list[1].name[:3] final_key1 = key0 + '-' + key1 + '-g1' final_key2 = key0 + '-' + key1 + '-g2' match_list.append(final_key1) match_list.append(self.request.get(final_key1)) match_list.append(final_key2) match_list.append(self.request.get(final_key2)) final_matches.append(match_list) first_round_winners = eval(self.request.get('first-round-winners')) quarter_finals_teams = [] counter = 1 for winners in first_round_winners: initials = winners[1].partition('-') team_names = [] team_names.append(get_team_whole_name(initials[0])) team_names.append(get_team_whole_name(initials[2])) team_names.append(counter) quarter_finals_teams.append(team_names) counter += 1 template_values = { 'session_status': True, 'user': session['active_user'], 'football_pool_name': self.request.get('football-pool-name'), 'first_round_matches': str(final_matches), 'quarter_finals_teams': quarter_finals_teams, 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot() } render_template(self, 'create_step2.html', template_values) else: self.redirect('/')
def get_top_users_global_ranking(): counter = 0 position_points = [] football_pools = CAFootballPool.all().filter("privacy =", False).fetch(10000) for football_pool in football_pools: if football_pool.payment: position_points.append((counter, get_total_points(football_pool))) counter += 1 football_pools_sorted_by_total_points = sorted( position_points, key=lambda position_point: position_point[1], reverse=True ) top_football_pools_sorted_by_total_points = football_pools_sorted_by_total_points[:5] top_users = [] counter = 0 for position_point in top_football_pools_sorted_by_total_points: football_pool = football_pools[position_point[0]] user = football_pool.user if user.type == 0: username = user.google_user.nickname elif user.type == 1: username = user.facebook_user.name else: username = user.native_user.name if counter % 2 == 1: row = "odd" else: row = "pair" top_users.append((username, football_pool.name, position_point[1], row)) counter += 1 return top_users
def post(self): session = get_current_session() check_session_status() if session.is_active(): save = self.request.get('save') active_user = session['active_user'] message = '' if active_user.type == 2: if save: native_user = CANativeUser.get(active_user.native_user.key()) native_user.name = self.request.get('name') native_user.email = self.request.get('email') native_user.password = self.request.get('password') native_user.put() active_user.native_user = native_user active_user.put() session['active_user'] = active_user message = 'Sus datos fueron actualizados exitosamente' active_user_football_pools = CAFootballPool.all().filter("user ="******"privacy =", False).fetch(1000) template_values = { 'session_status': True, 'user': session['active_user'], 'football_pools': active_user_football_pools, 'message': message, 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot() } render_template(self, 'list_football_pools_to_view.html', template_values) else: self.redirect('/')
def get(self): update_session_time() session = get_current_session() check_session_status() if session.is_active(): if session.has_key('active_user'): active_user = session['active_user'] active_user_football_pools = CAFootballPool.all().filter("user ="******"privacy =", False).fetch(1000) sandra_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGJqdAQw') christian_key = Key('ag5zfnR1cXVpbmllbGFjYXINCxIGQ0FVc2VyGNR1DA') mariel_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGIG0AQw') francisco_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGIbUAQw') ca_user_key = active_user.key() special_user = False if ca_user_key == sandra_key or ca_user_key == christian_key or ca_user_key == mariel_key or ca_user_key == francisco_key: special_user = True template_values = { 'session_status': True, 'user': active_user, 'football_pools': active_user_football_pools, 'message':'', 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot(), 'special_user': special_user } render_template(self, 'list_football_pools_to_pay.html', template_values) else: self.redirect('/')
def get(self): update_session_time() session = get_current_session() check_session_status() if session.is_active(): member_request = CARequestGroupMembership.get(Key(self.request.get('request'))) active_user = session['active_user'] active_user.groups.append(member_request.group.key()) active_user.put() active_user_football_pools = CAFootballPool.all().filter("user ="******"privacy =", False).fetch(1000) members = member_request.group.members.fetch(10000) for football_pool in active_user_football_pools: if football_pool.payment: groups = active_user.groups group_ranking = CAGroupRanking(football_pool=football_pool, group=member_request.group, rank=len(members)) group_ranking.put() CARequestGroupMembership.delete(member_request) # 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/groups/view') else: self.redirect('/')
def post(self): update_session_time() session = get_current_session() check_session_status() if session.is_active(): selected = self.request.get('selected_football_pool') view = self.request.get('view') pay = self.request.get('pay') edit = self.request.get('edit') if selected != "default": selected_football_pool_key = Key(selected) if view: selected_football_pool = CAFootballPool.get(selected_football_pool_key) first_round_matches = selected_football_pool.first_round_matches ga_team_set = Set() gb_team_set = Set() gc_team_set = Set() for match in first_round_matches: team_list = db.get(match.teams) if team_list[0].group.name == 'A': ga_team_set.add(team_list[0].name) ga_team_set.add(team_list[1].name) elif team_list[0].group.name == 'B': gb_team_set.add(team_list[0].name) gb_team_set.add(team_list[1].name) else: gc_team_set.add(team_list[0].name) gc_team_set.add(team_list[1].name) a_teams = list(ga_team_set) b_teams = list(gb_team_set) c_teams = list(gc_team_set) ga_teams_info = [] gb_teams_info = [] gc_teams_info = [] for counter in range(0, 4): if counter % 2 == 1: ga_teams_info.append((a_teams[counter], "odd")) gb_teams_info.append((b_teams[counter], "odd")) gc_teams_info.append((c_teams[counter], "odd")) else: ga_teams_info.append((a_teams[counter], "pair")) gb_teams_info.append((b_teams[counter], "pair")) gc_teams_info.append((c_teams[counter], "pair")) ga_results = [] gb_results = [] gc_results = [] for match in first_round_matches: match_info = [] team_list = db.get(match.teams) match_info.append(team_list[0].name) match_info.append(str(match.goals_team1)) match_info.append(str(match.goals_team2)) match_info.append(team_list[1].name) if team_list[0].group.name == 'A': ga_results.append(match_info) elif team_list[0].group.name == 'B': gb_results.append(match_info) else: gc_results.append(match_info) second_round_matches = selected_football_pool.second_round_matches.fetch(8) quarter_finals_matches = [] for i in range(0, 4): match = second_round_matches[i] match_info = [] team_list = db.get(match.teams) match_info.append(team_list[0].name) match_info.append(str(match.goals_team1)) match_info.append(str(match.goals_team2)) match_info.append(team_list[1].name) match_info.append(str(i + 1)) quarter_finals_matches.append(match_info) semi_final_matches = [] for i in range(4, 6): match = second_round_matches[i] match_info = [] team_list = db.get(match.teams) match_info.append(team_list[0].name) match_info.append(str(match.goals_team1)) match_info.append(str(match.goals_team2)) match_info.append(team_list[1].name) match_info.append(str(i - 3)) semi_final_matches.append(match_info) match = second_round_matches[6] third_fourth_match = [] team_list = db.get(match.teams) third_fourth_match.append(team_list[0].name) third_fourth_match.append(str(match.goals_team1)) third_fourth_match.append(str(match.goals_team2)) third_fourth_match.append(team_list[1].name) match = second_round_matches[7] final_match = [] team_list = db.get(match.teams) final_match.append(team_list[0].name) final_match.append(str(match.goals_team1)) final_match.append(str(match.goals_team2)) final_match.append(team_list[1].name) template_values = { 'session_status': True, 'user': session['active_user'], 'name': selected_football_pool.name, 'groups': [(ga_results, ga_teams_info, 'A'), (gb_results, gb_teams_info, 'B'), (gc_results, gc_teams_info, 'C')], 'quarter_finals_matches': quarter_finals_matches, 'semi_final_matches': semi_final_matches, 'third_fourth_match': third_fourth_match, 'final_match': final_match, 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot() } render_template(self, 'view_football_pool.html', template_values) elif pay: selected_football_pool = CAFootballPool.get(Key(self.request.get('selected_football_pool'))) if selected_football_pool.payment: active_user = session['active_user'] active_user_football_pools = CAFootballPool.all().filter("user ="******"privacy =", False).fetch(1000) template_values = { 'session_status': True, 'user': session['active_user'], 'football_pools': active_user_football_pools, 'message':'Esta quiniela ya fue pagada', 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot() } render_template(self, 'list_football_pools_to_pay.html', template_values) else: template_values = { 'session_status': True, 'user': session['active_user'], 'selected_football_pool_key': self.request.get('selected_football_pool'), 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot(), 'selected_user': '', 'searched_users': [] } render_template(self, 'pay_football_pool.html', template_values) elif edit: selected_football_pool = CAFootballPool.get(selected_football_pool_key) first_round_matches = selected_football_pool.first_round_matches ga_team_set = Set() gb_team_set = Set() gc_team_set = Set() for match in first_round_matches: team_list = db.get(match.teams) if team_list[0].group.name == 'A': ga_team_set.add(team_list[0].name) ga_team_set.add(team_list[1].name) elif team_list[0].group.name == 'B': gb_team_set.add(team_list[0].name) gb_team_set.add(team_list[1].name) else: gc_team_set.add(team_list[0].name) gc_team_set.add(team_list[1].name) a_teams = list(ga_team_set) b_teams = list(gb_team_set) c_teams = list(gc_team_set) ga_teams_info = [] gb_teams_info = [] gc_teams_info = [] for counter in range(0, 4): if counter % 2 == 1: ga_teams_info.append((a_teams[counter], "odd")) gb_teams_info.append((b_teams[counter], "odd")) gc_teams_info.append((c_teams[counter], "odd")) else: ga_teams_info.append((a_teams[counter], "pair")) gb_teams_info.append((b_teams[counter], "pair")) gc_teams_info.append((c_teams[counter], "pair")) ga_results = [] gb_results = [] gc_results = [] for match in first_round_matches: match_info = [] team_list = db.get(match.teams) match_info.append(team_list[0].name) match_info.append(str(match.goals_team1)) match_info.append(str(match.goals_team2)) match_info.append(team_list[1].name) if team_list[0].group.name == 'A': ga_results.append(match_info) elif team_list[0].group.name == 'B': gb_results.append(match_info) else: gc_results.append(match_info) template_values = { 'session_status': True, 'user': session['active_user'], 'name': selected_football_pool.name, 'groups': [(ga_results, ga_teams_info, 'A'), (gb_results, gb_teams_info, 'B'), (gc_results, gc_teams_info, 'C')], 'football_pool_key': selected_football_pool.key(), 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot() } render_template(self, 'edit_step1.html', template_values) else: if view or edit: self.redirect('/list/football-pools/view') elif pay: self.redirect('/list/football-pools/pay') else: self.redirect('/')
def get_total_points(football_pool): original_pool = CAFootballPool.all().filter("privacy =", True).fetch(1)[0] original_pool_first_round_matches = original_pool.first_round_matches.fetch(18) football_pool_first_round_matches = football_pool.first_round_matches.fetch(18) points = 0 for x in range(0, 18): original_match_team1_goals = original_pool_first_round_matches[x].goals_team1 original_match_team2_goals = original_pool_first_round_matches[x].goals_team2 match_team1_goals = football_pool_first_round_matches[x].goals_team1 match_team2_goals = football_pool_first_round_matches[x].goals_team2 if (original_match_team1_goals == match_team1_goals) and (original_match_team2_goals == match_team2_goals): points += 5 elif ( (original_match_team1_goals > original_match_team2_goals) and (match_team1_goals > match_team2_goals) ) or ((original_match_team1_goals < original_match_team2_goals) and (match_team1_goals < match_team2_goals)): points += 3 if ( (original_match_team1_goals != -1) and (original_match_team2_goals != -1) and ( (original_match_team1_goals == original_match_team2_goals) and (match_team1_goals == match_team2_goals) ) ): points += 3 original_pool_second_round_matches = original_pool.second_round_matches.fetch(8) football_pool_second_round_matches = football_pool.second_round_matches.fetch(8) # Quarter finals matches original_teams = [] teams = [] for x in range(0, 4): if original_pool_second_round_matches[x].teams: original_team1 = CATeam.get(original_pool_second_round_matches[x].teams[0]).name original_team2 = CATeam.get(original_pool_second_round_matches[x].teams[1]).name team1 = CATeam.get(football_pool_second_round_matches[x].teams[0]).name team2 = CATeam.get(football_pool_second_round_matches[x].teams[1]).name # Puntos por pegar orden en cuartos de final if original_team1 == team1: points += 3 if original_team2 == team2: points += 3 original_teams.append(original_team1) original_teams.append(original_team2) teams.append(team1) teams.append(team2) # Puntos por pegar partido completo points += add_points_for_match( original_team1, original_pool_second_round_matches[x].goals_team1, original_team2, original_pool_second_round_matches[x].goals_team2, team1, football_pool_second_round_matches[x].goals_team1, team2, football_pool_second_round_matches[x].goals_team2, ) # Puntos por adivinar equipo for team in teams: if team in original_teams: points += 3 original_teams = [] teams = [] # Semi final matches for x in range(4, 6): if original_pool_second_round_matches[x].teams: original_team1 = CATeam.get(original_pool_second_round_matches[x].teams[0]).name original_team2 = CATeam.get(original_pool_second_round_matches[x].teams[1]).name team1 = CATeam.get(football_pool_second_round_matches[x].teams[0]).name team2 = CATeam.get(football_pool_second_round_matches[x].teams[1]).name # Puntos por pegar partido completo points += add_points_for_match( original_team1, original_pool_second_round_matches[x].goals_team1, original_team2, original_pool_second_round_matches[x].goals_team2, team1, football_pool_second_round_matches[x].goals_team1, team2, football_pool_second_round_matches[x].goals_team2, ) original_teams.append(original_team1) original_teams.append(original_team2) teams.append(team1) teams.append(team2) # Puntos por adivinar equipo for team in teams: if team in original_teams: points += 3 original_teams = [] teams = [] # Third-fourth match if original_pool_second_round_matches[6].teams: original_team1 = CATeam.get(original_pool_second_round_matches[6].teams[0]).name original_team2 = CATeam.get(original_pool_second_round_matches[6].teams[1]).name team1 = CATeam.get(football_pool_second_round_matches[6].teams[0]).name team2 = CATeam.get(football_pool_second_round_matches[6].teams[1]).name original_teams.append(original_team1) original_teams.append(original_team2) teams.append(team1) teams.append(team2) # Puntos por pegar partido completo points += add_points_for_match( original_team1, original_pool_second_round_matches[6].goals_team1, original_team2, original_pool_second_round_matches[6].goals_team2, team1, football_pool_second_round_matches[6].goals_team1, team2, football_pool_second_round_matches[6].goals_team2, ) # Puntos por adivinar equipo for team in teams: if team in original_teams: points += 3 original_teams = [] teams = [] # Final if original_pool_second_round_matches[7].teams: original_team1 = CATeam.get(original_pool_second_round_matches[7].teams[0]).name original_team2 = CATeam.get(original_pool_second_round_matches[7].teams[1]).name team1 = CATeam.get(football_pool_second_round_matches[7].teams[0]).name team2 = CATeam.get(football_pool_second_round_matches[7].teams[1]).name original_teams.append(original_team1) original_teams.append(original_team2) teams.append(team1) teams.append(team2) # Puntos por pegar partido completo points += add_points_for_match( original_team1, original_pool_second_round_matches[7].goals_team1, original_team2, original_pool_second_round_matches[7].goals_team2, team1, football_pool_second_round_matches[7].goals_team1, team2, football_pool_second_round_matches[7].goals_team2, ) # Puntos por adivinar equipo for team in teams: if team in original_teams: points += 3 return points
def post(self): update_session_time() session = get_current_session() check_session_status() if session.is_active(): search_user = self.request.get('search_user') save = self.request.get('save') if search_user: active_user = session['active_user'] search_term = self.request.get('search') search_result = [] if search_term: users = CAUser.all().fetch(10000) logging.debug('Iterando por usuarios') for user in users: if active_user.key() != user.key(): username = [] logging.debug('tipo de usuario: ' + str(user.type)) if user.type == 0: nickname = user.google_user.nickname() email = user.google_user.email() if (search_term.lower() in str(nickname).lower()) or (search_term.lower() in str(email).lower()): username = nickname + ' ' + email elif user.type == 1: name = user.facebook_user.name if search_term.lower() in str(name).lower(): username = name else: logging.debug('Usuario nativo!') logging.debug('key de usuario: ' + str(user.key())) name = user.native_user.name email = user.native_user.email if (search_term.lower() in str(name).lower()) or (search_term.lower() in str(email).lower()): username = name + ' ' + email if username: search_result.append((str(username), str(user.key()))) template_values = { 'session_status': True, 'user': session['active_user'], 'searched_users': search_result, 'members': eval(self.request.get('last-members')), 'name': self.request.get('name'), 'last_search': str(search_result), 'last_members': self.request.get('last-members'), 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot() } render_template(self, 'create_competition_group.html', template_values) elif save: active_user = session['active_user'] name = self.request.get('name') new_group = CACompetitonGroup(name=name, privacy=False) new_group.put() active_user.groups.append(new_group.key()) active_user.put() active_user_football_pools = CAFootballPool.all().filter("user ="******"privacy =", False).fetch(1000) for football_pool in active_user_football_pools: if football_pool.payment: members = new_group.members.fetch(10000) group_ranking = CAGroupRanking(football_pool=football_pool, group=new_group, rank=len(members)) group_ranking.put() members = eval(self.request.get('last-members')) for member in members: member_key = Key(member[1]) user = CAUser.get(member_key) users = [] users.append(active_user.key()) users.append(user.key()) request_membership = CARequestGroupMembership(users=users, status=False, group=new_group) request_membership.put() #self.redirect('/list/groups/ranking') competition_groups = CACompetitonGroup.get(active_user.groups) template_values = { 'session_status': True, 'user': session['active_user'], 'groups': competition_groups, 'pending_membership_requests': get_pending_membership_requests(active_user), 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot(), 'message': 'Se han enviado con éxito las invitaciones a los usuarios para formar parte del grupo.' } render_template(self, 'list_competition_groups_to_ranking.html', template_values) else: self.redirect('/')
def get(self): session = get_current_session() check_session_status() upcomming_matches = get_upcomming_matches() upcomming_matches_info = [] for match in upcomming_matches: team_list = db.get(match.teams) upcomming_matches_info.append((team_list[0].name, team_list[1].name, str(match.date))) copa_america = CAFootballPool.all().filter("privacy =", True).fetch(1)[0] copa_america_first_round_matches = copa_america.first_round_matches ga_team_set = Set() gb_team_set = Set() gc_team_set = Set() for match in copa_america_first_round_matches: team_list = db.get(match.teams) if team_list[0].group.name == "A": ga_team_set.add(team_list[0].name) ga_team_set.add(team_list[1].name) elif team_list[0].group.name == "B": gb_team_set.add(team_list[0].name) gb_team_set.add(team_list[1].name) else: gc_team_set.add(team_list[0].name) gc_team_set.add(team_list[1].name) a_teams = list(ga_team_set) b_teams = list(gb_team_set) c_teams = list(gc_team_set) ga_teams_info = [] gb_teams_info = [] gc_teams_info = [] for counter in range(0, 4): if counter % 2 == 1: ga_teams_info.append((a_teams[counter], "odd")) gb_teams_info.append((b_teams[counter], "odd")) gc_teams_info.append((c_teams[counter], "odd")) else: ga_teams_info.append((a_teams[counter], "pair")) gb_teams_info.append((b_teams[counter], "pair")) gc_teams_info.append((c_teams[counter], "pair")) ga_results = [] gb_results = [] gc_results = [] for match in copa_america_first_round_matches: match_info = [] team_list = db.get(match.teams) match_info.append(team_list[0].name) match_info.append(str(match.goals_team1)) match_info.append(str(match.goals_team2)) match_info.append(team_list[1].name) if team_list[0].group.name == "A": ga_results.append(match_info) elif team_list[0].group.name == "B": gb_results.append(match_info) else: gc_results.append(match_info) second_round_matches = copa_america.second_round_matches.fetch(8) quarter_finals_matches = [] for i in range(0, 4): match = second_round_matches[i] match_info = [] team_list = db.get(match.teams) if team_list: match_info.append(team_list[0].name) match_info.append(str(match.goals_team1)) match_info.append(str(match.goals_team2)) match_info.append(team_list[1].name) match_info.append(str(i + 1)) else: match_info.append("?") match_info.append("") match_info.append("") match_info.append("?") match_info.append(str(i + 1)) quarter_finals_matches.append(match_info) semi_final_matches = [] for i in range(4, 6): match = second_round_matches[i] match_info = [] team_list = db.get(match.teams) if team_list: match_info.append(team_list[0].name) match_info.append(str(match.goals_team1)) match_info.append(str(match.goals_team2)) match_info.append(team_list[1].name) match_info.append(str(i - 3)) else: match_info.append("?") match_info.append("") match_info.append("") match_info.append("?") match_info.append(str(i - 3)) semi_final_matches.append(match_info) match = second_round_matches[6] third_fourth_match = [] team_list = db.get(match.teams) if team_list: third_fourth_match.append(team_list[0].name) third_fourth_match.append(str(match.goals_team1)) third_fourth_match.append(str(match.goals_team2)) third_fourth_match.append(team_list[1].name) else: third_fourth_match.append("?") third_fourth_match.append("") third_fourth_match.append("") third_fourth_match.append("?") match = second_round_matches[7] final_match = [] team_list = db.get(match.teams) if team_list: final_match.append(team_list[0].name) final_match.append(str(match.goals_team1)) final_match.append(str(match.goals_team2)) final_match.append(team_list[1].name) else: final_match.append("?") final_match.append("") final_match.append("") final_match.append("?") if session.is_active(): template_values = { "session_status": True, "user": session["active_user"], "upcomming_matches_info": upcomming_matches_info, "name": copa_america.name, "groups": [ (ga_results, ga_teams_info, "A"), (gb_results, gb_teams_info, "B"), (gc_results, gc_teams_info, "C"), ], "quarter_finals_matches": quarter_finals_matches, "semi_final_matches": semi_final_matches, "third_fourth_match": third_fourth_match, "final_match": final_match, "top_scorers": get_top_scorers(), "top_users": get_top_users_global_ranking(), "last_jackpot": get_last_jackpot(), } else: template_values = { "session_status": False, "upcomming_matches_info": upcomming_matches_info, "name": copa_america.name, "groups": [ (ga_results, ga_teams_info, "A"), (gb_results, gb_teams_info, "B"), (gc_results, gc_teams_info, "C"), ], "quarter_finals_matches": quarter_finals_matches, "semi_final_matches": semi_final_matches, "third_fourth_match": third_fourth_match, "final_match": final_match, "top_scorers": get_top_scorers(), "top_users": get_top_users_global_ranking(), "last_jackpot": get_last_jackpot(), } render_template(self, "copa_america.html", template_values)
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('/')
def get(self): update_session_time() session = get_current_session() check_session_status() if session.is_active(): original_pool = CAFootballPool.all().filter("privacy =", True).fetch(1)[0] first_round_matches = original_pool.first_round_matches.fetch(18) group_a_teams = [] group_b_teams = [] group_c_teams = [] ga_teams = Set() gb_teams = Set() gc_teams = Set() for match in first_round_matches: team_list = db.get(match.teams) if team_list[0].group.name == 'A': group_a_teams.append((team_list[0].name, team_list[1].name)) ga_teams.add(team_list[0].name) ga_teams.add(team_list[1].name) elif team_list[0].group.name == 'B': group_b_teams.append((team_list[0].name, team_list[1].name)) gb_teams.add(team_list[0].name) gb_teams.add(team_list[1].name) else: group_c_teams.append((team_list[0].name, team_list[1].name)) gc_teams.add(team_list[0].name) gc_teams.add(team_list[1].name) a_teams = list(ga_teams) b_teams = list(gb_teams) c_teams = list(gc_teams) ga_teams = [] gb_teams = [] gc_teams = [] for counter in range(0, 4): if counter % 2 == 1: ga_teams.append((a_teams[counter], "odd")) gb_teams.append((b_teams[counter], "odd")) gc_teams.append((c_teams[counter], "odd")) else: ga_teams.append((a_teams[counter], "pair")) gb_teams.append((b_teams[counter], "pair")) gc_teams.append((c_teams[counter], "pair")) sandra_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGJqdAQw') christian_key = Key('ag5zfnR1cXVpbmllbGFjYXINCxIGQ0FVc2VyGNR1DA') mariel_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGIG0AQw') francisco_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGIbUAQw') ca_user_key = session['active_user'].key() special_user = False if ca_user_key == sandra_key or ca_user_key == christian_key or ca_user_key == mariel_key or ca_user_key == francisco_key: special_user = True template_values = { 'session_status': True, 'user': session['active_user'], 'groups': [(group_a_teams, ga_teams, 'A'), (group_b_teams, gb_teams, 'B'), (group_c_teams, gc_teams, 'C')], 'top_scorers': get_top_scorers(), 'top_users': get_top_users_global_ranking(), 'last_jackpot': get_last_jackpot(), 'special_user': special_user } render_template(self, 'create_step1.html', template_values) else: self.redirect('/')