Exemple #1
0
 def commit(self, d):
     '''
     Mark done/not-done for a habit day
     '''
     from constants import HABIT_COMMIT_REPLIES
     habit_id = self.request.get_range('habit_id')
     day_iso = self.request.get('date')
     habit = self.user.get(Habit, id=habit_id)
     hd = None
     if habit:
         hd = HabitDay.Commit(habit, tools.fromISODate(day_iso))
         self.message = random.choice(HABIT_COMMIT_REPLIES)
         self.success = True
     self.set_response({'habitday': hd.json() if hd else None})
Exemple #2
0
 def _habit_commit(self, habit_param_raw):
     handled = False
     speech = None
     if habit_param_raw:
         habits = Habit.Active(self.user)
         for h in habits:
             if habit_param_raw.lower() in h.name.lower():
                 # TODO: Timezone?
                 hd = HabitDay.Commit(h, datetime.today().date())
                 encourage = random.choice(HABIT_COMMIT_REPLIES)
                 speech = "You've committed to '%s' today. %s" % (h.name, encourage)
                 handled = True
                 break
         if not handled:
             speech = "I'm not sure what you mean by '%s'. You may need to create a habit before you can commit to it." % habit_param_raw
     else:
         speech = "I couldn't tell what habit you want to commit to."
     return speech