def post(self, base_url, extra): """The user is saving their availability for the year, so save it to the datastore and invalidate the affected pages' HTML""" try: delete_years = set() if self.request.POST.has_key('updated'): player = Player.get_by_key_name(self.request.get('updated')) for year_round_key in self.request.POST.keys(): try: split_key = year_round_key.split('-') year = split_key[0] delete_years.add(year) round = split_key[1] if len(round) == 0: # Might have been a negative round, so an extra split! round = '-' + split_key[2] round_key = Round.get_key(round, year) round = Round.get_by_key_name(round_key) # Writes the current round's date each time, just in case it has changed. Would have preferred to have # multiple records for the player, linked by date and not time, but django made it difficult (unless I # wanted to have a Model that just contains a date, and everything links back to that...) if round: args = { 'key_name': Availability.get_key(player.db_key, round.num, round.year), 'year': round.year, 'round': round, 'player': player, 'playing': self.request.POST.get(year_round_key) == "0", 'given_date': round.date, } Availability(**args).put() except IndexError: pass # Pages that have been affected by this update: for y in delete_years: # - Draw page, via the number available memcache.delete(PlayerPage.get_draw_mem_key(y)) # - Player summary, because their checkboxes have changed memcache.delete( PlayerPage.get_player_mem_key(player.db_key, y)) memcache.delete(PlayerPage.get_draw_mem_key(ALL_YEARS)) memcache.delete( PlayerPage.get_player_mem_key(player.db_key, ALL_YEARS)) self.get(base_url, extra) except Exception, e: self.get(base_url, extra, error=e)
def do_body(self, args): """Render the HTML for all the results, and provide enough information to edit an game""" data = { 'url_args': args, } year = self.get_year(args) if year == ALL_YEARS: data['rounds'] = Round.gql('ORDER BY date ASC') else: data['rounds'] = Round.gql('WHERE year = :1 ORDER BY date ASC', year) tpath = os.path.join(DeeWhyPage.TEMPLATE_DIR, 'rounds.html') self.response.out.write(template.render(tpath, data)) data = { 'url_args': args, } # Get the full data for the given round so they can edit it if args.has_key('round'): round_num = args['round'] round_key = Round.get_key(round_num, year) result_key = Result.get_key(round_num, year) if round_key != '': curr_round = Round.get_by_key_name(round_key) if curr_round: data['players'] = [ p.player for p in TeamList.gql('WHERE year = :1', curr_round.date.year) ] data['players'].sort(self.sort_players) data['round'] = curr_round curr_result = Result.get_by_key_name(result_key) if curr_result: data['result'] = curr_result if curr_result.other_goals == 0: curr_result.other_goals = None if curr_result.own_goals == 0: curr_result.own_goals = None #if curr_result.deewhy_forfeit: # curr_result.deewhy_goals = 0 # curr_result.opponent_goals = 5 #elif curr_result.opponent_forfeit: # curr_result.deewhy_goals = 5 # curr_result.opponent_goals = 0 tpath = os.path.join(DeeWhyPage.TEMPLATE_DIR, 'manage_results.html') self.response.out.write(template.render(tpath, data))
def post(self, base_url, extra): """Save the data posted about the all the items from the HTML form""" try: delete_years = set() # Only refresh the cache for affected years # All the rounds are saved at once for year_round_key in self.request.POST.keys(): try: split_key = year_round_key.split('-') year = split_key[0] delete_years.add(year) round = split_key[1] if len(round) == 0: # Might have been a negative round, so an extra split! round = '-' + split_key[2] round_key = Round.get_key(round, year) round = Round.get_by_key_name(round_key) if round: args = { 'year': round.year, 'key_name': self.data_class.get_key(round.num, round.year), 'round': round } player_key = self.request.POST.get(year_round_key) args[self.name_property] = player_key if not player_key in self.data_class.OTHERS: args['player_ref'] = Player.get_by_key_name( player_key) new_entry = self.data_class(**args) new_entry.put() except IndexError: pass # Flush the cache for the affected years for y in delete_years: memcache.delete(CommonItemPage.get_mem_key(self.type, y)) memcache.delete(CommonItemPage.get_mem_key(self.type, ALL_YEARS)) self.get(base_url, extra) except Exception, e: self.get(base_url, extra, error=e)
def do_body(self, args): """Render the HTML for all the rounds, and provide enough information to edit an existing round or create a new one""" data = { 'url_args': args, 'new_round': True, 'grounds': Ground.gql('ORDER BY name ASC') } year = self.get_year(args) if year == ALL_YEARS: data['rounds'] = Round.gql('ORDER BY date ASC') else: data['rounds'] = Round.gql('WHERE year = :1 ORDER BY date ASC', year) # Retrieve the full information for the given round so we can edit it if args.has_key('round'): round_key = Round.get_key( urllib.unquote(urllib.unquote(args['round'])), year) curr_round = Round.get_by_key_name(round_key) if curr_round: data['current'] = curr_round data['new_round'] = False tpath = os.path.join(DeeWhyPage.TEMPLATE_DIR, 'manage_draw.html') self.response.out.write(template.render(tpath, data))
def post(self, base_url, extra): """Save the data posted about the result from the HTML form""" try: curr_round = None round_num = int(self.request.get('round_num')) year = int(self.request.get('year')) round_key = Round.get_key(round_num, year) if round_key: curr_round = Round.get_by_key_name(round_key) if curr_round: # Quite a few cached pages depend upon this output, need to delete them all # - Removing this page from the summary memcache.delete(PlayerPage.get_draw_mem_key(year)) memcache.delete(PlayerPage.get_draw_mem_key(ALL_YEARS)) # - Disabling the options for this page for each player for t in TeamList.gql('WHERE year = :1', year): memcache.delete( PlayerPage.get_player_mem_key(t.player.db_key, year)) # - Changing the result and who scored memcache.delete(ResultsPage.get_mem_key(year)) memcache.delete(ResultsPage.get_mem_key(ALL_YEARS)) # - Changing the number of goals memcache.delete(ScorersPage.get_mem_key(year)) memcache.delete(ScorersPage.get_mem_key(ALL_YEARS)) # - Triggering previously suppressed rounds for the beer and shirts memcache.delete(BeerPage.get_mem_key('beer', year)) memcache.delete(BeerPage.get_mem_key('beer', ALL_YEARS)) memcache.delete(ShirtsPage.get_mem_key('shirts', year)) memcache.delete(ShirtsPage.get_mem_key('shirts', ALL_YEARS)) args = { 'year': year, 'key_name': Result.get_key(round_num, year), 'round': curr_round, } deewhy_forfeit = self.request.get('deewhy_forfeit') opponent_forfeit = self.request.get('opponent_forfeit') if not (deewhy_forfeit or opponent_forfeit): # Regular operation - read the goal counts args['deewhy_goals'] = self.get_goals('deewhy_goals') args['opponent_goals'] = self.get_goals('opponent_goals') args['other_goals'] = self.get_goals('other_goals') args['own_goals'] = self.get_goals('own_goals') elif deewhy_forfeit is not None and self.request.get( 'deewhy_forfeit') == 'on': # No goals in a forfeit args['deewhy_forfeit'] = True elif opponent_forfeit is not None and self.request.get( 'opponent_forfeit') == 'on': # No goals in a forfeit args['opponent_forfeit'] = True curr_result = Result(**args) curr_result.put() # Need to delete any existing scorers for this round - otherwise orphaned goals will stuff up the tallies for scorer in curr_result.scorer_set: scorer.delete() if not (deewhy_forfeit or opponent_forfeit): for post_key in self.request.POST.keys(): # Each goal scorer in the game needs a separate record if post_key.startswith('goals_'): player = Player.get_by_key_name( post_key[len('goals_'):]) goals = self.get_goals(post_key) if player is not None and goals > 0: GoalsScored( key_name=GoalsScored.get_key( player.db_key, round_num, year), year=int(year), player=player, result=curr_result, count=goals, ).put() self.get(base_url, extra) except Exception, e: self.get(base_url, extra, error=e)
def delete_round(self, key): """Scrap the entire round""" if key: r = Round.get_by_key_name(key) if r: r.delete()