def add_coach(): # Add new coach body = request.get_json() name = body.get('name', None) specialty = body.get('specialty', None) try: new_coach = Coach(name=name, specialty=specialty) new_coach.insert() return jsonify({'success': True, 'coach': new_coach.format()}) except: abort(422)
def add_coachs(current_user): coach_new = Coach( nombre_equipo = request.get_json()['nombreEquipo'], nombre = request.get_json()['nombre'], apellido = request.get_json()['apellido'], fecha_nacimiento = request.get_json()['nacimiento'], rol = request.get_json()['rol'], nacionalidad = request.get_json()['nacionalidad']) try: coach_new.save() return jsonify({'result': 'OK'}) except(ValueError, KeyError, TypeError): return jsonify({'result': 'error'})
def recompute(self): self.reset() coach = Coach.get_by_key_name(self.key().name()) predictions = OFL_Prediction.all().ancestor(coach).filter( "points >", 0) for prediction in predictions: self.update(prediction.season, prediction.week, prediction.points)
def post(self): tournament_name = self.request.get("tournament_name") if Tournament.get_by_key_name(tournament_name): # TODO error: already exists return max_enrollment = int(self.request.get("max_enrollment")) assert not (max_enrollment < 4 or max_enrollment > 64) background = self.request.get("background") seed_by = self.request.get("seed_by") coach = Coach.get_by_key_name(self.request.get("coach_key_name")) min_tv = self.request.get("min_tv") max_tv = self.request.get("max_tv") min_ma = self.request.get("min_ma") max_ma = self.request.get("max_ma") # compute race restrictions race_restriction = self.request.get("race_restriction") if race_restriction: races_allowed = self.request.get_all("races_allowed") races_allowed = [ db.Key.from_path("Race", race_name) for race_name in races_allowed] else: races_allowed = [] tournament = Tournament( key_name = tournament_name, owner = coach, background = background, max_enrollment = max_enrollment, seed_by = seed_by, races_allowed = races_allowed) def format_tv(tv): tv = (tv / 10) * 10 return max(0, min(3500, tv)) if min_tv: tournament.min_tv = int(min_tv) if max_tv: tournament.max_tv = int(max_tv) if min_ma: tournament.min_ma = int(min_ma) if max_ma: tournament.max_ma = int(max_ma) trophy_pic = self.request.get("trophy_pic") if trophy_pic: pic = TournamentPicture.create_from_img(tournament_name, trophy_pic) pic.put() tournament.pic = pic tournament.put() views.Tournaments.clear() # I need to give a response or I get an error. Nobody on the internet seems # to know why. See https://github.com/malsup/form/issues#issue/22. self.response.out.write("OK")
def test_get_coaches2(self): with app.app_context(): result = Coach.lookup('1870b014-38db-4339-a601-0740c4bdece6') self.assertEqual(result['position'], 'Defensive Coordinator') self.assertEqual(result['last_name'], 'Pagano') self.assertEqual(result['first_name'], 'John') self.assertEqual(result['pic_link'], 'http://cdn.fansided.com/wp-content/blogs.dir/229/files/2014/01/7760788.jpg') self.assertEqual(result['team'], 'LAC')
def test_get_coaches1(self): with app.app_context(): result = Coach.lookup('1969df08-6df4-446e-8090-7f6729c22151') self.assertEqual(result['position'], 'Offensive Coordinator') self.assertEqual(result['last_name'], 'Goodwin') self.assertEqual(result['first_name'], 'Harold') self.assertEqual(result['pic_link'], 'http://www.gannett-cdn.com/-mm-/a093b53724d06bd26d8faf2b8eb467567a8cc03d/c=71-0-3330-2450&r=x513&c=680x510/local/-/media/2015/08/24/Phoenix/Phoenix/635760457921758000-cards-23.jpg') self.assertEqual(result['team'], 'ARI')
def logo_getter(standing): coach = Coach.get_by_key_name(standing.get_coach_name()) img = "<img src='%s' />" % coach.get_logo_url( ) # FIXME: thumb is broken return "<div style='background-color: %(color)s'>%(img)s</div>" % { 'color': coach.color, 'img': img }
def post(self): user = users.get_current_user() coach = Coach.all().filter("user ="******"tournament_key")) memberships = [m for m in TournamentMembership.all().ancestor(tournament) if m.team.coach.key() == coach.key()] membership = memberships[0] membership.delete() views.Tournaments.clear()
def post(self): user = users.get_current_user() coach = Coach.all().filter("user ="******"tournament_key")) memberships = [ m for m in TournamentMembership.all().ancestor(tournament) if m.team.coach.key() == coach.key() ] membership = memberships[0] membership.delete() views.Tournaments.clear()
def post(self): args = coach_parser.parse_args() if 'id' not in args: highest = Coach.query.order_by(Coach.id).last() coach_id = highest + 1 else: coach_id = args['id'] coach = Coach(id=coach_id, email=args['email'], password=args['password'], first_name=args['first_name'], last_name=args['last_name']) db.session.add(coach) db.session.commit() return coach, 201
def get(self): user = users.get_current_user() if user: log_out_url = users.create_logout_url("/") coach = Coach.all().filter("user ="******"<img src='http://www.oldworldfootball.com/%s'/>" % ( match.teamAlogo) return html def logoB_getter(match): html = "<img src='http://www.oldworldfootball.com/%s'/>" % ( match.teamBlogo) return html def nameA_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "%s (%s - %s)" % (match.teamA, match.teamAcoach, match.teamArace) return html def nameB_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "%s (%s - %s)" % (match.teamB, match.teamBcoach, match.teamBrace) return html def key_name_getter(prediction): return prediction.key().name() def choice_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) #html = "<img src='./get_wager_pic?keyname=%s&team=A'/>" % (prediction.key().name()) html = "<img src='http://www.oldworldfootball.com/%s'/>" % ( match.teamAlogo) if not match.gamePlayed: html += "<input type='radio' name='%schoice' value='-1' %s>" % ( match.key().name(), prediction.isChecked(-1)) html += "<input type='radio' name='%schoice' value='0' %s>" % ( match.key().name(), prediction.isChecked(0)) html += "<input type='radio' name='%schoice' value='1' %s>" % ( match.key().name(), prediction.isChecked(1)) else: html += "<input type='radio' name='%schoice' value='-1' disabled %s>" % ( match.key().name(), prediction.isChecked(-1)) html += "<input type='radio' name='%schoice' value='0' disabled %s>" % ( match.key().name(), prediction.isChecked(0)) html += "<input type='radio' name='%schoice' value='1' disabled %s>" % ( match.key().name(), prediction.isChecked(1)) html += "<img src='http://www.oldworldfootball.com/%s'/>" % ( match.teamBlogo) #html += "<img src='./get_wager_pic?keyname=%s&team=B'/>" % (prediction.key().name()) return html # Bypassing table.html Django template to create this table # Table requires Jquery code for sortable entires and wagers # Hidden input tags are also used with form. prediction_list = OFL_Prediction.all().filter( "season =", season).filter("week =", week).ancestor(coach).filter( "gameScored =", False).order("-wager") columns = ["Wager", "Away Team", "Prediction", "Home Team"] table_html = [] table_html.append(''' <table class="ofl_pickem schedule_table"> <thead> <tr>''') for column in columns: table_html.append( '<th style="text-align: center;"> %s </th>' % column) table_html.append(''' </tr> </thead> <tbody id="sortable">''') k = 0 for prediction in prediction_list: table_html.append('<tr class="row_%s">' % k) table_html.append( '<input type="hidden" name="row_%s" value="%s">' % (k, prediction.key().name())) table_html.append( "<input type='hidden' class='row_%s' name='%svalue' value='%s'>" % (k, prediction.key().name(), prediction.wager)) table_html.append( '<td class="row_%s" style="text -align: center;">%s</td>' % (k, prediction.wager)) table_html.append( '<td style="text-align: center;">%s</td>' % nameA_getter(prediction)) table_html.append( '<td style="text-align: center;">%s</td>' % choice_getter(prediction)) table_html.append( '<td style="text-align: center;">%s</td>' % nameB_getter(prediction)) k += 1 table_html.append('</tbody>\n</table>') table_html = "\n".join(table_html) played_table = Table( columns=[ # profile Column("Points", "Points Earned", attrgetter("points")), Column("Wager", "Wager Placed", attrgetter("wager")), Column("Away Team", "Away Team", nameA_getter, center=True), Column("Prediction", "Your Prediction", choice_getter, center=True), Column("Home Team", "Home Team", nameB_getter, center=True), ], query=OFL_Prediction.all().filter( "season =", season).filter("week =", week).ancestor(coach).filter( "gameScored =", True).order("-points"), id="played_table", cls="tablesorter", ) def logo_getter(standing): coach = Coach.get_by_key_name(standing.get_coach_name()) img = "<img src='%s' />" % coach.get_logo_url( ) # FIXME: thumb is broken return "<div style='background-color: %(color)s'>%(img)s</div>" % { 'color': coach.color, 'img': img } def name_getter(standing): coach = Coach.get_by_key_name(standing.get_coach_name()) return "<a class='leader_link' rel='leader_coach' href='%s'>%s</a>" % ( coach.get_box_href(), coach.key().name()) leader_table = {} query = OFLPickemStats.all().order('-all_time').fetch(10) label = "alltime" leader_table[label] = Table( columns=[ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Score", "Score", attrgetter("all_time")), ], query=query, cls="leader_table", ) query = OFLPickemSeasonRecord.all().filter( "season =", season).order("-points").fetch(10) label = "season" leader_table[label] = Table( columns=[ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Score", "Score", attrgetter("points")), ], query=query, cls="leader_table", ) query = OFLPickemWeekRecord.all().filter("week =", week).filter( "season =", season).order("-points").fetch(10) label = "week" leader_table[label] = Table( columns=[ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Score", "Score", attrgetter("points")), ], query=query, cls="leader_table", ) query = OFLPickemStats.all().order('-matches').fetch(10) label = "alltime_matches" leader_table[label] = Table( columns=[ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Matches", "Matches Predicted", attrgetter("matches")), ], query=query, cls="leader_table", ) query = OFLPickemSeasonRecord.all().filter( "season =", season).order("-matches").fetch(10) label = "season_matches" leader_table[label] = Table( columns=[ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Matches", "Matches Predicted", attrgetter("matches")), ], query=query, cls="leader_table", ) query = OFLPickemWeekRecord.all().filter("week =", week).filter( "season =", season).order("-matches").fetch(10) label = "week_matches" leader_table[label] = Table( columns=[ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Matches", "Matches Predicted", attrgetter("matches")), ], query=query, cls="leader_table", ) else: log_in_url = users.create_login_url("/") # render and update #--------------------------------------------------------------------# ofl_pickem_page = misc.render('ofl_pickem_page.html', locals()) self.update(ofl_pickem_page) self.response.out.write(ofl_pickem_page)
def name_getter(standing): coach = Coach.get_by_key_name(standing.get_coach_name()) return "<a class='leader_link' rel='leader_coach' href='%s'>%s</a>" % ( coach.get_box_href(), coach.key().name())
def coachIndex(): pageNum = int(request.args.get('page', 1)) order = OrderBy.OrderByCoach(request.args.get('order', None)).value() filters = FilterBy.CoachFilter(request.args.get('filter', None)).value() coaches = Coach.list(order, filters, pageNum) return json.dumps(coaches)
def is_staff(self): return Coach.is_staff()
def get(self): # check for a cached version #--------------------------------------------------------------------# coach_key = db.Key.from_path("Coach", self.request.get("coach_key_name")) if self.emit(self.response.out, coach_key): return # not cached or evicted from cache; regenerate #--------------------------------------------------------------------# coach = Coach.get(coach_key) if not coach: return coach_stats = CoachStats.all().ancestor(coach).get() # win/draw/loss bars and banner text color #--------------------------------------------------------------------# longest_bar_length = max(coach_stats.wins, coach_stats.draws, coach_stats.losses) banner_text_color = misc.get_contrasting_monochrome(coach.color) # team_table #--------------------------------------------------------------------# def name_getter(team): return "<a rel='team' href='%s'>%s</a>" % ( team.get_box_href(), team.key().name()) def race_getter(team): return "<img title='%s' src='%s' />" % ( team.race.key().name(), team.race.get_image_src(thumb=True)) def awp_getter(team): return "%0.3f" % team.awp def glicko_getter(team): return "%4.0f" % team.glicko_r teams = query = Team.all().filter("coach =", coach).filter("matches >", 0).order("-matches") team_table = Table( columns = [ # profile Column(" ", "Race", race_getter, center=True), Column("Team Name", "Team name", name_getter), Column("TV", "Team value (approximate)", attrgetter("tv"), divider=True), # record Column("Pl", "Matches played", attrgetter("matches")), Column("W", "Matches won", attrgetter("wins")), Column("D", "Matches drawn", attrgetter("draws")), Column("L", "Matches lost", attrgetter("losses"), divider=True), # rankings Column("AWP", "Adjusted win percentage", awp_getter), Column("TPts", "Tournament Points", attrgetter("tpts")), Column("Rating", "Glicko Rating", glicko_getter, divider=True), ## touchdowns #Column("TD+", "Touchdowns for", attrgetter("tds_for")), #Column("TD-", "Touchdowns against", attrgetter("tds_against")), #Column("<span class='over'>TD+</span>", "Average touchdowns for", # get_ave_getter("tds_for")), #Column("<span class='over'>TD-</span>", "Average touchdowns against", # get_ave_getter("tds_against")), ## casualties #Column("C+", "Casualties for", attrgetter("cas_for")), #Column("C-", "Casualties against", attrgetter("cas_against")), #Column("<span class='over'>C+</span>", "Average casualties for", # get_ave_getter("cas_for")), #Column("<span class='over'>C-</span>", "Average casualties against", # get_ave_getter("cas_against")), ], query = teams, id = "%s-team-table" % coach.key(), cls = "tablesorter", ) # coach_stat_table #--------------------------------------------------------------------# def get_left_header(tuple): coach_stats, which = tuple return which.capitalize() def getter(stat): def getter_closure(tuple): coach_stats, which = tuple attr = getattr(coach_stats, "%s_%s" % (stat, which)) return ( ("<span class='tot_stat'>%d</span>" % attr) + ("<span class='ave_stat'>%.1f</span>" % (attr / float(coach_stats.matches)))) return getter_closure stat_table = Table( columns = [ Column("<span class='link' id='%s-show-averages-toggle'></span>" % coach.key(), "", get_left_header), Column("TD", "Touchdowns", getter("tds")), Column("P", "Pass completions", getter("passes")), Column("YP", "Yards passing", getter("pyards")), Column("R", "Pass receptions", getter("rec")), Column("YR", "Yards rushing", getter("ryards")), Column("K", "Kills", getter("kills")), Column("C", "Casualties", getter("cas")), Column("KO", "Knock outs", getter("ko")), Column("S", "Stuns", getter("stun")), Column("T", "Tackles", getter("tckl")), Column("I", "Interceptions", getter("int")), ], query = ((coach_stats, "for"), (coach_stats, "against")), cls = "fancytable stats", ) # match_tables #--------------------------------------------------------------------# def name_getter(record): if record.team.key() == team.key(): return team.key().name() else: return "<a rel='team_opponents' href='%s'>%s</a>" % ( record.team.get_box_href(), record.team.key().name()) def race_getter(record): return "<img src='%s' />" % record.team.race.get_image_src(thumb=True) def link_getter(record): return """ <a rel='team_matches' href='%s'> <span class="go_to_arrow" title='Go to match page'>→</span></a>""" % ( record.get_match().get_box_href()) def glicko_getter(record): return "%4.0f" % record.glicko_r match_columns = [ Column(" ", "Race", race_getter, center=True), Column("Team", "Team name", name_getter), Column("Rating", "Team rating", glicko_getter), Column("TV", "Team value", attrgetter("tv_for")), Column("TD", "Touchdowns", attrgetter("tds_for")), Column("P", "Pass completions", attrgetter("passes_for")), Column("YP", "Yards passing", attrgetter("pyards_for")), Column("R", "Pass receptions", attrgetter("rec_for")), Column("YR", "Yards rushing", attrgetter("ryards_for")), Column("K", "Kills", attrgetter("kills_for")), Column("C", "Casualties", attrgetter("cas_for")), Column("KO", "Knock outs", attrgetter("ko_for")), Column("S", "Stuns", attrgetter("stun_for")), Column("T", "Tackles", attrgetter("tckl_for")), Column("I", "Interceptions", attrgetter("int_for")), Column("", "", link_getter, center=True, rowspan=2) ] # get matches from match_records and sort in order of most recent result = [] for team in teams: for record in TeamRecord.all().filter("team =", team): if record is not None: result.append(record) matches = sorted([record.get_match() for record in result],key=lambda m: m.created, reverse=True)[:30] match_tables = [] for match in matches: # sort with this team's match record first match_records = sorted( match.get_team_records_query(), key=lambda mr: mr.team.coach == coach, reverse=True) result_map = { 1 : "WIN!", 0 : "DRAW", -1 : "LOSS"} coach_flag = 0 if match_records[1].team.coach: if coach.key() == match_records[1].team.coach.key(): coach_flag = 1 title = "(%s) <b>%s-%s %s</b> %s vs. %s" % ( match.created.date(), match_records[0].tds_for, match_records[1].tds_for, result_map[match_records[coach_flag].result], match_records[0].team.key().name(), match_records[1].team.key().name()) if match.disconnect: title += " (Disconnect/Forfeit)" match_table = Table( columns = match_columns, query = match_records, cls = "tablesorter match_stats", title = title) match_tables.append((match.get_box_href(), match_table)) # active_member = team.get_active_tournament_membership() # active_tournament = active_member.parent() if active_member else None # render and update (TODO: move to bottom after implementing bottom code) #--------------------------------------------------------------------# coach_box = misc.render('coach_box.html', locals()) self.update(coach_box, coach_key) self.response.out.write(coach_box)
def get(self): user = users.get_current_user() if user: log_out_url = users.create_logout_url("/") coach = Coach.all().filter("user ="******"<img src='http://www.oldworldfootball.com/%s'/>" % (match.teamAlogo) return html def logoB_getter(match): html = "<img src='http://www.oldworldfootball.com/%s'/>" % (match.teamBlogo) return html def nameA_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "%s (%s - %s)" % (match.teamA, match.teamAcoach, match.teamArace) return html def nameB_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "%s (%s - %s)" % (match.teamB, match.teamBcoach, match.teamBrace) return html def key_name_getter(prediction): return prediction.key().name() def choice_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) #html = "<img src='./get_wager_pic?keyname=%s&team=A'/>" % (prediction.key().name()) html = "<img src='http://www.oldworldfootball.com/%s'/>" % (match.teamAlogo) if not match.gamePlayed: html += "<input type='radio' name='%schoice' value='-1' %s>" % (match.key().name(), prediction.isChecked(-1)) html += "<input type='radio' name='%schoice' value='0' %s>" % (match.key().name(), prediction.isChecked(0)) html += "<input type='radio' name='%schoice' value='1' %s>" % (match.key().name(), prediction.isChecked(1)) else: html += "<input type='radio' name='%schoice' value='-1' disabled %s>" % (match.key().name(), prediction.isChecked(-1)) html += "<input type='radio' name='%schoice' value='0' disabled %s>" % (match.key().name(), prediction.isChecked(0)) html += "<input type='radio' name='%schoice' value='1' disabled %s>" % (match.key().name(), prediction.isChecked(1)) html += "<img src='http://www.oldworldfootball.com/%s'/>" % (match.teamBlogo) #html += "<img src='./get_wager_pic?keyname=%s&team=B'/>" % (prediction.key().name()) return html # Bypassing table.html Django template to create this table # Table requires Jquery code for sortable entires and wagers # Hidden input tags are also used with form. prediction_list = OFL_Prediction.all().filter("season =", season).filter("week =", week).ancestor(coach).filter("gameScored =", False).order("-wager") columns = ["Wager", "Away Team", "Prediction", "Home Team"] table_html = [] table_html.append(''' <table class="ofl_pickem schedule_table"> <thead> <tr>''') for column in columns: table_html.append('<th style="text-align: center;"> %s </th>' % column) table_html.append(''' </tr> </thead> <tbody id="sortable">''') k = 0 for prediction in prediction_list: table_html.append('<tr class="row_%s">' % k) table_html.append('<input type="hidden" name="row_%s" value="%s">' % (k, prediction.key().name())) table_html.append("<input type='hidden' class='row_%s' name='%svalue' value='%s'>" % (k, prediction.key().name(), prediction.wager)) table_html.append('<td class="row_%s" style="text -align: center;">%s</td>' % (k, prediction.wager)) table_html.append('<td style="text-align: center;">%s</td>' % nameA_getter(prediction)) table_html.append('<td style="text-align: center;">%s</td>' % choice_getter(prediction)) table_html.append('<td style="text-align: center;">%s</td>' % nameB_getter(prediction)) k += 1 table_html.append('</tbody>\n</table>') table_html = "\n".join(table_html) played_table = Table( columns = [ # profile Column("Points", "Points Earned", attrgetter("points")), Column("Wager", "Wager Placed", attrgetter("wager")), Column("Away Team", "Away Team", nameA_getter, center=True), Column("Prediction", "Your Prediction", choice_getter, center=True), Column("Home Team", "Home Team", nameB_getter, center=True), ], query = OFL_Prediction.all().filter("season =", season).filter("week =", week).ancestor(coach).filter("gameScored =", True).order("-points"), id = "played_table", cls = "tablesorter", ) def logo_getter(standing): coach = Coach.get_by_key_name(standing.get_coach_name()) img = "<img src='%s' />" % coach.get_logo_url() # FIXME: thumb is broken return "<div style='background-color: %(color)s'>%(img)s</div>" % { 'color': coach.color, 'img': img} def name_getter(standing): coach = Coach.get_by_key_name(standing.get_coach_name()) return "<a class='leader_link' rel='leader_coach' href='%s'>%s</a>" % ( coach.get_box_href(),coach.key().name()) leader_table = {} query = OFLPickemStats.all().order('-all_time').fetch(10) label = "alltime" leader_table[label] = Table( columns = [ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Score", "Score", attrgetter("all_time")), ], query = query, cls = "leader_table", ) query = OFLPickemSeasonRecord.all().filter("season =", season).order("-points").fetch(10) label = "season" leader_table[label] = Table( columns = [ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Score", "Score", attrgetter("points")), ], query = query, cls = "leader_table", ) query = OFLPickemWeekRecord.all().filter("week =", week).filter("season =", season).order("-points").fetch(10) label = "week" leader_table[label] = Table( columns = [ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Score", "Score", attrgetter("points")), ], query = query, cls = "leader_table", ) query = OFLPickemStats.all().order('-matches').fetch(10) label = "alltime_matches" leader_table[label] = Table( columns = [ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Matches", "Matches Predicted", attrgetter("matches")), ], query = query, cls = "leader_table", ) query = OFLPickemSeasonRecord.all().filter("season =", season).order("-matches").fetch(10) label = "season_matches" leader_table[label] = Table( columns = [ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Matches", "Matches Predicted", attrgetter("matches")), ], query = query, cls = "leader_table", ) query = OFLPickemWeekRecord.all().filter("week =", week).filter("season =", season).order("-matches").fetch(10) label = "week_matches" leader_table[label] = Table( columns = [ Column(" ", "Logo", logo_getter, center=True), Column("Coach Name", "Coach name", name_getter), Column("Matches", "Matches Predicted", attrgetter("matches")), ], query = query, cls = "leader_table", ) else: log_in_url = users.create_login_url("/") # render and update #--------------------------------------------------------------------# ofl_pickem_page = misc.render('ofl_pickem_page.html', locals()) self.update(ofl_pickem_page) self.response.out.write(ofl_pickem_page)
def logo_getter(standing): coach = Coach.get_by_key_name(standing.get_coach_name()) img = "<img src='%s' />" % coach.get_logo_url() # FIXME: thumb is broken return "<div style='background-color: %(color)s'>%(img)s</div>" % { 'color': coach.color, 'img': img}
def get(self): # check for a cached version #--------------------------------------------------------------------# coach_key = db.Key.from_path("Coach", self.request.get("coach_key_name")) if self.emit(self.response.out, coach_key): return # not cached or evicted from cache; regenerate #--------------------------------------------------------------------# coach = Coach.get(coach_key) if not coach: return coach_stats = CoachStats.all().ancestor(coach).get() # win/draw/loss bars and banner text color #--------------------------------------------------------------------# longest_bar_length = max(coach_stats.wins, coach_stats.draws, coach_stats.losses) banner_text_color = misc.get_contrasting_monochrome(coach.color) # team_table #--------------------------------------------------------------------# def name_getter(team): return "<a rel='team' href='%s'>%s</a>" % ( team.get_box_href(), team.key().name()) def race_getter(team): return "<img title='%s' src='%s' />" % ( team.race.key().name(), team.race.get_image_src(thumb=True)) def awp_getter(team): return "%0.3f" % team.awp def glicko_getter(team): return "%4.0f" % team.glicko_r teams = query = Team.all().filter("coach =", coach).filter("matches >", 0).order("-matches") team_table = Table( columns = [ # profile Column(" ", "Race", race_getter, center=True), Column("Team Name", "Team name", name_getter), Column("TV", "Team value (approximate)", attrgetter("tv"), divider=True), # record Column("Pl", "Matches played", attrgetter("matches")), Column("W", "Matches won", attrgetter("wins")), Column("D", "Matches drawn", attrgetter("draws")), Column("L", "Matches lost", attrgetter("losses"), divider=True), # rankings Column("AWP", "Adjusted win percentage", awp_getter), Column("TPts", "Tournament Points", attrgetter("tpts")), Column("Rating", "Glicko Rating", glicko_getter, divider=True), ## touchdowns #Column("TD+", "Touchdowns for", attrgetter("tds_for")), #Column("TD-", "Touchdowns against", attrgetter("tds_against")), #Column("<span class='over'>TD+</span>", "Average touchdowns for", # get_ave_getter("tds_for")), #Column("<span class='over'>TD-</span>", "Average touchdowns against", # get_ave_getter("tds_against")), ## casualties #Column("C+", "Casualties for", attrgetter("cas_for")), #Column("C-", "Casualties against", attrgetter("cas_against")), #Column("<span class='over'>C+</span>", "Average casualties for", # get_ave_getter("cas_for")), #Column("<span class='over'>C-</span>", "Average casualties against", # get_ave_getter("cas_against")), ], query = teams, id = "%s-team-table" % coach.key(), cls = "tablesorter", ) # coach_stat_table #--------------------------------------------------------------------# def get_left_header(tuple): coach_stats, which = tuple return which.capitalize() def getter(stat): def getter_closure(tuple): coach_stats, which = tuple attr = getattr(coach_stats, "%s_%s" % (stat, which)) return ( ("<span class='tot_stat'>%d</span>" % attr) + ("<span class='ave_stat'>%.1f</span>" % (attr / float(coach_stats.matches)))) return getter_closure stat_table = Table( columns = [ Column("<span class='link' id='%s-show-averages-toggle'></span>" % coach.key(), "", get_left_header), Column("TD", "Touchdowns", getter("tds")), Column("P", "Pass completions", getter("passes")), Column("YP", "Yards passing", getter("pyards")), Column("R", "Pass receptions", getter("rec")), Column("YR", "Yards rushing", getter("ryards")), Column("K", "Kills", getter("kills")), Column("C", "Casualties", getter("cas")), Column("KO", "Knock outs", getter("ko")), Column("S", "Stuns", getter("stun")), Column("T", "Tackles", getter("tckl")), Column("I", "Interceptions", getter("int")), ], query = ((coach_stats, "for"), (coach_stats, "against")), cls = "fancytable stats", ) # render and update (TODO: move to bottom after implementing bottom code) #--------------------------------------------------------------------# coach_box = misc.render('coach_box.html', locals()) self.update(coach_box, coach_key) self.response.out.write(coach_box)
def get(self): # check for a cached version #--------------------------------------------------------------------# tournament = Tournament.get_by_key_name( self.request.get("tournament_key_name")) if tournament.started: if self.emit(self.response.out, tournament.key()): return # not cached or evicted from cache; regenerate #--------------------------------------------------------------------# teams = [ m.team for m in TournamentMembership.all().ancestor(tournament) ] races_allowed = [] for race_key in tournament.races_allowed: races_allowed.append(Race.get(race_key)) if not tournament.started: user = users.get_current_user() coach = None if user: coach = Coach.all().filter("user ="******":")] # pixel settings width_unit = 530 / round match_width = 200 # compute data for each match_up match_up_data = [] for match_up, child in match_ups: round, seed = [ int(x) for x in match_up.key().name().split(":") ] position_left = round * width_unit team_data = [] for i, mm in enumerate( match_up.tournamentmatchupmembership_set.order( "__key__")): data = {} data["name"] = "_" * 25 data["seed"] = "" data["score"] = "" if mm.membership: team = mm.membership.team if team.matches: data[ "name"] = "<a rel='tournament_teams' href='%s'>%s</a>" % ( team.get_box_href(), team.key().name()) else: data["name"] = "<b title='%s'>%s</b>" % ( team.coach.key().name(), team.key().name()) data["seed"] = mm.membership.seed + 1 if match_up.match: team_record = match_up.match.get_team_records_query( ).filter("team =", mm.membership.team.key()).get() score = str(team_record.tds_for) if (match_up.winner.key() == mm.membership.key() and (team_record.tds_for == team_record.tds_against or match_up.match.disconnect)): score += "*" data["score"] = "<b>%s</b>" % score elif match_up.winner: # if there was a winner but no match then it was a forfeit if match_up.winner.key() == mm.membership.key(): data["score"] = " " else: data["score"] = "<b><i>F</i></b>" team_data.append(data) if child == 0: arrow_class = "down_arrow" elif child == 1: arrow_class = "up_arrow" else: arrow_class = None match_data = match_up.match end_this_match = width_unit * round + match_width mid_next_match = width_unit * (round + 1) + match_width / 2 arrow_width = mid_next_match - end_this_match match_up_data.append((round, team_data, position_left, arrow_width, arrow_class, match_data)) # render and update #--------------------------------------------------------------------# tournament_box = misc.render('tournament_box.html', locals()) if tournament.started: self.update(tournament_box, tournament.key()) self.response.out.write(tournament_box)
def get(self): user = users.get_current_user() if user: log_out_url = users.create_logout_url("/") coach = Coach.all().filter("user ="******"schedule").split("-") if not season or not week: season, week = misc.get_ofl_season_and_week() season += 3 else: season = int(season) week = int(week) parser = OFLScheduleParser() ofl_info = urlfetch.fetch( "http://www.shalkith.com/bloodbowl/processSchedule.php?s=%s&w=%s" % (season, week)) parser.feed(ofl_info.content) update_schedule_entries(coach, season, week, parser.data) sort_wagers(coach, season, week) def logoA_getter(match): html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % ( match.teamAlogo) return html def logoB_getter(match): html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % ( match.teamBlogo) return html def nameA_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "%s (%s)" % (match.teamA, match.teamAcoach) return html def nameB_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "%s (%s)" % (match.teamB, match.teamBcoach) return html def key_name_getter(prediction): return prediction.key().name() def choice_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % ( match.teamAlogo) if not match.gamePlayed: html += "<input type='radio' name='%schoice' value='-1' %s>" % ( match.key().name(), prediction.isChecked(-1)) html += "<input type='radio' name='%schoice' value='0' %s>" % ( match.key().name(), prediction.isChecked(0)) html += "<input type='radio' name='%schoice' value='1' %s>" % ( match.key().name(), prediction.isChecked(1)) else: html += "<input type='radio' name='%schoice' value='-1' disabled %s>" % ( match.key().name(), prediction.isChecked(-1)) html += "<input type='radio' name='%schoice' value='0' disabled %s>" % ( match.key().name(), prediction.isChecked(0)) html += "<input type='radio' name='%schoice' value='1' disabled %s>" % ( match.key().name(), prediction.isChecked(1)) html += "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % ( match.teamBlogo) return html # Bypassing table.html Django template to create this table # Table requires Jquery code for sortable entires and wagers # Hidden input tags are also used with form. prediction_list = OFL_Prediction.all().filter( "season =", season).filter("week =", week).ancestor(coach).filter( "gameScored =", False).order("-wager") columns = ["Wager", "Away Team", "Prediction", "Home Team"] table_html = [] table_html.append(''' <table class="ofl_pickem schedule_table"> <thead> <tr>''') for column in columns: table_html.append( '<th style="text-align: center;"> %s </th>' % column) table_html.append(''' </tr> </thead> <tbody id="sortable">''') k = 0 for prediction in prediction_list: table_html.append('<tr class="row_%s">' % k) table_html.append( '<input type="hidden" name="row_%s" value="%s">' % (k, prediction.key().name())) table_html.append( "<input type='hidden' class='row_%s' name='%svalue' value='%s'>" % (k, prediction.key().name(), prediction.wager)) table_html.append( '<td class="row_%s" style="text -align: center;">%s</td>' % (k, prediction.wager)) table_html.append( '<td style="text-align: center;">%s</td>' % nameA_getter(prediction)) table_html.append( '<td style="text-align: center;">%s</td>' % choice_getter(prediction)) table_html.append( '<td style="text-align: center;">%s</td>' % nameB_getter(prediction)) k += 1 table_html.append('</tbody>\n</table>') table_html = "\n".join(table_html) played_table = Table( columns=[ # profile Column("Points", "Points Earned", attrgetter("points")), Column("Wager", "Wager Placed", attrgetter("wager")), Column("Away Team", "Away Team", nameA_getter, center=True), Column("Prediction", "Your Prediction", choice_getter, center=True), Column("Home Team", "Home Team", nameB_getter, center=True), ], query=OFL_Prediction.all().filter( "season =", season).filter("week =", week).ancestor(coach).filter( "gameScored =", True).order("-points"), id="played_table", cls="tablesorter", ) else: log_in_url = users.create_login_url("/") # render and update #--------------------------------------------------------------------# ofl_pickem_page = misc.render('ofl_pickem_box.html', locals()) self.update(ofl_pickem_page) self.response.out.write(ofl_pickem_page)
teamsite_objects[school] = TeamSite(school, year1, year2) return teamsite_objects, coachsite_objects everything = (Instantiate(2011, 2018)) teamsite = everything[ 0] # gives you a dictionary with keys = school name and values\n", # are TeamSite instances\n", keys = list((teamsite).keys()) coachsite = everything[1] #gives you object instance\n", #######Instansiate coach model########## coach_instances = [] for tup in coachsite.salaries[0]: tup2 = int(tup[2].replace('$', '').replace(',', '')) c_instance = Coach(name = tup[0] , years = tup[1] , salary = tup2,\ sal_school = tup[3]) coach_instances.append(c_instance) session.add(c_instance) #######Instansiate school model########## team_instances = [] for school_name in keys: years_ = teamsite[school_name].years winloss_ = teamsite[school_name].winloss team_points_ = teamsite[school_name].team_points opp_points_ = teamsite[school_name].opp_points for i in range(0, len(years_)): if years_[i] != '' and winloss_[i] != '' and team_points_[ i] != '' and opp_points_[i] != '': team_instance = School(name = school_name, years = years_[i], winloss = winloss_[i],\
def get(self): # check for a cached version #--------------------------------------------------------------------# coach_key = db.Key.from_path("Coach", self.request.get("coach_key_name")) if self.emit(self.response.out, coach_key): return # not cached or evicted from cache; regenerate #--------------------------------------------------------------------# coach = Coach.get(coach_key) if not coach: return coach_stats = CoachStats.all().ancestor(coach).get() # win/draw/loss bars and banner text color #--------------------------------------------------------------------# longest_bar_length = max(coach_stats.wins, coach_stats.draws, coach_stats.losses) banner_text_color = misc.get_contrasting_monochrome(coach.color) # team_table #--------------------------------------------------------------------# def name_getter(team): return "<a rel='team' href='%s'>%s</a>" % (team.get_box_href(), team.key().name()) def race_getter(team): return "<img title='%s' src='%s' />" % ( team.race.key().name(), team.race.get_image_src(thumb=True)) def awp_getter(team): return "%0.3f" % team.awp def glicko_getter(team): return "%4.0f" % team.glicko_r teams = query = Team.all().filter("coach =", coach).filter("matches >", 0).order("-matches") team_table = Table( columns=[ # profile Column(" ", "Race", race_getter, center=True), Column("Team Name", "Team name", name_getter), Column("TV", "Team value (approximate)", attrgetter("tv"), divider=True), # record Column("Pl", "Matches played", attrgetter("matches")), Column("W", "Matches won", attrgetter("wins")), Column("D", "Matches drawn", attrgetter("draws")), Column("L", "Matches lost", attrgetter("losses"), divider=True), # rankings Column("AWP", "Adjusted win percentage", awp_getter), Column("TPts", "Tournament Points", attrgetter("tpts")), Column("Rating", "Glicko Rating", glicko_getter, divider=True), ## touchdowns #Column("TD+", "Touchdowns for", attrgetter("tds_for")), #Column("TD-", "Touchdowns against", attrgetter("tds_against")), #Column("<span class='over'>TD+</span>", "Average touchdowns for", # get_ave_getter("tds_for")), #Column("<span class='over'>TD-</span>", "Average touchdowns against", # get_ave_getter("tds_against")), ## casualties #Column("C+", "Casualties for", attrgetter("cas_for")), #Column("C-", "Casualties against", attrgetter("cas_against")), #Column("<span class='over'>C+</span>", "Average casualties for", # get_ave_getter("cas_for")), #Column("<span class='over'>C-</span>", "Average casualties against", # get_ave_getter("cas_against")), ], query=teams, id="%s-team-table" % coach.key(), cls="tablesorter", ) # coach_stat_table #--------------------------------------------------------------------# def get_left_header(tuple): coach_stats, which = tuple return which.capitalize() def getter(stat): def getter_closure(tuple): coach_stats, which = tuple attr = getattr(coach_stats, "%s_%s" % (stat, which)) return (("<span class='tot_stat'>%d</span>" % attr) + ("<span class='ave_stat'>%.1f</span>" % (attr / float(coach_stats.matches)))) return getter_closure stat_table = Table( columns=[ Column( "<span class='link' id='%s-show-averages-toggle'></span>" % coach.key(), "", get_left_header), Column("TD", "Touchdowns", getter("tds")), Column("P", "Pass completions", getter("passes")), Column("YP", "Yards passing", getter("pyards")), Column("R", "Pass receptions", getter("rec")), Column("YR", "Yards rushing", getter("ryards")), Column("K", "Kills", getter("kills")), Column("C", "Casualties", getter("cas")), Column("KO", "Knock outs", getter("ko")), Column("S", "Stuns", getter("stun")), Column("T", "Tackles", getter("tckl")), Column("I", "Interceptions", getter("int")), ], query=((coach_stats, "for"), (coach_stats, "against")), cls="fancytable stats", ) # match_tables #--------------------------------------------------------------------# def name_getter(record): if record.team.key() == team.key(): return team.key().name() else: return "<a rel='team_opponents' href='%s'>%s</a>" % ( record.team.get_box_href(), record.team.key().name()) def race_getter(record): return "<img src='%s' />" % record.team.race.get_image_src( thumb=True) def link_getter(record): return """ <a rel='team_matches' href='%s'> <span class="go_to_arrow" title='Go to match page'>→</span></a>""" % ( record.get_match().get_box_href()) def glicko_getter(record): return "%4.0f" % record.glicko_r match_columns = [ Column(" ", "Race", race_getter, center=True), Column("Team", "Team name", name_getter), Column("Rating", "Team rating", glicko_getter), Column("TV", "Team value", attrgetter("tv_for")), Column("TD", "Touchdowns", attrgetter("tds_for")), Column("P", "Pass completions", attrgetter("passes_for")), Column("YP", "Yards passing", attrgetter("pyards_for")), Column("R", "Pass receptions", attrgetter("rec_for")), Column("YR", "Yards rushing", attrgetter("ryards_for")), Column("K", "Kills", attrgetter("kills_for")), Column("C", "Casualties", attrgetter("cas_for")), Column("KO", "Knock outs", attrgetter("ko_for")), Column("S", "Stuns", attrgetter("stun_for")), Column("T", "Tackles", attrgetter("tckl_for")), Column("I", "Interceptions", attrgetter("int_for")), Column("", "", link_getter, center=True, rowspan=2) ] # get matches from match_records and sort in order of most recent result = [] for team in teams: for record in TeamRecord.all().filter("team =", team): if record is not None: result.append(record) matches = sorted([record.get_match() for record in result], key=lambda m: m.created, reverse=True)[:30] match_tables = [] for match in matches: # sort with this team's match record first match_records = sorted(match.get_team_records_query(), key=lambda mr: mr.team.coach == coach, reverse=True) result_map = {1: "WIN!", 0: "DRAW", -1: "LOSS"} coach_flag = 0 if match_records[1].team.coach: if coach.key() == match_records[1].team.coach.key(): coach_flag = 1 title = "(%s) <b>%s-%s %s</b> %s vs. %s" % ( match.created.date(), match_records[0].tds_for, match_records[1].tds_for, result_map[match_records[coach_flag].result], match_records[0].team.key().name(), match_records[1].team.key().name()) if match.disconnect: title += " (Disconnect/Forfeit)" match_table = Table(columns=match_columns, query=match_records, cls="tablesorter match_stats", title=title) match_tables.append((match.get_box_href(), match_table)) # active_member = team.get_active_tournament_membership() # active_tournament = active_member.parent() if active_member else None # render and update (TODO: move to bottom after implementing bottom code) #--------------------------------------------------------------------# coach_box = misc.render('coach_box.html', locals()) self.update(coach_box, coach_key) self.response.out.write(coach_box)
def name_getter(standing): coach = Coach.get_by_key_name(standing.get_coach_name()) return "<a class='leader_link' rel='leader_coach' href='%s'>%s</a>" % ( coach.get_box_href(),coach.key().name())
def post(self): tournament_name = self.request.get("tournament_name") if Tournament.get_by_key_name(tournament_name): # TODO error: already exists return max_enrollment = int(self.request.get("max_enrollment")) assert not (max_enrollment < 4 or max_enrollment > 64) background = self.request.get("background") seed_by = self.request.get("seed_by") coach = Coach.get_by_key_name(self.request.get("coach_key_name")) min_tv = self.request.get("min_tv") max_tv = self.request.get("max_tv") min_ma = self.request.get("min_ma") max_ma = self.request.get("max_ma") # compute race restrictions race_restriction = self.request.get("race_restriction") if race_restriction: races_allowed = self.request.get_all("races_allowed") races_allowed = [ db.Key.from_path("Race", race_name) for race_name in races_allowed ] else: races_allowed = [] tournament = Tournament(key_name=tournament_name, owner=coach, background=background, max_enrollment=max_enrollment, seed_by=seed_by, races_allowed=races_allowed) def format_tv(tv): tv = (tv / 10) * 10 return max(0, min(3500, tv)) if min_tv: tournament.min_tv = int(min_tv) if max_tv: tournament.max_tv = int(max_tv) if min_ma: tournament.min_ma = int(min_ma) if max_ma: tournament.max_ma = int(max_ma) trophy_pic = self.request.get("trophy_pic") if trophy_pic: pic = TournamentPicture.create_from_img(tournament_name, trophy_pic) pic.put() tournament.pic = pic tournament.put() views.Tournaments.clear() # I need to give a response or I get an error. Nobody on the internet seems # to know why. See https://github.com/malsup/form/issues#issue/22. self.response.out.write("OK")
def get(self): # check for a cached version #--------------------------------------------------------------------# if self.emit(self.response.out): return # not cached or evicted from cache; regenerate #--------------------------------------------------------------------# user = users.get_current_user() coach = None if user: coach = Coach.all().filter("user ="******"<img src='get_trophy?size=thumb&tournament_key=%s' />" % tournament.key() return "" def name_getter(tournament): return "<a rel='tournaments' href='%s'>%s</a>" % ( tournament.get_box_href(), tournament.key().name()) def date_getter(tournament): return tournament.created.date() def organizer_getter(tournament): return tournament.owner.key().name() def enrollment_getter(tournament): return "%s/%s" % ( TournamentMembership.all().ancestor(tournament).count(), tournament.max_enrollment) def final_enrollment_getter(tournament): return TournamentMembership.all().ancestor(tournament).count() def winner_getter(tournament): return "<a rel='winners' href='%s'>%s</a> (%s)" % ( tournament.winning_team.get_box_href(), tournament.winning_team.key().name(), tournament.winning_team.coach.key().name()) def tv_getter(tournament): if tournament.min_tv and tournament.max_tv: return "%s - %s" % (tournament.min_tv, tournament.max_tv) elif tournament.min_tv: return "≥ %s" % tournament.min_tv elif tournament.max_tv: return "≤ %s" % tournament.max_tv else: return "Any" def ma_getter(tournament): if tournament.min_ma != None and tournament.max_ma != None: return "%s - %s" % (tournament.min_ma, tournament.max_ma) elif tournament.min_ma != None: return "≥ %s" % tournament.min_ma elif tournament.max_ma != None: return "≤ %s" % tournament.max_ma else: return "Any" def races_getter(tournament): if tournament.races_allowed: return "Restricted" else: return "Any" tournaments = {} for tournament in Tournament.all(): if tournament.winning_team: tournaments.setdefault("Completed", []).append(tournament) elif tournament.started: tournaments.setdefault("In Progress", []).append(tournament) else: tournaments.setdefault("Open", []).append(tournament) tables = [ ("Open", Table( columns = [ Column("", "Trophy Image", trophy_getter, center=True), Column("Name", "Tournament name", name_getter), Column("Created", "Creation date", date_getter), Column("Organizer", "Tournament organizer", organizer_getter), Column("Enrolled", "Enrollment count", enrollment_getter), Column("TV", "TV range", tv_getter), Column("Matches Played", "Matches played range", ma_getter), Column("Races", "Races allowed", races_getter), Column("Seed By", "Teams are seeded by", attrgetter("seed_by")), ], query = tournaments.get("Open", []), cls = "tablesorter tournaments_table", )), ("In Progress", Table( columns = [ Column("", "Trophy Image", trophy_getter, center=True), Column("Name", "Tournament name", name_getter), Column("Created", "Creation date", date_getter), Column("Organizer", "Tournament organizer", organizer_getter), Column("Enrolled", "Final enrollment count", final_enrollment_getter), Column("TV", "TV range", tv_getter), Column("Races", "Races allowed", races_getter), ], query = tournaments.get("In Progress", []), cls = "tablesorter tournaments_table", )), ("Completed", Table( columns = [ Column("", "Trophy Image", trophy_getter, center=True), Column("Name", "Tournament name", name_getter), Column("Created", "Creation date", date_getter), Column("Organizer", "Tournament organizer", organizer_getter), Column("Winner", "Tournament winner", winner_getter), Column("Enrolled", "Final enrollment count", final_enrollment_getter), Column("TV", "TV range", tv_getter), Column("Races", "Races allowed", races_getter), ], query = tournaments.get("Completed", []), cls = "tablesorter tournaments_table", ))] # render and update #--------------------------------------------------------------------# tournaments = misc.render('tournaments.html', locals()) self.update(tournaments) self.response.out.write(tournaments)
def get(self): user = users.get_current_user() if user: log_out_url = users.create_logout_url("/") coach = Coach.all().filter("user ="******"schedule").split("-") if not season or not week: season, week = misc.get_ofl_season_and_week() season += 3 else: season = int(season) week = int(week) parser = OFLScheduleParser() ofl_info = urlfetch.fetch("http://www.shalkith.com/bloodbowl/processSchedule.php?s=%s&w=%s" % (season, week)) parser.feed(ofl_info.content) update_schedule_entries(coach, season, week, parser.data) sort_wagers(coach, season, week) def logoA_getter(match): html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (match.teamAlogo) return html def logoB_getter(match): html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (match.teamBlogo) return html def nameA_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "%s (%s)" % (match.teamA, match.teamAcoach) return html def nameB_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "%s (%s)" % (match.teamB, match.teamBcoach) return html def key_name_getter(prediction): return prediction.key().name() def choice_getter(prediction): match = OFL_Match.get_by_key_name(prediction.key().name()) html = "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (match.teamAlogo) if not match.gamePlayed: html += "<input type='radio' name='%schoice' value='-1' %s>" % (match.key().name(), prediction.isChecked(-1)) html += "<input type='radio' name='%schoice' value='0' %s>" % (match.key().name(), prediction.isChecked(0)) html += "<input type='radio' name='%schoice' value='1' %s>" % (match.key().name(), prediction.isChecked(1)) else: html += "<input type='radio' name='%schoice' value='-1' disabled %s>" % (match.key().name(), prediction.isChecked(-1)) html += "<input type='radio' name='%schoice' value='0' disabled %s>" % (match.key().name(), prediction.isChecked(0)) html += "<input type='radio' name='%schoice' value='1' disabled %s>" % (match.key().name(), prediction.isChecked(1)) html += "<img src='http://www.shalkith.com/bloodbowl/%s'/>" % (match.teamBlogo) return html # Bypassing table.html Django template to create this table # Table requires Jquery code for sortable entires and wagers # Hidden input tags are also used with form. prediction_list = OFL_Prediction.all().filter("season =", season).filter("week =", week).ancestor(coach).filter("gameScored =", False).order("-wager") columns = ["Wager", "Away Team", "Prediction", "Home Team"] table_html = [] table_html.append(''' <table class="ofl_pickem schedule_table"> <thead> <tr>''') for column in columns: table_html.append('<th style="text-align: center;"> %s </th>' % column) table_html.append(''' </tr> </thead> <tbody id="sortable">''') k = 0 for prediction in prediction_list: table_html.append('<tr class="row_%s">' % k) table_html.append('<input type="hidden" name="row_%s" value="%s">' % (k, prediction.key().name())) table_html.append("<input type='hidden' class='row_%s' name='%svalue' value='%s'>" % (k, prediction.key().name(), prediction.wager)) table_html.append('<td class="row_%s" style="text -align: center;">%s</td>' % (k, prediction.wager)) table_html.append('<td style="text-align: center;">%s</td>' % nameA_getter(prediction)) table_html.append('<td style="text-align: center;">%s</td>' % choice_getter(prediction)) table_html.append('<td style="text-align: center;">%s</td>' % nameB_getter(prediction)) k += 1 table_html.append('</tbody>\n</table>') table_html = "\n".join(table_html) played_table = Table( columns = [ # profile Column("Points", "Points Earned", attrgetter("points")), Column("Wager", "Wager Placed", attrgetter("wager")), Column("Away Team", "Away Team", nameA_getter, center=True), Column("Prediction", "Your Prediction", choice_getter, center=True), Column("Home Team", "Home Team", nameB_getter, center=True), ], query = OFL_Prediction.all().filter("season =", season).filter("week =", week).ancestor(coach).filter("gameScored =", True).order("-points"), id = "played_table", cls = "tablesorter", ) else: log_in_url = users.create_login_url("/") # render and update #--------------------------------------------------------------------# ofl_pickem_page = misc.render('ofl_pickem_box.html', locals()) self.update(ofl_pickem_page) self.response.out.write(ofl_pickem_page)