def post(self, year, month, day): year, month, day = map(int, (year, month, day)) the_date = date(year, month, day) request_body = json.loads(self.request.body) if any(x not in request_body for x in ['hours', 'description']): self.set_status(400) self.write('400: Required parameter missing') return id = request_body.get('id', None) hours = request_body['hours'] description = request_body['description'] if id: log = WorkLog.get(id) if not log: self.set_status(400) self.write('400: No log with id %s' % id) return else: log = WorkLog() log.date = the_date log.hours = hours log.description = description log.save() for time_tracker in settings.time_trackers: try: time_tracker.log_hours(the_date, hours, description) except Exception as e: print "Unable to sync with time tracking service", e if id: self.set_status(201) # created
def serve(): handlers = [(r'/', MainHandler)] if hasattr(settings, 'favicon_path'): handlers.append((r'/(favicon.ico)', tornado.web.StaticFileHandler, {'path': settings.favicon_path})) handlers.append((r'/static/(.*)', tornado.web.StaticFileHandler, {'path': settings.static_path})) handlers.extend(api.GetRegisteredResources()) tornado_app = tornado.web.Application(handlers) from models import WorkLog from datetime import date log = WorkLog() log.date = date.today() log.hours = 5 log.description = "derp" log.save() log = WorkLog() log.date = date.today() log.hours = 6 log.description = "herp" log.save() server = tornado.httpserver.HTTPServer(tornado_app) server.listen(tornado.options.options.port) tornado.ioloop.IOLoop.instance().start()