コード例 #1
0
def index():
    # Define get_items variable to retrieve all items currently saved within the browser session
    # Reverse sort (alphabetic) the results by 'status' to get 'Not Started' before 'Completed'
    get_items = sorted(session.get_items(),
                       key=lambda item: item['status'],
                       reverse=True)
    # Return the rendered "index.html" template
    # Pass the value of get_items into the template as variable items (used by Jinja2)
    return render_template("index.html", items=get_items)
コード例 #2
0
def index():
    if request.method == 'POST':
        new_item = session.add_item(
            request.form['Title'])  ## Title is the name used in new.html
        ##      session._DEFAULT_ITEMS.append(new_item) #append to list instead calling session
        return redirect(url_for('index'))


### tried using PUT doesnt save input from form :(
    elif request.method == 'PUT':
        found_id = session.get_item(id)
        passed_id = request.form['Id']
        updated_status = request.form['Status_update']
        a = session.get_item(found_id)
        item = {'id': passed_id, 'status': updated_status, 'title': a['title']}
        update_item = session.save_item(item['id'])
        return redirect(url_for('index'))
    return render_template('index.html', Items=session.get_items())
コード例 #3
0
def index():
    if request.method == "POST":
        form_type = request.form.get('form_id')

        if form_type == 'add-item':
            title = request.form.get('title')
            if title:
                session.add_item(title)
            else:
                raise Error('Item title is required')

        elif form_type == 'update-item':
            id = request.form.get('item_id')
            if id:
                item = session.get_item(id)
                if item:
                    updated_status = 'Not Started' if item['status'] == 'Done' else 'Done'
                    updated_item = { 'id': item['id'], 'status': updated_status, 'title': item['title'] }
                    session.save_item(updated_item)
                else:
                    raise Error('No item found with id ' + id)
            else:
                raise Error('Item id is required')

        elif form_type == 'delete-item':
            id = request.form.get('item_id')

            if id:
                session.delete_item(id)
            else:
                raise Error('Item id is required')
        
        else:
            raise Error('Invalid request')

    items = session.get_items()
    return render_template('index.html', items=items)
コード例 #4
0
def index():
    items = session.get_items()
    session.add_item('Avi')
    return render_template("index.html", items=items)
コード例 #5
0
def create():
    items = session.get_items()
    session.add_item(request.form.get('item_title'))
    return render_template("index.html", items=items)
コード例 #6
0
def index():
    items = session.get_items()
    return render_template('index.html', items=items)
コード例 #7
0
ファイル: app.py プロジェクト: hbeard84/DevOps-Course-Starter
def index():
    items = session.get_items()
    return render_template("index.html", todos = items)