def post(self):
     # Insert your own CHALLONGE Information.
     api.set_credentials(CHALLONGE_USERANME, CHALLONGE_API)
     league_key_string = self.request.get("league_key_string")
     tournament_type = self.request.get("type")
     entrants = self.request.get("entrants", allow_multiple=True)
     if len(entrants) < 2:
         self.redirect("/tournament?league_key_string=" + league_key_string)
         return
     league_key = ndb.Key(urlsafe=league_key_string)
     league_model = league_key.get()
     if not checkAdmin(league_model, users.get_current_user().email()):
         return
     bracket_name = league_model.name + " " + datetime.now().strftime("%Y-%m-%d %H:%M:%S")
     bracket_url = league_model.name + datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
     bracket_url = bracket_url.replace(" ", "")
     if tournament_type == "swiss":
         rounds = math.floor((len(entrants) * 2) / 3)
         tournaments.create(bracket_name, bracket_url, tournament_type, swiss_rounds=rounds)
     else:
         tournaments.create(bracket_name, bracket_url, tournament_type)
     tournament = tournaments.show(bracket_url)
     for entrant in entrants:
         participants.create(tournament["id"], entrant)
     tournaments.publish(tournament["id"])
     tournaments.start(tournament["id"])
     league_model.tournaments.append(bracket_url)
     league_model.put()
     self.redirect("/tournament?league_key_string=" + league_key_string + "&bracket_url=" + bracket_url)
 def get(self):
   user = users.get_current_user()
   if not user:
     template_params = {
       'user': False,
       'url': users.create_login_url('/manage'),
       'about_active': True
       #no user means no league selected is possible
     }
     render_template(self, 'about.html', template_params)
   else:
     league_key_string = self.request.get("league_key_string")
     template_params = {
       'user': True,
       'user_email': user.email(),
       'url': users.create_logout_url('/'),
       'about_active': True,
     }
     if(league_key_string):
       league_key = ndb.Key(urlsafe=league_key_string)
       league_model = league_key.get()
       if checkAdmin(league_model, users.get_current_user().email()):
         template_params['admin'] = True
       template_params['league_selected'] = True
       template_params['league_name'] = league_model.name
       template_params['league_key_string'] = league_key.urlsafe()
     render_template(self, 'about.html', template_params)
Beispiel #3
0
    def get(self):
        user = users.get_current_user()
        if not user:
            render_template(self, 'error_no_user.html',
                            {'url': users.create_login_url('/manage')})
            return
        league_key_string = self.request.get("league_key_string")
        template_params = {
            'user': True,
            'user_email': user.email(),
            'rank_active': True,
            'url': users.create_logout_url('/'),
        }
        if not league_key_string:
            render_template(self, 'error_no_league.html', template_params)
            return
        league_key = ndb.Key(urlsafe=league_key_string)
        league_model = league_key.get()
        if checkAdmin(league_model, user.email()):
            template_params['admin'] = True
        members = MemberModel.query(
            ancestor=league_key).order(-MemberModel.rank)
        number_of_members = MemberModel.query(ancestor=league_key).count()

        template_params['zipped_ordered_list'] = zip(
            range(1, number_of_members + 1), members)
        template_params['league_selected'] = True
        template_params['league_name'] = league_model.name
        template_params['league_key_string'] = league_key.urlsafe()

        render_template(self, '/ranking.html', template_params)
Beispiel #4
0
 def post(self):
     league_key_string = self.request.get('league_key_string')
     league_key = ndb.Key(urlsafe=league_key_string)
     result = []
     league = league_key.get()
     num_members = MemberModel.query(ancestor=league_key).count()
     members = MemberModel.query(ancestor=league_key)
     generalInfo = {}
     if checkAdmin(league_key.get(), users.get_current_user().email()):
         generalInfo['admin'] = True
     else:
         generalInfo['admin'] = False
     generalInfo['league_name'] = league.name
     generalInfo['number'] = num_members
     generalInfo['date'] = league.date_created.strftime('%Y-%m-%d')
     generalInfo['name'] = "null"
     result += [generalInfo]
     for member in members:
         temp = {}
         temp['league_name'] = league.name
         temp['number'] = num_members
         temp['name'] = member.name
         temp['email'] = member.email
         result += [temp]
     self.response.out.write(json.dumps(result))
 def get(self):
   user = users.get_current_user()
   upload_url = blobstore.create_upload_url('/upload')
   if not user:
     render_template(self, "/error_no_user.html", {'url':user.create_login_url('/manage')})
     return
   league_key_string = self.request.get("league_key_string")
   template_params = {
     'user': True,
     'user_email': user.email(),
     'url': users.create_logout_url('/'),
     'manage_active': True,
     'upload_url': upload_url
   }
   if league_key_string:
     #get the key
     league_key = ndb.Key(urlsafe=league_key_string)
     qry = MemberModel.query(MemberModel.email == user.email(), ancestor=league_key).count()
     if qry != 0:
       template_params['member'] = True
     #get the model
     league_model = league_key.get()
     #True so bottom of sidebar shows up and right half of navbar
     template_params['league_selected'] = True
     #name for the navbar and sidebar
     template_params['league_name'] = league_model.name
     #urlsafestring to pass the league from page to page
     template_params['league_key_string'] = league_key.urlsafe()
     #check for admin
     if checkAdmin(league_model, user.email()):
       template_params['admin'] = True
   #render template
   render_template(self, '/manage.html', template_params)
 def get(self):
   user = users.get_current_user()
   if not user:
     render_template(self, 'error_no_user.html', { 'url': users.create_login_url('/manage')})
     return
   league_key_string = self.request.get("league_key_string")
   template_params = {
     'user': True,
     'user_email': user.email(),
     'url': users.create_logout_url('/'),
     'results_active': True,
   }
   if not league_key_string:
     render_template(self, 'error_no_league.html', template_params)
     return
   league_key = ndb.Key(urlsafe=league_key_string)
   league_model = league_key.get()
   if checkAdmin(league_model, user.email()):
     template_params['admin'] = True
   template_params['league_selected'] = True
   template_params['league_name'] = league_model.name
   template_params['league_key_string'] = league_key.urlsafe()
   MUs = []
   for i in league_model.match_ups:
     playerA_name = i.playerA
     playerB_name = i.playerB
     number = i.round_num
     MUs.append((number, playerA_name, playerB_name))
   template_params['match_ups'] = MUs
   render_template(self, '/results.html', template_params) 
 def post(self):
   # Insert your own CHALLONGE Information.
   api.set_credentials(CHALLONGE_USERANME, CHALLONGE_API)
   league_key_string = self.request.get("league_key_string")
   tournament_type = self.request.get("type") 
   entrants = self.request.get('entrants', allow_multiple=True)
   if len(entrants) < 2:
     self.redirect('/tournament?league_key_string='+league_key_string)
     return
   league_key = ndb.Key(urlsafe=league_key_string)
   league_model = league_key.get()
   if not checkAdmin(league_model, users.get_current_user().email()):
     return
   bracket_name = league_model.name + " " + datetime.now().strftime("%Y-%m-%d %H:%M:%S")
   bracket_url = league_model.name + datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
   bracket_url = bracket_url.replace(" ","")
   if tournament_type == "swiss":
     rounds = math.floor((len(entrants) * 2) / 3)
     tournaments.create(bracket_name, bracket_url, tournament_type, swiss_rounds=rounds)
   else:
     tournaments.create(bracket_name, bracket_url, tournament_type)
   tournament = tournaments.show(bracket_url)
   for entrant in entrants:
     participants.create(tournament['id'], entrant)
   tournaments.publish(tournament['id'])
   tournaments.start(tournament['id'])
   league_model.tournaments.append(bracket_url)
   league_model.put()
   self.redirect('/tournament?league_key_string='+league_key_string+'&bracket_url='+bracket_url)
Beispiel #8
0
 def post(self):
   league_key_string = self.request.get('league_key_string')
   league_key = ndb.Key(urlsafe=league_key_string)
   result = []
   league = league_key.get()
   num_members = MemberModel.query(ancestor=league_key).count()
   members = MemberModel.query(ancestor=league_key)
   generalInfo = {}
   if checkAdmin(league_key.get(), users.get_current_user().email()):
     generalInfo['admin'] = True
   else:
     generalInfo['admin'] = False
   generalInfo['league_name'] = league.name
   generalInfo['number'] = num_members
   generalInfo['date'] = league.date_created.strftime('%Y-%m-%d')
   generalInfo['name'] = "null"
   result += [generalInfo]
   for member in members:
     temp = {}
     temp['league_name'] = league.name
     temp['number'] = num_members
     temp['name'] = member.name
     temp['email'] = member.email
     result += [temp]
   self.response.out.write(json.dumps(result))
 def get(self):
     user = users.get_current_user()
     if not user:
         template_params = {
             'user': False,
             'url': users.create_login_url('/manage'),
             'about_active': True
             #no user means no league selected is possible
         }
         render_template(self, 'about.html', template_params)
     else:
         league_key_string = self.request.get("league_key_string")
         template_params = {
             'user': True,
             'user_email': user.email(),
             'url': users.create_logout_url('/'),
             'about_active': True,
         }
         if (league_key_string):
             league_key = ndb.Key(urlsafe=league_key_string)
             league_model = league_key.get()
             if checkAdmin(league_model, users.get_current_user().email()):
                 template_params['admin'] = True
             template_params['league_selected'] = True
             template_params['league_name'] = league_model.name
             template_params['league_key_string'] = league_key.urlsafe()
         render_template(self, 'about.html', template_params)
 def post(self):
   league_key_string = self.request.get("league_key_string") 
   league_key = ndb.Key(urlsafe=league_key_string)
   league_model = league_key.get()
   MUs = league_model.match_ups  
   if not checkAdmin(league_model, users.get_current_user().email()):
     return
   playerA_name = self.request.get('player_one')
   playerB_name = self.request.get('player_two')
   '''failsafe for bad entries'''
   if self.request.get('player_two') =="":
     return
   if self.request.get('player_one') =="":
     return
   number=0
   for i in league_model.match_ups:
     number=number+1
   MU = MatchUpModel()
   MU.round_num = number
   MU.playerA = playerA_name
   MU.playerB = playerB_name
   MUs.append(MU)
   league_model.match_ups = MUs
   league_model.put()
   self.redirect("/match_create?league_key_string="+league_key_string)
 def post(self):
   league_key_string = self.request.get("league_key_string") 
   league_key = ndb.Key(urlsafe=league_key_string)
   league_model = league_key.get()
   if not checkAdmin(league_model, users.get_current_user().email()):
     return
   rounds_reported = self.request.get("rounds_entered").split("-")
   rounds_reported = rounds_reported[:len(rounds_reported)-1]
   MUs = league_model.match_ups  
   for i in rounds_reported:
     history_model = HistoryModel(parent=league_key)
     winner = self.request.get("round"+i+"winner")
     loser = self.request.get("round"+i+"loser")
     members = MemberModel.query(ancestor=league_key)
     for j in members:
       if j.name == winner:
         winner_model = j
         history_model.playerA = j.name
         history_model.playerA_rank = j.rank
         history_model.winner = j.name
       if j.name == loser:
         loser_model = j
         history_model.playerB = j.name
         history_model.playerB_rank = j.rank
     report_and_rank(winner_model, loser_model)
     winner_model.put()
     loser_model.put()
     history_model.put()
     for i in range(0, len(MUs)):
       if MUs[i].playerA == winner or MUs[i].playerB == winner:
         MUs.pop(i)
         break 
   league_model.match_ups = MUs
   league_model.put()
   self.redirect('/results?league_key_string='+league_key_string)
Beispiel #12
0
 def post(self):
   league_key_string = self.request.get('league_key_string')
   league_key = ndb.Key(urlsafe=league_key_string)
   if not checkAdmin(league_key.get(), users.get_current_user().email()):
     return
   picked = self.request.get('toDelete')
   if picked == "":
     return
   member_key = ndb.Key(urlsafe=picked)
   member_key.delete()
   self.redirect('/manage?mode=leagueInfo&league_key_string='+league_key_string)
Beispiel #13
0
 def post(self):
   league_key_string = self.request.get("league_key_string")
   league_key = ndb.Key(urlsafe=league_key_string)
   if not checkAdmin(league_key.get(), users.get_current_user().email()):
     return
   members = MemberModel.query(ancestor=league_key)
   for i in members:
     i.key.delete()
   history = HistoryModel.query(ancestor=league_key)
   for i in history:
     i.key.delete()
   league_key.delete()
   self.redirect('/manage')
Beispiel #14
0
 def post(self):
     league_key_string = self.request.get("league_key_string")
     league_key = ndb.Key(urlsafe=league_key_string)
     if not checkAdmin(league_key.get(), users.get_current_user().email()):
         return
     members = MemberModel.query(ancestor=league_key)
     for i in members:
         i.key.delete()
     history = HistoryModel.query(ancestor=league_key)
     for i in history:
         i.key.delete()
     league_key.delete()
     self.redirect('/manage')
Beispiel #15
0
 def get(self):
   league_key_string = self.request.get("league_key_string")
   league_key = ndb.Key(urlsafe=league_key_string)
   if not checkAdmin(league_key.get(), users.get_current_user().email()):
     return
   members = MemberModel.query(ancestor=league_key)
   result = []
   for member in members:
     temp = {}
     temp['name'] = member.name
     temp['key'] = member.key.urlsafe()
     result += [temp]
   self.response.out.write(json.dumps(result))
 def get(self):
     user = users.get_current_user()
     if not user:
         render_template(self, "error_no_user.html", {"url": users.create_login_url()})
         return
     # To use this you need a challonge account and to enter the Username and API
     api.set_credentials(CHALLONG_USERNAME, CHALLONGE_API)
     bracket_url = self.request.get("bracket_url")
     league_key_string = self.request.get("league_key_string")
     if not league_key_string:
         render_template(self, "error_no_league.html", template_params)
         return
     template_params = {
         "user": True,
         "user_email": user.email(),
         "url": users.create_logout_url("/"),
         "league_key_string": league_key_string,
     }
     league_model = ndb.Key(urlsafe=league_key_string).get()
     template_params["league_selected"] = True
     template_params["league_name"] = league_model.name
     template_params["bracket_url"] = bracket_url
     if checkAdmin(league_model, user.email()):
         template_params["admin"] = True
     else:
         render_template(self, "/tournament.html", template_params)
         return
     if not bracket_url:
         # create bracekt
         members = MemberModel.query(ancestor=league_model.key).order(-MemberModel.rank)
         template_params["entrants"] = members
         render_template(self, "/tournament_create.html", template_params)
         return
     tournament = tournaments.show(bracket_url)
     matches_to_report = matches.index(tournament["id"], state="open")
     players = []
     for match in matches_to_report:
         p1 = participants.show(tournament["id"], match["player1-id"])["name"]
         p2 = participants.show(tournament["id"], match["player2-id"])["name"]
         players.append(
             (
                 str(match["id"]).strip(),
                 str(match["player1-id"]).strip(),
                 str(p1).strip(),
                 str(match["player2-id"]).strip(),
                 str(p2).strip(),
                 str(match["identifier"]),
             )
         )
     template_params["matches"] = players
     render_template(self, "/tournament.html", template_params)
 def post(self):
     league_key_string = self.request.get("league_key_string")
     league_key = ndb.Key(urlsafe=league_key_string)
     league_model = league_key.get()
     results = []
     first = {"name": league_model.name, "key": league_key_string}
     if checkAdmin(league_key.get(), users.get_current_user().email()):
         first["admin"] = True
     results += [first]
     tournaments = league_model.tournaments
     for tournament in reversed(tournaments):
         temp = {"name": league_model.name, "url": tournament, "key": league_key_string}
         results += [temp]
     self.response.out.write(json.dumps(results))
Beispiel #18
0
 def post(self):
   league_key_string = self.request.get('league_key_string')
   league_key = ndb.Key(urlsafe=league_key_string)
   if not checkAdmin(league_key.get(), users.get_current_user().email()):
     return
   member_name = self.request.get('memberName')
   member_email = self.request.get('memberEmail')
   if member_name == "" or member_email == "":
     return
   members = MemberModel.query(ndb.OR(MemberModel.name == member_name, MemberModel.email == member_email), ancestor=league_key).count()
   if members > 0:
     return
   member = MemberModel(parent=league_key)
   member.name = member_name
   member.email = member_email
   member.put()
 def get(self):
   user = users.get_current_user()
   if not user:
     render_template(self, 'error_no_user.html', { 'url': users.create_login_url()})
     return
   # To use this you need a challonge account and to enter the Username and API
   api.set_credentials(CHALLONG_USERNAME, CHALLONGE_API)
   bracket_url = self.request.get('bracket_url')
   league_key_string = self.request.get('league_key_string')
   if not league_key_string:
     render_template(self, 'error_no_league.html', template_params)
     return
   template_params = {
     'user': True,
     'user_email': user.email(),
     'url': users.create_logout_url('/'),
     'league_key_string': league_key_string,
   }
   league_model = ndb.Key(urlsafe=league_key_string).get()
   template_params['league_selected'] = True
   template_params['league_name'] = league_model.name
   template_params['bracket_url'] = bracket_url
   if checkAdmin(league_model, user.email()):
     template_params['admin'] = True
   else:
     render_template(self, '/tournament.html', template_params)
     return
   if not bracket_url:
     #create bracekt 
     members = MemberModel.query(ancestor=league_model.key).order(-MemberModel.rank)
     template_params['entrants'] = members
     render_template(self,'/tournament_create.html', template_params)
     return
   tournament = tournaments.show(bracket_url)
   matches_to_report = matches.index(tournament['id'], state="open")
   players = []
   for match in matches_to_report:
     p1 = participants.show(tournament['id'], match['player1-id'])['name']
     p2 = participants.show(tournament['id'], match['player2-id'])['name']
     players.append((str(match['id']).strip(), str(match['player1-id']).strip(), str(p1).strip(), str(match['player2-id']).strip(), str(p2).strip(), str(match['identifier'])))
   template_params['matches'] = players
   render_template(self, '/tournament.html', template_params)  
 def post(self):
   league_key_string = self.request.get("league_key_string")
   league_key = ndb.Key(urlsafe=league_key_string)
   league_model = league_key.get()
   results = []
   first = {
     'name': league_model.name,
     'key': league_key_string,
   }
   if checkAdmin(league_key.get(), users.get_current_user().email()):
     first['admin'] = True
   results += [first]
   tournaments = league_model.tournaments
   for tournament in reversed(tournaments):
     temp = {
       'name': league_model.name,
       'url': tournament,
       'key': league_key_string,
     }
     results += [temp]
   self.response.out.write(json.dumps(results))
 def get(self):
   user = users.get_current_user()
   if not user:
     render_template(self, 'error_no_user.html', { 'url': users.create_login_url('/manage')})
     return
   league_key_string = self.request.get("league_key_string")
   template_params = {
     'user': True,
     'user_email': user.email(),
     'url': users.create_logout_url('/'),
     'match_active': True,
   }
   if not league_key_string:
     render_template(self, 'error_no_league.html', template_params)
     return
   league_key = ndb.Key(urlsafe=league_key_string)
   league_model = league_key.get()
   if checkAdmin(league_model, user.email()):
     template_params['admin'] = True
   #if league_model.match_ups is None:
   members=MemberModel.query(ancestor=league_key)
   member_list = []
   matched_up= [] 
   for i in league_model.match_ups:
     playerA_name = i.playerA
     playerB_name = i.playerB
     matched_up.append(playerA_name)
     matched_up.append(playerB_name)
   for i in members:
     if not i.name in matched_up:
       player_name = i.name
       member_list.append(player_name)  
   template_params['member_list'] = member_list
   template_params['league_selected'] = True
   template_params['league_name'] = league_model.name
   template_params['league_key_string'] = league_key.urlsafe()
   render_template(self, '/match_create.html', template_params)