def _habit_status(self):
habits = Habit.All(self.user)
today = datetime.today().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
评论列表
文章目录