def post(self):
     username = request.form['username']
     if 'user-type' in request.form:
         user_type = request.form['user-type']
     else:
         user = self.users.get(username)
         user_type = user['type']
     if 'email' in request.form:
         email = request.form['email']
         print('Creating new user [{}]', username)
         self.users.put(user_type, username, email)
     specialist = None if 'specialist' not in request.form else request.form['specialist']
     events = None
     booked_event = None
     if specialist != None:
         events = self.events.current_month(username, specialist)
         for event in events:
             if not Event.from_dict(event).is_free():
                 # the user looking at this page already has an appointment!
                 booked_event = event
     elif user_type == 'specialist':
         events = self.events.current_month(username, username)
     for event in events:
         event['nice_starttime'] = time.ctime(event['starttime'])
     return render_template('user_page.html',
             username = username, 
             specialist = specialist,
             user_type = user_type,
             events = events,
             booked_event = booked_event,
             message = None)
Пример #2
0
 def get_events(self, username, min_starttime, max_starttime):
     try:
         # ddb does between exclusively, so we need to bump out our bounds 
         min_starttime -= 1
         max_starttime += 1
         ddb_events = self.event_table.query(
                 KeyConditionExpression=Key('username').eq(username) & \
                         Key('starttime').between(min_starttime, max_starttime))['Items']
         return map(lambda ee: Event.from_dict(ee), ddb_events)
     except (NoVersionFound, ResourceLoadException, RetriesExceededError) as e:
         return None