Exemple #1
0
def get_books_in_category(id):
    books = session.query(Book).all()
    # for -> loop all books
    # filter book which has the same category id
    # make them as json
    data = [book.serialize for book in books if book.category == id]
    return jsonify(data)
def deleteItem(category, item):
    # First we make sure we are loged in
    if 'username' not in login_session:
        return redirect('/login')
    # Then we delete
    itemToDelete = session.query(Items).filter_by(name=item).one()
    if request.method == 'POST':
        session.delete(itemToDelete)
        session.commit()
        flash("Item deleted!")
        return redirect(url_for('catalog'))
    else:
        return render_template('delete.html', category=category, item=item)
def editItem(category, item):
    # First we make sure we are loged in
    if 'username' not in login_session:
        return redirect('/login')
    categories = session.query(Categories)
    items = session.query(Items)
    editedItem = session.query(Items).filter_by(name=item).one()
    # Process the request and make sure everything is there then we update
    if request.method == 'POST':
        if request.form['name']:
            editedItem.name = request.form['name']
        if request.form['description']:
            editedItem.description = request.form['description']
        if request.form['price']:
            editedItem.price = request.form['price']
        if request.form['category']:
            editedItem.category = request.form['category']
        session.add(editedItem)
        session.commit()
        flash("Item edited!")
        return redirect(url_for('catalog'))
    else:
        return render_template('edit.html', categories=categories, category=category, item=item, items=items)
def newItem():
    # First we make sure we are loged in
    if 'username' not in login_session:
        return redirect('/login')
    # Then we process the request, creating and item
    categories = session.query(Categories)
    if request.method == 'POST':
        new = Items(name=request.form['name'], description=request.form[
                    'description'], price=request.form['price'], category=request.form['category'])
        session.add(new)
        session.commit()
        flash("New item created!")
        # Go back to main page and notify user
        return redirect(url_for('catalog'))
    else:
        # Display form
        return render_template('new.html', categories=categories)
Exemple #5
0
def all_logs():
    readings = session.query(Reading).all()
    for r in readings:
        print "CPU: " + str(r.reading) + ", stamp: " + str(r.stamp)
def categoryItem(category, item):
    items = session.query(Items)
    return render_template('item.html', item=item, items=items)
def catalogCategory(category):
    categories = session.query(Categories)
    items = session.query(Items)
    return render_template('category.html', categories=categories, category=category, items=items)
def categoryItemJSON(category, item):
    items = session.query(Items).filter_by(name=item)
    return jsonify(Items=[i.serialize for i in items])
def catalogCategoryJSON(category):
    items = session.query(Items).filter_by(category=category).all()
    return jsonify(Items=[i.serialize for i in items])
def catalogJSON():
    categories = session.query(Categories)
    items = session.query(Items)
    return jsonify(Categories=[c.serialize for c in categories], Items=[i.serialize for i in items])
Exemple #11
0
def get_categories():
    categories = session.query(Category).all()
    data = [i.serialize for i in categories]
    return jsonify(data)
Exemple #12
0
def get_books_by_id(id):
    books = session.query(Book).get(id)
    return jsonify(books.serialize)
Exemple #13
0
def get_category_by_id(id):
    category = session.query(Category).get(id)
    # this generates json file
    return jsonify(category.serialize)
Exemple #14
0
def get_books():
    books = session.query(Book).all()
    data = [i.serialize for i in books]
    # this generate the json file
    return jsonify(data)