예제 #1
0
def todo_save():
    """
    Saves the edited item into the database and redirects to main list for validated users
    Produces error message for anon or invalid users
    """
    edit = bottle.request.forms.get('task', '').strip()
    status = bottle.request.forms.get('status', '').strip()
    num = bottle.request.forms.get('num', '').strip()
    if status == 'open':
        status = 1
    else:
        status = 0
    #verify user
    session = sign_up.get_session()
    email = session['email']
    user_info = manage_users.get_info_from_db(email)
    if user_info:
        db.tasks.update({'_id': int(num)},
                        {'$set': {
                            'task': edit,
                            'status': status
                        }})
        return bottle.redirect('/todo')
    else:
        cur_task = db.tasks.find_one({'_id': int(num)})
        return bottle.template(
            'edit_task',
            old=cur_task,
            num=num,
            error_msg=
            "Sorry you cannot add tasks because you are not signed in as a user or because of a cookie error"
        )
예제 #2
0
def save_new_item():
    """
    Saves the new item into the database and redirects to main list for validated users
    Produces error message for anon or invalid users
    """
    new = bottle.request.forms.get('task', '').strip()
    new_id = db.tasks.count() + 1
    #verify user
    session = sign_up.get_session()
    email = session['email']
    user_info = manage_users.get_info_from_db(email)
    if user_info:
        db.tasks.insert({
            "_id": new_id,
            "task": new,
            "status": 1,
            "username": user_info['username']
        })
        if 'food' in user_info:
            db.tasks.update({"_id": new_id},
                            {"$set": {
                                "food": user_info['food']
                            }})
        return bottle.redirect('/todo')
    else:
        return bottle.template(
            'new_task',
            error_msg=
            "Sorry you cannot add tasks because you are not signed in as a user or because of a cookie error"
        )
예제 #3
0
파일: todo.py 프로젝트: alysonla/bottletodo
def save_new_item():
    """
    Saves the new item into the database and redirects to main list for validated users
    Produces error message for anon or invalid users
    """
    new = bottle.request.forms.get('task', '').strip()
    new_id = db.tasks.count() + 1
    #verify user
    session = sign_up.get_session()
    email = session['email']
    user_info = manage_users.get_info_from_db(email)
    if user_info:
        db.tasks.insert({"_id": new_id, "task": new, "status": 1, "username": user_info['username']})
        if 'food' in user_info:
            db.tasks.update({"_id": new_id}, {"$set": {"food": user_info['food']}})
        return bottle.redirect('/todo')
    else:
        return bottle.template('new_task',
                error_msg = "Sorry you cannot add tasks because you are not signed in as a user or because of a cookie error")
예제 #4
0
파일: todo.py 프로젝트: alysonla/bottletodo
def todo_save():
    """
    Saves the edited item into the database and redirects to main list for validated users
    Produces error message for anon or invalid users
    """
    edit = bottle.request.forms.get('task','').strip()
    status = bottle.request.forms.get('status','').strip()
    num = bottle.request.forms.get('num','').strip()
    if status == 'open':
        status = 1
    else:
        status = 0
    #verify user
    session = sign_up.get_session()
    email = session['email']
    user_info = manage_users.get_info_from_db(email)
    if user_info:
        db.tasks.update({'_id': int(num)}, {'$set':
            {'task': edit, 'status': status}})
        return bottle.redirect('/todo')
    else:
        cur_task = db.tasks.find_one({'_id': int(num)})
        return bottle.template('edit_task', old=cur_task,
                num=num, error_msg="Sorry you cannot add tasks because you are not signed in as a user or because of a cookie error")