def todos(): if request.method == "POST": title = str(request.data.get('title', '')) description = str(request.data.get('description', '')) if title and description: todo = Todo(title=title, description=description) todo.save() response = jsonify({ 'id': todo.id, 'title': todo.title, 'description': todo.description, 'date_created': todo.date_created, 'date_updated': todo.date_updated, 'done_status': todo.done_status }) response.status_code = 201 return response else: # GET todos = Todo.get_all() results = [] for todo in todos: obj = { 'id': todo.id, 'title': todo.title, 'description': todo.description, 'done_status': todo.done_status, 'date_created': todo.date_created, 'date_updated': todo.date_updated } results.append(obj) response = jsonify(results) response.status_code = 200 return response
def create(record_name="First_Record"): new_record = Todo() new_record.content = record_name db.session.add(new_record) db.session.commit() # print(request.method) return jsonify({"result": True})
def add(): #不带验证的版本 #form = request.form #content = form['content'] #todo = Todo(content=content) #todo.save() #带验证的版本 #form = TodoForm(request.form) #if form.validate(): # content = form.content.data # todo = Todo(content=content, time=datetime.now()) # todo.save() #todos = Todo.objects.order_by('-time') #return render_template('index.html', todos=todos,form=form) #react的版本 form = request.form content = form.get('content') finishtime = form.get('finishtime') classification = form.get('classification') todo = Todo(content=content, time=datetime.strftime(datetime.now(), '%d-%m-%Y %H:%M:%S'), finishtime=finishtime, classification=classification) todo.save() return jsonify(status="success")
def add(): form = request.form content = form.get('content') todo = Todo( content=content,time=datetime.now()) todo.save() return jsonify( status = "success")
def add(): form = TodoForm(request.form) if form.validate(): content = request.form.get("content") todo = Todo(content=content) todo.save() todos = Todo.objects.all() return render_template("index.html", todos=todos, form=form)
def test_delete_todo(self): todolist = TodoList(self.shopping_list_title).save() todo = Todo('A book about TDD', todolist.id).save() self.assertEqual(todolist.count_todos(), 1) todo_id = todo.id todo.delete() self.assertIsNone(Todo.query.get(todo_id)) self.assertEqual(todolist.count_todos(), 0)
def add(): form = TodoForm(request.form) if form.validate(): content = request.form.get("content") todo = Todo(content=content) todo.save() todos = Todo.objects.all() return render_template('index.html', todos=todos, form=form)
def add(): form = TodoForm(request.form) if form.validate(): content = form.content.data todo = Todo(content=content, time=datetime.now()) todo.save() todos = Todo.objects.order_by('-time') return render_template('index.html', todos=todos, form=form)
def test_api_delete_todo(client, headers, todo): response = client.delete(url_for('TodoView:delete', todo_id=todo.id), data={}, headers=headers) assert response.status_code == 200 with pytest.raises(ModelNotFound): Todo.find_or_fail(todo.id)
def add(): form = TodoForm(request.form) if form.validate(): content = form.content.data todo = Todo(content=content, time=datetime.now()) todo.save() todos = Todo.objects.order_by('-time') return render_template("index.html", todos=todos, form=form)
def test_update(self): todo = Todo(title='test', complete=False) self.session.add(todo) todo.complete = True self.session.add(todo) result = Todo.query.filter_by(title='test').first() self.assertEqual(result.title, 'test') self.assertTrue(result.complete)
def test_delete_todo(self): todolist = TodoList(self.shopping_list_title).save() todo = Todo("A book about TDD", todolist.id).save() self.assertEqual(todolist.todo_count, 1) todo_id = todo.id todo.delete() self.assertIsNone(Todo.query.get(todo_id)) self.assertEqual(todolist.todo_count, 0)
def add_todolist_todo(todolist_id): todolist = TodoList.query.get_or_404(todolist_id) try: todo = Todo(description=request.json.get('description'), todolist_id=todolist.id).save() except: abort(400) return jsonify(todo.to_dict()), 201
def add(): # form = TodoForm(request.form) form = TodoForm() if form.validate_on_submit(): todo = Todo(content=form.content.data) todo.save() todos = Todo.query.order_by(desc(Todo.time)).all() return render_template('index.html', todos=todos, form=form)
def add(): form = TodoForm(request.form) if form.validate(): content = form.content.data todo = Todo(content=content) todo.save() todos = Todo.objects.order_by('-time') return redirect(url_for(".index"))
def test_add_todos(): new_todo1 = Todo(name="test1", priority=1) new_todo2 = Todo(name="test2", priority=2) new_todo3 = Todo(name="test3", priority=5) add_todo(new_todo1) add_todo(new_todo2) add_todo(new_todo3) assert len(DATABASE) == 3 assert DATABASE[1].name == "test1"
def add_todo(): for x in range(100): todo = Todo() todo.todo_desc = "test plan--" + str(x) + str(x) + str(x) todo.todo_status = random.randint(0, 1) todo.todo_type = random.randint(1, 3) todo.todo_date = date(2015, random.randint(1, 12), random.randint(1, 27)) db.session.add(todo) db.session.commit()
def create_todo(): a1 = Course(title='Mathematics') b1 = Todo(description='Finish math homework', course=a1) db.session.add(b1) a2 = Course(title='English') b2 = Todo(description='write essay', course=a2) db.session.add(b2) db.session.commit()
def alter_todo(): if (guild_id := request.json.get('guild_id')) is not None: member = User.query.get(get_internal_id()) if guild_id in [x.id for x in member.permitted_guilds()]: if request.method == 'POST': if (channel_id := request.json.get('channel_id')) is not None and \ (value := request.json.get('value')) is not None and \ 0 < len(value) <= 2000: if channel_id == -1: todo = Todo(guild_id=guild_id, channel_id=None, user_id=member.id, value=value) db.session.add(todo) db.session.commit() return jsonify({'id': todo.id}) else: guild = Guild.query.get(guild_id) if guild.channels.filter( Channel.id == channel_id).first() is not None: todo = Todo(guild_id=guild_id, channel_id=channel_id, user_id=member.id, value=value) db.session.add(todo) db.session.commit() return jsonify({'id': todo.id}) else: abort(404) else: abort(400) elif request.method == 'DELETE': if (channel_id := request.json.get('channel_id')) is not None and \ (todo_id := request.json.get('todo_id')) is not None: if channel_id == -1: channel_id = None Todo.query \ .filter(Todo.id == todo_id) \ .filter(Todo.channel_id == channel_id) \ .filter(Todo.guild_id == guild_id) \ .delete(synchronize_session='fetch')
def add(): form = AddTodoForm(request.form) if request.method == 'POST' and form.validate(): todo = Todo(content=form.content.data, time=form.time.data, status=form.status.data) todo.save() flash('success') return redirect('/') return render_template('add.html', form=form)
def post(self): """ Create new todo """ data = parser.parse_args() slug = slugify(data['name']) todo = Todo(data['name'], data['description'], slug) try: todo.save() except: return {'message': 'A problem occured creating todo item'}, 500 return {'message': 'Todo item successfully created'}, 202
def add(): form = TodoForm(request.form) # content = request.form['content'] if request.method == 'POST' and form.validate(): content = form.content.data todo = Todo(content) todo.add() return redirect(url_for('index')) todos = Todo.query.order_by('-time') return render_template('index.html', todos=todos, form=form)
def home(request): form = TodoForm() todos = Todo.objects.all() if request.is_ajax() and request.POST: text = request.POST.get('comment') todo = Todo(text=text) todo.save() data = {'message': request.POST.get('comment')} return HttpResponse(json.dumps(data), content_type='application/json') return render(request, 'app/index.html',{'todos': todos, 'form': form})
def add(): form = TodoForm(request.form) if form.validate(): content = form.content.data todo = Todo(content=content) todo.save() return redirect(url_for("index", forms=form)) else: todos = Todo.objects.all() return render_template("index.html", todos=todos, forms=form)
def add_user_todolist_todo(username, todolist_id): user = User.query.filter_by(username=username).first_or_404() todolist = TodoList.query.get_or_404(todolist_id) try: todo = Todo(description=request.json.get('description'), todolist_id=todolist.id, creator=user.username).save() except: abort(400) return jsonify(todo.to_dict()), 201
def todo_add_from_plan(): json_data = request.get_json() todo_desc = json_data.get('todo_desc') if todo_desc is not None: _todo = Todo() _todo.todo_desc = todo_desc _todo.todo_type = Todo.TYPE_PLAN db.session.add(_todo) db.session.commit() return jsonify(success=True) return jsonify(success=False)
def add(): form = AddForm(request.form) if form.validate(): data = form.todo.data todo = Todo(data) todo.add() else: for error in form.todo.errors: flash(error) #todos = Todo.query.all() return redirect(url_for('index'))
def add_todo(): a1 = Course(title='Drafting') b1 = Todo( description='start blueprints', course=a1 ) db.session.add(b1) a2 = Course(title='Python') b2 = Todo(description='practice', todo=a2) db.session.add(b2) db.session.commit()
def generate_fake_todo(self, count): # for the todolist relation we need todolists todolists = TodoList.query.all() assert todolists != [] for _ in range(count): todolist = random.choice(todolists) todo = Todo(description=forgery_py.forgery.lorem_ipsum.words(), todolist_id=todolist.id, creator=todolist.creator, created_at=self.generate_fake_date()).save() if random.choice([True, False]): todo.finished()
def add(): # form = request.form # content = form.get('content') # todo = Todo(content=content) # todo.save() # todos = Todo.objects.all() form = TodoForm(request.form) if form.validate(): content = form.content.data todo = Todo(content=content) todo.save() todos = Todo.objects.order_by('-time') return render_template('index.html', todos=todos, form=form)
def new(): if request.method == 'POST': if not request.form['title']: flash('Title is required', 'error') elif not request.form['text']: flash('Text is required', 'error') else: todo = Todo(request.form['title'], request.form['text']) todo.user = g.user db.session.add(todo) db.session.commit() flash('Todo item was successfully created') return redirect(url_for('index')) return render_template('new.html')
def add(): title = request.form.get("title") descript = request.form.get("descript") if Todo.query.filter_by(title=title).first() is None: new_todo = Todo(title=title, complete=False, descript=descript) db.session.add(new_todo) db.session.commit() return redirect(url_for("home")) elif Todo.query.filter_by(title=title).first().title == title: return redirect(url_for("home")) else: new_todo = Todo(title=title, complete=False, descript=descript) db.session.add(new_todo) db.session.commit() return redirect(url_for("home"))
def setUp(self): self.app = create_app(TestingConfig) self.client = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.user1 = User(username='******', password='******') self.user2 = User(username='******', password='******') self.todo1 = Todo(text='Finish homework') self.todo2 = Todo(text='Exercise') self.user1.todos.extend([self.todo1, self.todo2]) self.user2.todos.append((Todo(text='Mow lawn'))) db.session.add_all([self.user1, self.user2]) db.session.commit() self.token = self.user1.generate_jwt()
def test_add_duplicated_todo(): new_todo1 = Todo(name="test1", priority=1) try: add_todo(new_todo1) assert False except Exception: assert True
def new_todolist(): form = TodoForm(todo=request.form.get("todo")) if form.validate(): todolist = TodoList(creator=_get_user()).save() Todo(form.todo.data, todolist.id).save() return redirect(url_for("main.todolist", id=todolist.id)) return redirect(url_for("main.index"))
def delete(self, slug): """ Delete a todo item """ todo = Todo.get_by_slug(slug) if todo: todo.delete() return {'message', 'Todo item successfully removed'}, 200 return {'message': 'Todo item not found'}, 404
def todolist(id): todolist = TodoList.query.filter_by(id=id).first_or_404() form = TodoForm() if form.validate_on_submit(): Todo(form.todo.data, todolist.id, _get_user()).save() return redirect(url_for("main.todolist", id=id)) return render_template("todolist.html", todolist=todolist, form=form)
def queryPies(todo_date): date = todo_date.split('-') year = date[0] month = int(date[1]) datas=[ ['工作',0], ['人情',0], { 'name': '娱乐', 'y':0, 'sliced': 'true', 'selected': 'true' }, ['教育',0], ['日杂',0], ] data_count=[0,0,0,0,0] sum=0 search = { 'time': re.compile(year) } todos = Todo.objects(**search) for todo in todos: date = todo.time date_split = date.split('-') todo_month = int(date_split[1]) if(todo_month==month and todo.classification=="工作"): data_count[0] = data_count[0]+1 elif(todo_month==month and todo.classification=="人情"): data_count[1] = data_count[1]+1 elif (todo_month == month and todo.classification == "娱乐"): data_count[2] = data_count[2]+1 elif (todo_month == month and todo.classification == "教育"): data_count[3] = data_count[3]+1 elif (todo_month == month and todo.classification == "日杂"): data_count[4] = data_count[4]+1 for i in range(5): sum = sum+data_count[i] if(sum!=0): datas[0][1] = data_count[0]/sum datas[1][1] = data_count[1]/sum datas[2]['y'] = data_count[2]/sum datas[3][1] = data_count[3]/sum datas[4][1] = data_count[4]/sum return jsonify(status="success", data=datas)
def queryBars(todo_date): search = { 'time': re.compile(todo_date) } todos = Todo.objects(**search) dones=[] undones=[] for i in range(1,13): count_done = 0 count_undone = 0 for todo in todos: date = todo.time date_split = date.split('-') month = int(date_split[1]) if(month==i and todo.status==1): count_done = count_done+1 elif(month==i and todo.status==0): count_undone = count_undone+1 dones.append(count_done) undones.append(count_undone) count_done = 0 count_undone = 0 return jsonify(status="success", done=dones, undone=undones)
def save(): todo=Todo(content='study flask') todo.save()
def save(): todo = Todo(content="Study Flask") todo.save()
def save_todo(): todo = Todo(content='my first todo') todo.save()
def save_todo(twits): todo = Todo(content=twits) todo.save()
def save_todo(): todo = Todo(content="my first todo") todo.save()
def save(): todo = Todo(content='Hello anthony', status=1) todo.save()
def save(): todo = Todo(content = 'kobebryant') todo.save()
def save(): todo = Todo(content="first pro") todo.save()
def test_delete_todo(self): todo = Todo(content='test delete done') todo.save() url = '/delete/'+str(todo.id) rv = self.app.get(url) assert "No todos, please add" in rv.data
def test_undone_todo(self): todo = Todo(content='test undone todo') todo.save() url = '/undone/'+str(todo.id) rv = self.app.get(url) assert '/done/'+str(todo.id) in rv.data
def query(todo_content): search = { 'content':re.compile(todo_content) } todos = Todo.objects(**search).order_by('-time') return jsonify(status="success", todos=[todo.to_json() for todo in todos])
def save_todo(): todo = Todo(content='my 5 todo') todo.save()
def save(): todo = Todo(content="study mistake") todo.save()
def save(): todo = Todo(content="study flask") todo.save()