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('/')
Ejemplo n.º 2
0
 def get(self):
     session = get_current_session()
     
     check_session_status()
         
     if session.is_active():
         if session.has_key('active_user'):
             active_user = session['active_user']
             
             global_competition_group = CACompetitonGroup.all().filter("privacy =", True).fetch(1)[0]
             global_rank = CAGroupRanking.gql("WHERE group = :1 ORDER BY rank", global_competition_group.key()).fetch(10000)
             
             global_rank_list = []
             
             for rank in global_rank:
                 if rank.user.key() == active_user.key():
                     current_user = True
                 else:
                     current_user = False
                 
                 if rank.user.type == 0:
                     user_name = rank.user.google_user
                 elif rank.user.type == 1:
                     user_name = rank.user.facebook_user.name
                 else:
                     user_name = rank.user.native_user.name
                 
                 global_rank_list.append((user_name, rank.rank, current_user))
             
             template_values = {
                 'session_status': True,
                 'user': session['active_user'],
                 'ranking': global_rank_list,
                 'competition_group_name': global_competition_group.name,
                 'top_scorers': get_top_scorers(),
                 'top_users': get_top_users_global_ranking(),
                 'last_jackpot': get_last_jackpot()
             }
             
             render_template(self, 'view_global_ranking.html', template_values)
     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_competition_group')
         
         edit = self.request.get('edit')
         ranking = self.request.get('ranking')
         
         if selected != "default":
             selected_competition_group_key = Key(selected)
             
             if edit:
                 global_group = CACompetitonGroup.all().filter("privacy =", True).fetch(1)[0]
                 
                 if (selected_competition_group_key != global_group.key()):
                     self.redirect('/edit/group?id=' + selected)
                 else:
                     self.redirect('/list/groups/view')
             elif ranking:
                 competition_group = CACompetitonGroup.get(selected_competition_group_key)
                 
                 group_ranking = CAGroupRanking.all().filter("group =", selected_competition_group_key).fetch(10000)
                 
                 active_user = session['active_user']
                 active_user_football_pools = active_user.football_pools
                 
                 active_user_football_pools_keys = []
                 for football_pool in active_user_football_pools: 
                     active_user_football_pools_keys.append(football_pool.key())
                 
                 group_ranking_list = []
                 
                 for rank in group_ranking:
                     if rank.football_pool.key() in active_user_football_pools_keys:
                         selected = True
                     else:
                         selected = False
                     
                     if rank.football_pool.user.type == 0:
                         name = rank.football_pool.user.google_user.nickname()
                     elif rank.football_pool.user.type == 1:
                         name = rank.football_pool.user.facebook_user.name
                     else:
                         name = rank.football_pool.user.native_user.name
                         
                     group_ranking_list.append((name, rank.football_pool.name, get_total_points(rank.football_pool), selected, rank.football_pool.key()))
                     
                 sorted_group_ranking_list = sorted(group_ranking_list,key=lambda position: position[2], reverse=True)    
                 comments = CAGroupComment.all().filter("group =", competition_group).fetch(10000)
                 comments_info = []
                 
                 for comment in comments:
                     if comment.user.type == 0:
                         name = comment.user.google_user.nickname()
                     elif comment.user.type == 1:
                         name = comment.user.facebook_user.name
                     else:
                         name = comment.user.native_user.name
                         
                     comments_info.append((name, str(comment.date.day) + '/' + str(comment.date.month) + '/' + str(comment.date.year) + ' ' + str(comment.date.hour) + ':' + str(comment.date.minute), comment.comment))
                     
                 template_values = {
                     'session_status': True,
                     'user': active_user,
                     'competition_group_name': competition_group.name,
                     'group_ranking': sorted_group_ranking_list,
                     'top_scorers': get_top_scorers(),
                     'top_users': get_top_users_global_ranking(),
                     'last_jackpot': get_last_jackpot(),
                     'comments': comments_info,
                     'selected_group_key': self.request.get('selected_competition_group'),
                 }
                 
                 render_template(self, 'ranking.html', template_values)
         else:
             if edit:
                 self.redirect('/list/groups/view')
             elif ranking:
                 self.redirect('/list/groups/ranking')
     else:
         self.redirect('/')
    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('/')
Ejemplo n.º 5
0
    def post(self):
        update_session_time()
        session = get_current_session()
        check_session_status()

        if session.is_active():
            comment_text = self.request.get("comment-text")
            selected_competition_group_key = Key(self.request.get("selected_group_key"))
            competition_group = CACompetitonGroup.get(selected_competition_group_key)

            google_time = datetime.datetime.today()
            delta = datetime.timedelta(minutes=270)
            comment_time = google_time - delta

            comment = CAGroupComment(
                group=competition_group, user=session["active_user"], comment=comment_text, date=comment_time
            )
            comment.put()

            group_ranking = CAGroupRanking.all().filter("group =", selected_competition_group_key).fetch(10000)

            active_user = session["active_user"]
            active_user_football_pools = active_user.football_pools

            active_user_football_pools_keys = []
            for football_pool in active_user_football_pools:
                active_user_football_pools_keys.append(football_pool.key())

            group_ranking_list = []

            for rank in group_ranking:
                if rank.football_pool.key() in active_user_football_pools_keys:
                    selected = True
                else:
                    selected = False

                if rank.football_pool.user.type == 0:
                    name = rank.football_pool.user.google_user.nickname()
                elif rank.football_pool.user.type == 1:
                    name = rank.football_pool.user.facebook_user.name
                else:
                    name = rank.football_pool.user.native_user.name

                group_ranking_list.append(
                    (
                        name,
                        rank.football_pool.name,
                        get_total_points(rank.football_pool),
                        selected,
                        rank.football_pool.key(),
                    )
                )

            comments = CAGroupComment.all().filter("group =", competition_group).fetch(10000)
            comments_info = []

            for comment in comments:
                if comment.user.type == 0:
                    name = comment.user.google_user.nickname()
                elif comment.user.type == 1:
                    name = comment.user.facebook_user.name
                else:
                    name = comment.user.native_user.name

                comments_info.append(
                    (
                        name,
                        str(comment.date.day)
                        + "/"
                        + str(comment.date.month)
                        + "/"
                        + str(comment.date.year)
                        + " "
                        + str(comment.date.hour)
                        + ":"
                        + str(comment.date.minute),
                        comment.comment,
                    )
                )

            template_values = {
                "session_status": True,
                "user": active_user,
                "competition_group_name": competition_group.name,
                "group_ranking": group_ranking_list,
                "top_scorers": get_top_scorers(),
                "top_users": get_top_users_global_ranking(),
                "last_jackpot": get_last_jackpot(),
                "comments": comments_info,
                "selected_group_key": self.request.get("selected_group_key"),
            }

            render_template(self, "ranking.html", template_values)
        else:
            self.redirect("/")