def post(self): dao = UserDAO(self.db) cursor = yield (dao.create()) if not cursor.closed: self.write('closing cursor') cursor.close() self.finish()
def delete(self): dao = UserDAO(self.db) cursor = yield (dao.delete_table()) if not cursor.closed: self.write('closing cursor') cursor.close() self.finish()
def delete(self, id=None): if id: dao = UserDAO(self.db) result = yield (dao.delete(id)) self.write('user deleted') else: self.write('invalid user') self.finish()
def get(self, id=None): dao = UserDAO(self.db) if not id: dict_result = yield (dao.get_list()) else: dict_result = yield (dao.get(id)) self.write(json.dumps(dict_result)) self.finish()
def put(self, id=None): if not hasattr(self, 'json_args'): self.write('invalid request') self.finish() else: dao = UserDAO(self.db) if id: result = yield (dao.update(id, data=self.json_args)) dict_result = yield (dao.get(id)) self.write(json.dumps(dict_result)) else: self.write('invalid user') self.finish()
app.debug = True # if True Flash will reload the code on every change app.secret_key = "super_insecure_key" app.config["UPLOAD_FOLDER"] = os.path.join('/tmp') # Not permanent at Heroku!! app.config["MAX_CONTENT_LENGTH"] = 1024 * 1024 # = 1 Megabyte app.add_url_rule("/uploads/<filename>", "uploaded_file", build_only=True) # This lets us use the route /uploads although it does not phisically exist app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {"/uploads": app.config["UPLOAD_FOLDER"]}) # Register blueprints from project_api_endpoint.py and project_oauth.py app.register_blueprint(api_json) app.register_blueprint(api_atom) app.register_blueprint(oauth) # Instantiate our Data Access Objects usr_dao = UserDAO() rst_dao = RestaurantDAO() mnu_dao = MenuItemDAO() # Helper functions def is_logged(): """Returns True if and only if the user is logged.""" return "username" in login_session def is_owners_session(obj): """Returns True if and only if the user in session is the owner of obj. The owner of an object is the User pointed by the DB relaation.""" return is_logged() and obj.user_id == login_session["user_id"]
async def user_dao(): return UserDAO(AiopgTestService)