Beispiel #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))
Beispiel #2
0
 def do_body(self, args):
     """Render the HTML for all the items, and provide enough information to edit one of them."""
     updated_args = dict(args)
     year = self.get_year(args)
     updated_args['year'] = year
     data = {
         'url_args': updated_args,
     }
     if year == ALL_YEARS:
         data['rounds'] = Round.gql('ORDER BY date ASC')
         data['players'] = Player.gql(
             'ORDER BY last_name ASC, first_name ASC')
     else:
         data['rounds'] = Round.gql('WHERE year = :1 ORDER BY date ASC',
                                    int(year))
         data['players'] = [
             p.player for p in TeamList.gql('WHERE year = :1', int(year))
         ]
         data['players'].sort(self.sort_players)
     tpath = os.path.join(DeeWhyPage.TEMPLATE_DIR, self.template_file)
     self.response.out.write(template.render(tpath, data))
Beispiel #3
0
    def do_body(self, args):
        """Render the HTML for the front page"""
        self.do_player_list(args)
        year = self.get_year(args)
        # Different key for the different modes
        if args.has_key('player'):
            mem_key = PlayerPage.get_player_mem_key(args['player'], year)
        else:
            mem_key = PlayerPage.get_draw_mem_key(year)

        player_page = memcache.get(mem_key)
        if player_page is None:
            data = {
                'url_args': args,
            }

            # Switches mode depending on the input:
            if args.has_key('player'):
                # Present the player with the dialogues to set the availability
                page = 'individual.html'
                data = {
                    'rounds': Round.gql('WHERE year = :1 ORDER BY date ASC',
                                        year),
                    'player': Player.get_by_key_name(args['player']),
                }
            else:
                # Present the full season summary of upcoming games
                page = 'summary.html'
                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, page)
            player_page = template.render(tpath, data)
            memcache.set(mem_key, player_page)
        self.response.out.write(player_page)
Beispiel #4
0
    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))
Beispiel #5
0
    def do_body(self, args):
        """Generate the HTML email if there is an upcoming game"""
        day_skip = 2
        if args.has_key('days'):
            try:
                day_skip = int(args['days'])
            except:
                pass
        admin_address = '*****@*****.**'
        curr_date = datetime.now()
        start_date = curr_date.replace(hour=0, minute=0,
                                       second=0) + timedelta(days=day_skip)
        end_date = curr_date.replace(hour=0, minute=0,
                                     second=0) + timedelta(days=day_skip + 1)

        # Find all the games that are within the given date range - really only expect one, behaviour
        # could end up a little strange if there's multiple...
        query = Round.gql('WHERE date >= :1 AND date <= :2', start_date,
                          end_date)
        curr_round = query.get()
        logging.debug('WHERE date >= %s AND date <= %s' %
                      (start_date, end_date))
        logging.debug(curr_round)

        if curr_round:
            data = {
                'current': curr_round,
            }

            tpath = os.path.join(DeeWhyPage.TEMPLATE_DIR, 'mailer.html')
            email_content = template.render(tpath, data)
            self.response.out.write(
                email_content)  # Print the content as an added debug

            players = [
                p.player
                for p in TeamList.gql('WHERE year = :1', curr_round.date.year)
            ]
            non_admins = []
            admin = ''
            for p in players:
                details = '%s %s<%s>' % (p.first_name, p.last_name, p.email)
                if p.email == admin_address:
                    admin = details
                else:
                    non_admins.append(details)
            recipients = ','.join(non_admins)
            cc_recipients = admin  # working around a server bug where cron emails fail when sent to me!
            #recipients = 'Test Guy<*****@*****.**>' % (curr_date.strftime('%A %d %B %I:%M'))	# To make sure tests don't go out!
            logging.debug('Sending to ' + recipients)
            """
			recipients = ','.join([
				'Adam1<*****@*****.**>',
				'Adam2<*****@*****.**>',
				])
			logging.debug('Really sending to ' + recipients)
			"""

            caption = curr_round.caption
            if not caption:
                caption = 'Round ' + ` int(curr_round.num) `
            kickoffStr = ` int(curr_round.time.strftime('%I')) `
            if curr_round.time.minute > 0:
                kickoffStr += ':' + curr_round.time.strftime('%M')
            kickoffStr += curr_round.time.strftime('%p')
            subject = caption + ' - ' + curr_round.date.strftime(
                '%A %d %B') + ' at ' + kickoffStr

            message = mail.EmailMessage()
            message.subject = subject
            message.sender = 'Dee Why AL5 Team Page<*****@*****.**>'
            message.to = recipients
            message.cc = cc_recipients
            # Too lazy to add BCC recipients as a UI option so just add them here
            message.bcc = '*****@*****.**'
            message.html = email_content
            message.check_initialized()
            message.send()