Exemplo n.º 1
0
def picks():
    user_obj = flask.g.user_obj
    week = int(flask.request.args.get('week', util.get_week()))
    return flask.render_template('picks.html',
                                 username=user_obj.name,
                                 week=week,
                                 picks=user_obj.picks_for_week(week))
Exemplo n.º 2
0
def get_counters(name):
    """
    获取此计数器的若干个实例,如总计数,本日计数,本月计数,本年计数
    """
    time_periods = [
        "all",
        util.get_today(),
        util.get_week(),
        util.get_month(),
        util.get_year()
    ]

    res = [get_counter(name, time_period) for time_period in time_periods]
    return res
Exemplo n.º 3
0
 def _get_todo_history_holes(self, date_range, week_pre):
     """Add missed days/weeks to history table: weekends or days off"""
     history_buffer = []
     for item in date_range:
         week = util.get_week(item)
         if week_pre != week['num']:
             headers = self._generate_timestamp_header(item)
             history_buffer.extend(
                 ['', headers['week'], self.tbl['todo']['singleline']])
         if week['day'] in self.settings['weekend']:
             history_buffer.append(
                 '  %s    Weekend' %
                 self._generate_timestamp_header(item)['day'])
         else:
             history_buffer.append(
                 '  %s    Day off' %
                 self._generate_timestamp_header(item)['day'])
         week_pre = week['num']
     return history_buffer, week_pre
Exemplo n.º 4
0
    def _generate_timestamp_header(self,
                                   date=None,
                                   time=None,
                                   time_evening=None):
        """Generate formatted timestamp strings.
        Return formatted week, day, day_time, day_time_delta...
        """
        if not date:
            timestamp = self._get_timestamp()
        else:
            timestamp = {'date': date, 'time': time}

        week = util.get_week(timestamp['date'])
        foo = {}
        foo['week'] = 'Week %02d' % week['num']

        if timestamp['time']:
            foo['day_time'] = '%s, %s, %s' % (timestamp['date'], week['day'],
                                              timestamp['time'])
        else:
            foo['day_time'] = 'Hole'

        foo['day'] = '%s, %s' % (timestamp['date'], week['day'])

        if time_evening:
            hm = [timestamp['time'].split(':'), time_evening.split(':')]
            hm = [[int(hm[i][j]) for j in (range(2))] for i in range(2)]
            duration_in_mins = (hm[1][0] - hm[0][0]) * 60 + (hm[1][1] -
                                                             hm[0][1])
            # pass midnight timestamp
            duration_in_mins = duration_in_mins + 24 * 60 if duration_in_mins < 0 else duration_in_mins
            duration = '%02d:%02d' % (duration_in_mins / 60,
                                      duration_in_mins % 60)
            foo['day_time_delta'] = '%s, %s, %s - %s, %s' % (
                timestamp['date'], week['day'], timestamp['time'],
                time_evening, duration)
        else:
            foo['day_time_delta'] = 'Hole'

        return foo
Exemplo n.º 5
0
    def _generate_todo_history(self):
        """Generate history part of TODO table. Historical range date is defined by settings."""
        todo_history = self.todo_db_history.search(
            (db.Query().date.search(self.settings['todo_history']['re'])))
        todo_history.sort(key=operator.itemgetter('date'))
        todo_history.reverse()
        # self.log.info(todo_history)
        todo_history_buffer = []
        todo_history_buffer.append(self.tbl['todo']['history']['header'])
        todo_history_buffer.append(self.tbl['todo']['doubleline'])
        # todo_history_buffer.append('')

        week_pre = -1
        day_pre = self._get_timestamp()['date']
        for day in todo_history:
            # fill todo_history holes: weekends, holidays, vacations, etc
            missed_range = self._get_date_range(day['date'], day_pre)
            if missed_range:
                todo_history_buffer.append('')
                history_buffer, week_pre = self._get_todo_history_holes(
                    missed_range, week_pre)
                todo_history_buffer.extend(history_buffer)

            week_cur = util.get_week(day['date'])['num']
            headers = self._generate_timestamp_header(day['date'],
                                                      day['time_morning'],
                                                      day['time_evening'])
            if week_pre != week_cur:
                todo_history_buffer.extend(
                    ['', headers['week'], self.tbl['todo']['singleline']])

            todo_history_buffer.append('')
            todo_history_buffer.append('  %s' % headers['day_time_delta'])
            todo_history_buffer.append('    %s' %
                                       self.tbl['todo']['today']['tbl_header'])
            total = {'est': 0, 'pom': 0}
            for item in day['todo_item']:
                todo_today_tbl_line = (util.allign_text(
                    str(item['est']),
                    5,
                ), util.allign_text({
                    0: '',
                    1: 'Ok'
                }[item['sta']], 5), util.allign_text(str(item['pom']),
                                                     5), item['task'])
                todo_history_buffer.append(
                    '    ' + self.tbl['todo']['today']['tbl_task_line'] %
                    todo_today_tbl_line)
                total['est'] += item['est']
                total['pom'] += item['pom']
            todo_today_tbl_line = (util.allign_text(str(total['est']),
                                                    5,
                                                    alligner='-'),
                                   util.allign_text('', 5, alligner='-'),
                                   util.allign_text(str(total['pom']),
                                                    5,
                                                    alligner='-'), '= Total')
            todo_history_buffer.append(
                '    ' + self.tbl['todo']['today']['tbl_task_line'] %
                todo_today_tbl_line)

            week_pre = week_cur
            day_pre = day['date']
        todo_history_buffer.append(self.tbl['todo']['pointline'])
        return todo_history_buffer
Exemplo n.º 6
0
def picks():
    user_obj = flask.g.user_obj
    week = int(flask.request.args.get("week", util.get_week()))
    return flask.render_template("picks.html", username=user_obj.name, week=week, picks=user_obj.picks_for_week(week))
Exemplo n.º 7
0
def homepage():
    user_obj = flask.g.user_obj
    return flask.render_template("homepage.html", username=user_obj.name, week=util.get_week())
Exemplo n.º 8
0
def test_get_week():
    assert get_week(now_for_test) == "2021-week-31"
Exemplo n.º 9
0
def homepage():
    user_obj = flask.g.user_obj
    return flask.render_template('homepage.html',
                                 username=user_obj.name,
                                 week=util.get_week())