def insert_catergory(): user = validate_cookie(request) responseWrapper = ResponseWrapper() response = any_response(request) if user != None: category = Category() form_data = request.form['data'] json_data = json.loads(form_data) category.name = json_data['category_name'] result = categoryDAO.insert_category(category) if result != None: responseWrapper.set_error(False) responseWrapper.set_data(result) else: responseWrapper.set_error(True) responseWrapper.set_data(["error writing category"]) else: responseWrapper.set_error(True) responseWrapper.set_data(["User not found. Please login again"]) response.status_code = 302 response.data = json.dumps(responseWrapper, default=ResponseWrapper.__str__) response.mimetype = "application/json" return response
def get_categories(self): collection = self.categories results = collection.find() if results != None: category_list = [] for result in results: print result['name'] category = Category() obj_id = result["_id"] category.id = str(obj_id) category.name = result["name"] category_list.append(category) return category_list else: return None