Пример #1
0
    def get(self):
        logging.info('Analyzing for: %s', users.get_current_user().nickname())

        try:
            weeks = int(self.request.get('weeks'))
        except ValueError:
            weeks = DEFAULT_WEEKS

        time_min = datetime.utcnow() - timedelta(weeks=weeks)
        time_max = datetime.utcnow()

        cal_id = self.request.get('cal', default_value=DEFAULT_CAL_ID)
        # TODO: The get_events and get_cal_name calls should be concurrent
        try:
            events = _get_events(cal_id, time_min, time_max)
        except AccessTokenRefreshError:
            return self.redirect('/')
        cal_name = get_cal_name(cal_id, service, decorator.http())

        stats = _generate_stats(time_min, time_max, events)

        params = {
            'cal_id': cal_id,
            'time_min': time_min,
            'time_max': time_max,
            'weeks': weeks,
            'work_day_start': WORK_DAY_START,
            'work_day_end': WORK_DAY_END,
            }
        data = {
            'events': events,
            'params': params,
            'stats': stats,
            'stats_json': json.dumps(stats),
            'cal_name': cal_name,
            'pformat': pformat,
            'title': cal_name,
            'page': 'analyze',
            'js': 'analyze',
            'css': 'analyze',
            }
        template = template_engine.get_template('analyze.html')
        self.response.out.write(template.render(data))
Пример #2
0
    def get(self):
        logging.info('Choosing calendar for: %s', users.get_current_user().nickname())

        has_credentials = decorator.has_credentials(),

        if has_credentials:
            try:
                items = _get_calendar_list()
                primary = get_cal_name('primary', service, decorator.http())
            except AccessTokenRefreshError:
                return self.redirect('/choose_cal')

        data = {
            'title': 'Choose Calendar',
            'page': 'analyze',
            'has_credentials': has_credentials,
            'auth_url': decorator.authorize_url(),
            'revoke_url': 'https://www.google.com/accounts/b/0/IssuedAuthSubTokens',
            'primary': primary,
            'items': items,
            }
        template = template_engine.get_template('choose_cal.html')
        self.response.out.write(template.render(data))