Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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)