예제 #1
0
def create_mysql(event, context):
    data = json.loads(event['body'])
    timestamp = sqlalchemy.sql.func.now()

    newTodo = Todo(id=str(uuid.uuid1()),
                   firstName=data['firstName'],
                   lastName=data['lastName'],
                   email=data['email'],
                   comments=data['comments'],
                   options=data['options'],
                   checked=False,
                   createdAt=timestamp,
                   updatedAt=timestamp)
    session = get_session()
    session.add(newTodo)
    session.commit()

    # create a response
    response = {
        "statusCode": 200,
        "body": json.dumps(newTodo, cls=AlchemyEncoder),
        "headers": {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Credentials": "true"
        }
    }

    return response
예제 #2
0
def add_todos():
    for td in get_todos():
        logger.success("Задание: {}, для пользователя с id:{}", td["title"], td["userId"])
        todo = Todo(
            user_id=td["userId"],
            title=td["title"],
            completed=td["completed"],
        )
        s.add(todo)
        s.commit()
    s.close()
예제 #3
0
def todos_POST():
    if not session.get('logged_in'):
        return redirect('/login')

    user = User.query.get(session['user'])
    description = request.form.get('description')
    if len(description) > 0:
        todo = Todo(user=user, description=description, completed=0)
        db.session.add(todo)
        db.session.commit()
    else:
        flash('You must provide a description')

    flash('Todo inserted')
    return redirect('/todo')
예제 #4
0
def add_todo():
    if request.form["action"] == "Add":
        print("adding")
        date = datetime.datetime.strptime(request.form["date"], "%d/%m %H:%M")
        date = date.replace(year=datetime.datetime.now().year)
        todo = Todo(text=request.form["text"], date_=date)
        session.add(todo)
        session.commit()
    if request.form["action"] == "Delete":
        print("deleting")
        todo = session.query(Todo).filter_by(
            id=request.form["todo_id"]).first()
        if todo:
            session.delete(todo)
            session.commit()

    return get_index()
예제 #5
0
async def create_todo(todo_in: TodoIn, db: Session = Depends(get_db)):
    todo = Todo(title=todo_in.title, done=False)
    db.add(todo)
    db.commit()
    todo = get_todo(db, todo.id)
    return todo