def __create_to_do_item(user): form = ToDoForm(request.form) if form.validate(): new_to_do = ToDo(title=form.title.data, description=form.description.data, pomodoro_length=form.pomodoro_length.data, break_length=form.break_length.data, long_break_length=form.long_break_length.data) new_to_do.author = user for i in range(form.num_pomodoros.data): new_pomodoro = Pomodoro(remaining_length=form.pomodoro_length.data) new_to_do.pomodoros.append(new_pomodoro) if new_to_do.save(): return jsonify(to_do = new_to_do, message = "To do created successfully!") else: return jsonify(error="Could not create to do item."), 401 else: return jsonify(errors=form.errors.items()), 400
def __create_to_do_item(user): form = ToDoForm(request.form) if form.validate(): new_to_do = ToDo(title=form.title.data, description=form.description.data, pomodoro_length=form.pomodoro_length.data, break_length=form.break_length.data, long_break_length=form.long_break_length.data) new_to_do.author = user for i in range(form.num_pomodoros.data): new_pomodoro = Pomodoro(remaining_length=form.pomodoro_length.data) new_to_do.pomodoros.append(new_pomodoro) if new_to_do.save(): return jsonify(to_do=new_to_do, message="To do created successfully!") else: return jsonify(error="Could not create to do item."), 401 else: return jsonify(errors=form.errors.items()), 400
def __fetch_to_do_items(user): to_dos = ToDo.objects(author=user) return jsonify(to_dos=to_dos)