def createInstrument(request, creator_id):
    # strip away leading and trailing spaces
    form_name = ""
    form_description = ""
    form_picture_url = ""
    form_picture_attr = ""
    form_category = ""
    if request.form['name']:
        form_name = request.form['name'].strip()
    if request.form['description']:
        form_description = request.form['description'].strip()
    if request.form['picture_url']:
        form_picture_url = request.form['picture_url'].strip()
    if request.form['picture_attr']:
        form_picture_attr = request.form['picture_attr'].strip()
    if request.form['category']:
        form_category_id = getCategoryId(request.form['category'])
    # create a new Instrument from entered data
    inst = Instrument(
        name=form_name,
        description=form_description,
        picture_url=form_picture_url,
        picture_attr=form_picture_attr,
        category_id=form_category_id,
        user_id=creator_id)
    return inst
def newInstrument(category_id):
    if 'email' not in login_session:
        return redirect(url_for('showLogin'))
    categories = session.query(Category).all()
    umail = getUserEmail()
    message = ""
    if request.method == 'POST':
        # create an Instrument object from posted data
        newItem = createInstrument(request, login_session['user_id'])
        # if any field is blank, reject the post
        if (not newItem.name or not newItem.description
                or not newItem.picture_url or not newItem.picture_attr
                or not newItem.category_id):
            message = "All fields are required"
            return render_template(
                'newinstrument.html', user_email=umail,
                item=newItem, categories=categories,
                message=message), 400
        session.add(newItem)
        session.commit()
        return redirect(url_for(
            'showCategory', category_id=newItem.category_id))
    else:
        newItem = Instrument(
            name="",
            description="",
            picture_url="",
            picture_attr="",
            category_id=category_id)
        return render_template(
            'newinstrument.html', user_email=umail,
            item=newItem, categories=categories,
            message=message)
Ejemplo n.º 3
0
def newInstrument():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newInstrument = Instrument(name=request.form['name'],
                                   user_id=login_session['user_id'])
        session.add(newInstrument)
        session.commit()
        return redirect(url_for('showInstruments'))
    else:
        return render_template('newInstrument.html')
Ejemplo n.º 4
0
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Dummy user
User1 = User(name="Robo Barista", email="*****@*****.**")
session.add(User1)
session.commit()

# Menu for Drums
instrument1 = Instrument(user_id=1, name="Drums")

session.add(instrument1)
session.commit()


menuItem1 = MenuItem(user_id=1, name="Natal Arcadia", description="A versatile, affordable\
drum kit for your first gigs or recording sessions"                                                   , price="$699.99",\
instrument=instrument1)

session.add(menuItem1)
session.commit()

menuItem2 = MenuItem(
    user_id=1,
    name="Yamaha Stage Custom Birch",