Esempio n. 1
0
    def post(self):
        """
        Register a user for wakeup calls
        """
        params = {'phone_number': None, 'timezone': None, 
                  'wakeup_hour': None, 'wakeup_minute': None}
                  
        for k, v in params.items():
            params[k] = cgi.escape(self.request.get(k))
                    
        if not params['phone_number']:
            params['error'] = 'you forgot to give us your number'
            return self.__render(params)

        # Create a user for the given details. Validation of phone numbers
        # will occur through twilio, at which point we'll set the user's
        # `validated` attribute to true
        tz = pytz.timezone(params['timezone'])
        user_time = datetime.datetime(1970, 1, 1,
                      int(params['wakeup_hour']),
                      int(params['wakeup_minute']))
        wakeup_time = tz.localize(user_time).astimezone(pytz.utc).time()
        user = User(**{'phone_number': params['phone_number'],
                       'wakeup_time': wakeup_time,
                       'timezone': params['timezone']})

        user.put()
        validation_call_url = "%s/twilio/validation?user_key=%s" % \
                              (WALRUS_DOMAIN, user.key())
        twilio_res = user.call(validation_call_url)
        if twilio_res:
            self.redirect("/confirm?user_id=%s" % user.key().id())
        else:
            params['error'] = 'that number is invalid'
Esempio n. 2
0
 def get(self):
     """
     User succeed
     """
     user_id = cgi.escape(self.request.get('user_id'))
     user = User.get_by_id(int(user_id))
     tz = pytz.timezone(user.timezone)
     proper_time = datetime.datetime(1970,1,1,user.wakeup_time.hour,
                   user.wakeup_time.minute)
     local_time = pytz.utc.localize(proper_time).astimezone(tz).time()
     template_values = {'domain': WALRUS_DOMAIN, 'user': user,
                        'local_time': local_time}
     path = os.path.join(TEMPLATE_DIR, 'registration_success.html')
     self.response.out.write(template.render(path, template_values))
Esempio n. 3
0
 def get(self):
     """
     User succeed
     """
     user_id = cgi.escape(self.request.get('user_id'))
     user = User.get_by_id(int(user_id))
     tz = pytz.timezone(user.timezone)
     proper_time = datetime.datetime(1970, 1, 1, user.wakeup_time.hour,
                                     user.wakeup_time.minute)
     local_time = pytz.utc.localize(proper_time).astimezone(tz).time()
     template_values = {
         'domain': WALRUS_DOMAIN,
         'user': user,
         'local_time': local_time
     }
     path = os.path.join(TEMPLATE_DIR, 'registration_success.html')
     self.response.out.write(template.render(path, template_values))
Esempio n. 4
0
    def post(self):
        """
        Register a user for wakeup calls
        """
        params = {
            'phone_number': None,
            'timezone': None,
            'wakeup_hour': None,
            'wakeup_minute': None
        }

        for k, v in params.items():
            params[k] = cgi.escape(self.request.get(k))

        if not params['phone_number']:
            params['error'] = 'you forgot to give us your number'
            return self.__render(params)

        # Create a user for the given details. Validation of phone numbers
        # will occur through twilio, at which point we'll set the user's
        # `validated` attribute to true
        tz = pytz.timezone(params['timezone'])
        user_time = datetime.datetime(1970, 1, 1, int(params['wakeup_hour']),
                                      int(params['wakeup_minute']))
        wakeup_time = tz.localize(user_time).astimezone(pytz.utc).time()
        user = User(
            **{
                'phone_number': params['phone_number'],
                'wakeup_time': wakeup_time,
                'timezone': params['timezone']
            })

        user.put()
        validation_call_url = "%s/twilio/validation?user_key=%s" % \
                              (WALRUS_DOMAIN, user.key())
        twilio_res = user.call(validation_call_url)
        if twilio_res:
            self.redirect("/confirm?user_id=%s" % user.key().id())
        else:
            params['error'] = 'that number is invalid'
Esempio n. 5
0
 def is_local_weekend(self):
     utc = pytz.utc
     tz = pytz.timezone(self.timezone)
     now = datetime.datetime.now()
     local_now = utc.localize(now).astimezone(tz)
     return local_now.isoweekday() in (6, 7)
Esempio n. 6
0
 def is_local_weekend(self):
     utc = pytz.utc
     tz = pytz.timezone(self.timezone)
     now = datetime.datetime.now()
     local_now = utc.localize(now).astimezone(tz)
     return local_now.isoweekday() in (6, 7)