def testGet(self): todo1 = {'title': 'test1', 'order': 1, 'completed': False} key = Todo(**todo1).put() todo1['id'] = key.id() request = webapp2.Request.blank('/api/todos') response = request.get_response(main.app) self.assertEqual([todo1], json.loads(response.body))
def registration_form(): """Allow users to register, only their email and pw is required. """ if request.method == 'GET': return render_template("/users/register.html") else: user_email = request.form.get("email") pw = request.form.get("pw") fname = request.form.get("fname") lname = request.form.get("lname") zipcode = request.form.get("zipcode") picture = request.form.get("picture") linkedin = request.form.get("linkedin") role = request.form.get("role") new_user = User(email=user_email, pw=pw, fname=fname, lname=lname, zipcode=zipcode, linkedin=linkedin, role=role, picture=picture) db.session.add(new_user) db.session.commit() # session['user_id'] = request.form['user_id'] session['user_id'] = new_user.user_id # add preset todo items for user user_id = session['user_id'] # datetime for todo date now = datetime.now() anp = "Add First Project" anc = "Add First Crewmember" phref = "/projects" chref = "/crew" add_new_project = Todo(user_id=new_user.user_id, task_name=anp, task_date=now, task_completion=False, task_link=phref) add_new_crewmember = Todo(user_id=new_user.user_id, task_name=anc, task_date=now, task_completion=False, task_link=chref) db.session.add(add_new_project) db.session.commit() db.session.add(add_new_crewmember) db.session.commit() return redirect('/dashboard')
def post(self): form = CreateTodoForm() if form.validate_on_submit(): data = get_dict(request.form, 'topic', 'start', 'end', 'desc') todo = Todo(**data) todo.poster = ObjectId(session["user_id"]) try: todo.save() except: return redirect(url_for('todo.create')) return redirect(url_for('todo.list'))
def post_todo(): myform = form.CreateTodoForm(request.form) if not myform.validate(): abort(400, myform.errors) name = request.form['name'] if service.get_by_name(name) is None: created_date = datetime.datetime.now() newtodo = Todo(None, name, False, created_date, None) service.add(newtodo) return jsonify(newtodo.json()), 201 return "Post failed because todo name already exists", 400
def example_data(): Entry.query.delete() Todo.query.delete() User.query.delete() #users brighticorn = User( name='Brighticorn', user_id=1, email='*****@*****.**', password= '******', zipcode='94566') pairprogrammer = User( name='PairProgrammer', user_id=2, email='*****@*****.**', password= '******', zipcode='94588') #entries be1 = Entry(user_id=1, date='2018-10-3', title='Entry Title', text='Entry body text', quote='Some random quote for the day', weather='Sunny') be2 = Entry(user_id=1, date='2018-10-4', title='Another Title', text='Some text to go in entry body', quote='another quote', weather='Cloudy') pe1 = Entry(user_id=2, date='2018-10-3', title='Testing same date', text='Enrty body for testing same date', quote='some quote', weather='Snowy') pe2 = Entry(user_id=2, date='2018-10-16', title='Test Title', text='Some text for an entry body', quote='daily quote', weather='Sunny') #todo bt1 = Todo(user_id=1, todo_id=1, todo='wash dishes') bt2 = Todo(user_id=1, todo_id=2, todo='laundry') pt1 = Todo(user_id=2, todo_id=3, todo='sweep/mop') db.session.add_all( [brighticorn, pairprogrammer, be1, be2, pe1, pe2, bt1, bt2, pt1]) db.session.commit()
def testGet(self): todo1 = { 'title': 'test1', 'order': 1, 'completed': False } key = Todo(**todo1).put() todo1['id'] = key.id() request = webapp2.Request.blank('/api/todos') response = request.get_response(main.app) self.assertEqual([todo1], json.loads(response.body))
def todos_page(): if request.method == "POST": todo_id = request.form.get("todo_id", "") title = request.form.get("title", "") details = request.form.get("details", "") method = request.form.get("_method", "") if method == "PATCH": process_patch_request() else: Todo.add_todo(_id=todo_id, _title=title, _details=details) return redirect(url_for("todos_page")) todos = Todo.get_all_todos() return render_template("index.html", todos=todos)
def add(self, sender, liste, msg): if liste == "all": return "On ne peut pas nommer une liste 'all'" todo = Todo(liste, msg, sender, time.time()) self.bot.session.add(todo) self.bot.session.commit() return "TODO ajouté"
def put(self, id_): todo = Todo.get_by_id(int(id_)) j = json.loads(self.request.body) for k, v in j.iteritems(): setattr(todo, k, v) todo.put()
async def fetch_all_todos(): todos = [] cursor = collection.find({}) async for doc in cursor: todos.append(Todo(**doc)) return todos
def get_all_todos() -> List[Todo]: c.execute('select * from todos') results = c.fetchall() todos = [] for result in results: todos.append(Todo(*result)) return todos
def createTodo(self, payload): auth = sec.context.get_auth() newTodo = Todo( title=payload.get("title"), description=payload.get("description"), createdBy=auth.user_id ) try: newTodo.save() except ValidationError as error: errorMessage = { "msg": str(error) } return json.dumps(errorMessage) return newTodo.to_json()
def setUp(self): """ Creates a random todo we add manually to the database """ todo_list = string_gen(8) todo_msg = string_gen(50) self.todo = Todo(todo_list, todo_msg, "sender", time.time()) self.bot.session.add(self.todo) self.bot.session.commit()
def find_todo(username): to_list = [] sql = 'select * from todo where username="******"'.format(username) cur = db.cursor() cur.execute(sql) data = cur.fetchall() for item in data: if item is None: continue to_list.append(Todo(*item)) return to_list if data is None: return data return Todo(*data)
def get(self): todos = [] for todo in Todo.query(): d = todo.to_dict() d['id'] = todo.key.id() todos.append(d) self.response.headers['Content-Type'] = 'application/json; charset=utf-8' self.response.out.write(json.dumps(todos))
def add_todo(text, complete): """ToDo item""" todo = Todo(text=text, complete=False) db.session.add(todo) db.session.commit() return todo
def update_todo(): """Add todo item to database""" todo = request.form.get("todo") finduser = User.query.filter_by(email=session["email"]).first() new_todo = Todo(user_id=finduser.user_id, todo=todo) db.session.add(new_todo) db.session.commit() return todo
def get(self): todos = [] for todo in Todo.query(): d = todo.to_dict() d['id'] = todo.key.id() todos.append(d) self.response.headers[ 'Content-Type'] = 'application/json; charset=utf-8' self.response.out.write(json.dumps(todos))
def slack_todos(): res = request.form['text'].split(' ') cmd, *args = res ret_msg = '' if cmd == 'create': todo_name = args[0] todo = Todo() todo.title = todo_name db.session.add(todo) db.session.commit() ret_msg = 'todo created' elif cmd == 'list': pass return ret_msg
def create_todo(current_user): data = request.get_json() new_todo = Todo(text=data['text'], complete=False, user_id=current_user.id) db.session.add(new_todo) db.session.commit() return jsonify({'message': 'Todo created!'})
def load_todo(): """Load todo list into database.""" autotask = ["Add First Project", "Add First Crewmember"] task_date = datetime.now() for i in autotask: new_todo = Todo(task_name=i, task_date=task_date) db.session.add(new_todo) db.session.commit()
def todo(id=None): """ Provide: - /api/todo/ POST and GET routes GET is without arguments POST require at least a title, also accept a description """ if request.method == 'POST': print request.json if not request.json or not 'title' in request.json: abort(400) todo = Todo(request.json['title'], request.json.get('content', "")) db_session.add(todo) db_session.commit() todo.users = [g.user] db_session.commit() return jsonify(ok=todo.serealize) elif request.method == 'GET': return jsonify(todos=[item.serealize for item in g.user.todos]) else: abort(400)
def index(): if request.method == "POST": task_content = request.form['content'] new_task = Todo(content=task_content) db.add(new_task) db.commit() return redirect("/") else: tasks = db.query(Todo).all() return render_template("index.html", tasks=tasks)
def load_todos(): """Load todos from todo.item into database.""" print("Todos") for row in open("seed_data/todo.item"): row = row.rstrip() todo_id, user_id, todo = row.split("|") todo = Todo(todo_id = todo_id, user_id = user_id, todo = todo) db.session.add(todo) db.session.commit()
def post(self, edit_id): done = self.request.get("done") task = Todo().get_by_id(int(edit_id)) task.task = self.request.get("task") if done == "1": task.done = True else: task.done = False task.put() params = {"task": task} return self.render_template("edit.html", params)
def setUp(self): """ Creates 3 random todo we add manually to the database """ self.todos = [] todos = { string_gen(8): string_gen(50), string_gen(8): string_gen(50), string_gen(8): string_gen(50) } for list_name, todo in todos.iteritems(): todo = Todo(list_name, todo, "sender", time.time()) self.bot.session.add(todo) self.bot.session.commit() self.todos.append(todo)
def insert_todo(todo: Todo): c.execute('select count(*) FROM todos') count = c.fetchone()[0] todo.position = count if count else 0 with conn: c.execute( 'INSERT INTO todos VALUES (:task, :category, :date_added, :date_completed, :status, :position)', { 'task': todo.task, 'category': todo.category, 'date_added': todo.date_added, 'date_completed': todo.date_completed, 'status': todo.status, 'position': todo.position })
def print_template(self): user = users.get_current_user() if user: is_user = True user_url = users.create_logout_url('/') else: is_user = False user_url = users.create_login_url('/') tasks = Todo().query().fetch() params = { "tasks": tasks, "user": user, "is_user": is_user, "user_url": user_url } return self.render_template("hello.html", params)
def new(): if request.method == 'POST': category = Category.query.filter_by( id=request.form['category']).first() #priority = Priority.query.filter_by(id=request.form['priority']).first() #todo = Todo(category=category, priority=priority, description=request.form['description']) todo = Todo(category=category, description=request.form['description']) db.session.add(todo) db.session.commit() return redirect(url_for('list_all')) else: return render_template( 'new-task.html', page='new-task', categories=Category.query.all(), #priorities=Priority.query.all() )
def todos_delete(todo_id): Todo.delete_todo_by_id(_id=todo_id) todos = Todo.get_all_todos() return render_template("index.html", todos=todos)
def process_patch_request(): todo_id = request.form.get("todo_id_edit", "") title = request.form.get("todo_title_edit", "") details = request.form.get("todo_details_edit", "") Todo.update_todo(_id=todo_id, _title=title, _details=details)
def get(self): return render_template('todo/list.html', todos = Todo.objects(done=None, poster=ObjectId(session["user_id"])).order_by('end'), dones=Todo.objects(done=True, poster=ObjectId(session["user_id"])).order_by('end'))
def get(self, obj_id): try: Todo.objects(id=obj_id).delete() except: redirect(url_for('todo.list', message=u'Delete Fail!!!')) return redirect(url_for('todo.list'))
def get(self, condition): try: todos = Todo.objects(topic__contains=condition) except: return redirect(url_for('todo.list', error='Search Fail!')) return render_template('todo/search_result.html', todos=todos)
def add(task: str, category: str): typer.echo(f"adding {task}, {category}") todo = Todo(task, category) insert_todo(todo) show()
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from model import Todo, Base, User from DAL import dal dal.connect() session = dal.Session() # Insert a User in the User table new_user = User(name='sksun') session.add(new_user) session.commit() # Insert an Todo in the Todo table new_todo = Todo(text='Another todo by sksun from sql-alchemy', isdone=False, user=user) session.add(new_todo) session.commit()
def add_todo_item(parent_username, item_title, item_urgency): new_item = Todo(parent_username=parent_username, item_title=item_title, item_urgency=item_urgency) session1.add(new_item) session1.commit()
def post(self): j = json.loads(self.request.body) key = Todo(**j).put() self.response.out.write(json.dumps({'id': key.id()}))
def delete(self, id_): todo = Todo.get_by_id(int(id_)) if todo is None: return todo.key.delete()