コード例 #1
0
ファイル: agent.py プロジェクト: xverges/flow-dashboard
 def _habit_status(self):
     habits = Habit.All(self.user)
     today = self.user.local_time().date()
     habitday_keys = [
         ndb.Key('HabitDay', HabitDay.ID(h, today), parent=self.user.key)
         for h in habits
     ]
     habitdays = ndb.get_multi(habitday_keys)
     n_habits_done = 0
     habits_committed_undone = []
     habits_done = []
     for hd in habitdays:
         if hd:
             habit = hd.habit.get()
             if hd.committed and not hd.done:
                 if habit:
                     habits_committed_undone.append(habit.name)
             if hd.done:
                 habits_done.append(habit.name)
                 n_habits_done += 1
     if habits:
         if n_habits_done:
             text = "Good work on doing %d %s (%s)!" % (
                 n_habits_done, tools.pluralize('habit', n_habits_done),
                 tools.english_list(habits_done))
         else:
             text = "No habits done yet."
         if habits_committed_undone:
             text += " Don't forget you've committed to %s." % tools.english_list(
                 habits_committed_undone)
     else:
         text = "You haven't added any habits yet. Try saying 'add habit run'"
     return text
コード例 #2
0
    def testPluralize(self):
        volley = [("item", 1, "item"), ("cat", 10, "cats"),
                  ("hamburger", 0, "hamburgers")]

        for v in volley:
            _in, _count, _expect = v
            out = tools.pluralize(_in, count=_count)
            self.assertEqual(out, _expect)
コード例 #3
0
    def testPluralize(self):
        volley = [
            ("item", 1, "item"),
            ("cat", 10, "cats"),
            ("hamburger", 0, "hamburgers")
        ]

        for v in volley:
            _in, _count, _expect = v
            out = tools.pluralize(_in, count=_count)
            self.assertEqual(out, _expect)
コード例 #4
0
ファイル: agent.py プロジェクト: hd21/flow-dashboard
 def _tasks_request(self):
     tasks = Task.Recent(self.user)
     tasks_undone = []
     n_done = Task.CountCompletedSince(self.user, datetime.combine(datetime.today(), time(0,0)))
     for task in tasks:
         if not task.is_done():
             tasks_undone.append(task.title)
     if n_done:
         text = "You've completed %d %s for today." % (n_done, tools.pluralize('task', n_done))
     else:
         text = "You haven't completed any tasks yet."
     if tasks_undone:
         text += " You still need to do %s." % tools.english_list(tasks_undone)
     if not n_done and not tasks_undone:
         text += " Try adding tasks by saying 'add task Q2 planning'"
     return text
コード例 #5
0
 def action(self, d):
     '''
     '''
     action = self.request.get('action')
     res = {}
     if action == 'archive_complete':
         recent = Task.Recent(self.user, limit=20)
         to_archive = []
         for t in recent:
             if not t.archived and t.is_done():
                 t.archive()
                 to_archive.append(t)
         if to_archive:
             ndb.put_multi(to_archive)
             res['archived_ids'] = [t.key.id() for t in to_archive]
             self.message = "Archived %d %s" % (len(to_archive), tools.pluralize('task', count=len(to_archive)))
         else:
             self.message = "No completed tasks to archive"
         self.success = True
     else:
         self.message = "Unknown action"
     self.set_response(res)
コード例 #6
0
 def rename(self, name):
     self.name = name
     self.name_plural = tools.pluralize(name)