def get(self):
     next_treat_time = TreatQueue.get_next_treat_time()
     if next_treat_time:
         next_treat_time = format_datetime_for_printing(next_treat_time)
     else:
         next_treat_time = "No treats scheduled :( Give the next treat!"
     next_treat_slot = TreatQueue.get_next_open_treat_slot()
     next_treat_slot = format_datetime_for_printing(next_treat_slot)
     self.render("templates/index.html", 
                 next_treat_time=next_treat_time,
                 next_treat_slot=next_treat_slot)
    def post(self):
        success = False
        error = None
        phone = self.get_argument('phone')
        name = self.get_argument('name')
        phone = format_valid_phone_number(phone)
        if phone and name:
            latest_treat = TreatQueue.get_latest_treat()
            if latest_treat and latest_treat.get(TreatQueue.A_PHONE) == phone:
                error = 'duplicate'
            else:
                next_treat_slot = TreatQueue.get_next_open_treat_slot()
                treat_time = TreatQueue.add_to_queue(name, phone, next_treat_slot)
                if treat_time:
                    success = True
                else:
                    error = 'other_error'
        else:
            error = 'missing_param'
        
        if success:
            resp = {
                'success':1,
                'treat_time': treat_time
            }
        elif error == "missing_param":
            resp = {
                'error': 1,
                'message': 'Either first_name or phone_number were not provided'
            }
        elif error == "duplicate":
            resp = {
                'error': 1,
                'message': 'Sorry, you can\'t sign up for two treats in a row'
            }
        elif error == "other_error":
            resp = {
                'error': 1,
                'message': 'Sorry, there was an error adding you to the queue'
            }

        self.write(resp)
 def post(self):
     phone = self.get_argument('phone')
     name = self.get_argument('name')
     phone = format_valid_phone_number(phone)
     if phone and name:
         next_treat_slot = TreatQueue.get_next_open_treat_slot()
         treat_time = TreatQueue.add_to_queue(name, phone, next_treat_slot)
         if treat_time:
             resp = {
                 'success':1,
                 'treat_time': treat_time
             }
         else:
             resp = {
                 'error': 1,
                 'message': 'Sorry, there was an error adding you to the queue'
             }
     else:
         resp = {
             'error': 1,
             'message': 'Either first_name or phone_number were not provided'
         }
     self.write(resp)
 def get(self):
     treat_queue = TreatQueue.get_treat_queue()
     self.write(simplejson.dumps(treat_queue))