Esempio n. 1
0
    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))
Esempio n. 2
0
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')
Esempio n. 3
0
 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'))
Esempio n. 4
0
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
Esempio n. 5
0
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()
Esempio n. 6
0
    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))
Esempio n. 7
0
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)
Esempio n. 8
0
 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é"
Esempio n. 9
0
    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()
Esempio n. 10
0
async def fetch_all_todos():
    todos = []
    cursor = collection.find({})
    async for doc in cursor:
        todos.append(Todo(**doc))

    return todos
Esempio n. 11
0
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
Esempio n. 12
0
 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()
Esempio n. 13
0
 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()
Esempio n. 14
0
    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()
Esempio n. 15
0
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)
Esempio n. 16
0
 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))
Esempio n. 17
0
def add_todo(text, complete):
    """ToDo item"""

    todo = Todo(text=text, complete=False)
    db.session.add(todo)
    db.session.commit()

    return todo
Esempio n. 18
0
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
Esempio n. 19
0
 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))
Esempio n. 20
0
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
Esempio n. 21
0
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!'})
Esempio n. 22
0
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()
Esempio n. 23
0
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)
Esempio n. 24
0
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)
Esempio n. 25
0
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()
Esempio n. 26
0
 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)
Esempio n. 27
0
 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)
Esempio n. 28
0
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
            })
Esempio n. 29
0
 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)
Esempio n. 30
0
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()
        )
Esempio n. 31
0
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)
Esempio n. 32
0
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)
Esempio n. 33
0
 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'))
Esempio n. 34
0
 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'))
Esempio n. 35
0
 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)
Esempio n. 36
0
def add(task: str, category: str):
    typer.echo(f"adding {task}, {category}")
    todo = Todo(task, category)
    insert_todo(todo)
    show()
Esempio n. 37
0
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()
Esempio n. 38
0
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()
Esempio n. 39
0
    def post(self):
        j = json.loads(self.request.body)
        key = Todo(**j).put()

        self.response.out.write(json.dumps({'id': key.id()}))
Esempio n. 40
0
    def delete(self, id_):
        todo = Todo.get_by_id(int(id_))
        if todo is None:
            return

        todo.key.delete()