def new(): form = CreateForm() if form.validate_on_submit(): todo = TodoModel(title=form.title.data, remarks=form.remarks.data) todo.save_to_db() return redirect(url_for('view.home')) return render_template('create.html', form=form)
def todo(): todo_form = Todo() if todo_form.validate_on_submit(): todo = TodoModel(content=todo_form.content.data) db.session.add(todo) db.session.commit() return redirect('/') return render_template('todo.html', form=todo_form)
def test_list(self): todoModel = TodoModel(title=self.TITLE, completed=self.IS_COMPLETED).put() todoApi = TodoApi() request = todoApi.TodosList.remote.request_type() todos_list = todoApi.TodosList(request).items self.assertEqual(1, len(todos_list)) result = todos_list[0] self.assertEquals(self.TITLE, result.title) self.assertEquals(self.IS_COMPLETED, result.completed)
def post(self): """POST /: Create a single todo""" self.response.headers = initialize_headers(self.response.headers, 'POST') # new_title = json.loads(self.request.body).get('title') new_todo = self.request.get('todoText') new_todo = TodoModel(todoText = new_todo) key = new_todo.put() message = json.dumps({'log': 'New Todo was successfully created', 'id': key.id()}) self.response.write(message)
def post(self, todo_id): args = task_post_args.parse_args() task = TodoModel.query.filter_by(id=todo_id).first() if task: abort(409, 'Task with this ID already taken!') todo = TodoModel(id=todo_id, task=args['task'], summary=args['summary']) db.session.add(todo) db.session.commit() return 201, todo
def todo(): if request.method == "GET": todos = {"todos": []} result = TodoModel.query.all() for todo in result: todos['todos'].append(todo.json()) print(jsonify(todos)) return todos elif request.method == "POST": post_body = request.form print(type(post_body)) print(post_body) todo = TodoModel(title=post_body.get('title'), description=post_body.get('description')) db.session.add(todo) db.session.commit() return redirect("/")
def put(self, todo_id: str): """ modify existing todo item""" req_data = self.parser.parse_args() try: todo = TodoModel.find_by_id(todo_id) if not todo: todo = TodoModel(**req_data, owner=get_jwt_identity()) else: todo.desc = req_data["desc"] todo.title = req_data["title"] todo.status = req_data["status"] todo.save_to_db() return {"success": True, "todo": todo.to_json()}, 200 except Exception as exception: logger.error( f"Exception occured when modifying a todo with params: {req_data}, {exception}", ) return {"sucess": False, "message": "internal_error"}, 500
def post(self): """ Create new todo item""" req_data = self.parser.parse_args() user_id = get_jwt_identity() new_todo = TodoModel(**req_data, owner=user_id) try: new_todo.save_to_db() except Exception as exception: logger.debug( f"Exception occured when creating a todo with params: {new_todo}, {exception}", ) return {"success": False, "message": "internal_error"}, 500 return { "success": True, "message": "todo created succesfully", "todo": new_todo.to_json(), }
def __init__(self): self.model = TodoModel()
def test_toggle(self): todoModel = TodoModel(title=self.TITLE).put() todoApi = TodoApi() request = todoApi.TodoToggle.remote.request_type() request.id = 1 todoApi.TodoToggle(request)
def create(): request_data = json.loads(request.data) todo = TodoModel(content=request_data['content']) db.session.add(todo) db.session.commit() return str({'201': 'todo created successfully'})