예제 #1
0
def showItem(item_id):
    # filter down to the item_id passed in
    item = db_session.query(CatalogItem).filter_by(id=item_id).one()
    creator = getUserInfo(item.user_id)
    category = db_session.query(Category).filter_by(id=item.category_id).one()
    return render_template('showItem.html',
                           item=item,
                           category=category,
                           creator=creator)
예제 #2
0
def editItem(item_id):
    # filter for the passed in item_id
    editedItem = db_session.query(CatalogItem).filter_by(id=item_id).one()
    creator = getUserInfo(editedItem.user_id)

    if creator.id != login_session['user_id']:
        flash('You must be the owner to edit')
        return redirect(url_for('showCategories'))
    form = editItemForm()
    # couldn't seem to set this in the template
    form.categories.data = editedItem.category_id
    form.description.data = editedItem.description
    # validate_on_submit checks that the request is POST and that all validators
    # are True
    if form.validate_on_submit():
        filename = images.save(request.files['item_image'])
        url = images.url(filename)
        editedItem.name = form.name.data
        editedItem.category_id = form.categories.data
        editedItem.description = form.description.data
        editedItem.image_filename = filename
        editedItem.image_url = url
        db_session.commit()
        flash('Item successfully edited')
        return redirect(url_for('showCategories'))
    return render_template('editItem.html', form=form, item=editedItem)
예제 #3
0
def createUser(login_session):
    newUser = Users(
        name=login_session['username'],
        email=login_session['email'],
        picture=login_session['picture'])
    db_session.add(newUser)
    db_session.commit()
    user = db_session.query(Users).filter_by(
        email=login_session['email']).one()
    return user.id
예제 #4
0
def showCategories():
    # create the form and populate the categories from the above query results
    form = mainForm()

    # if no category is selected then the request will fail so just display all
    # items.  Otherwise display only items for the selected category.
    try:
        choice = request.form['choice']
        items = db_session.query(CatalogItem).filter_by(
            category_id=choice).all()
        return render_template('front.html',
                               form=form,
                               items=items,
                               choice=choice)
    except:
        choice = 0
        items = db_session.query(CatalogItem)
        return render_template('front.html',
                               form=form,
                               items=items,
                               choice=choice)
예제 #5
0
def deleteItem(item_id):
    # filter for the passed in item_id
    deletedItem = db_session.query(CatalogItem).filter_by(id=item_id).one()
    creator = getUserInfo(deletedItem.user_id)

    if creator.id != login_session['user_id']:
        flash('You must be the owner to delete')
        return redirect(url_for('showCategories'))
    form = deleteItemForm()
    # validate_on_submit checks that the request is POST and that all validators
    # are True
    if form.validate_on_submit():
        db_session.delete(deletedItem)
        db_session.commit()
        flash('Item successfully deleted')
        return redirect(url_for('showCategories'))
    return render_template('deleteItem.html', form=form, item=deletedItem)
예제 #6
0
def deleteCategory(category_id):
    # filter for the passed in category_id
    deletedCategory = db_session.query(Category).filter_by(
        id=category_id).one()
    creator = getUserInfo(deletedCategory.user_id)

    if creator.id != login_session['user_id']:
        flash('You must be the owner to delete')
        return redirect(url_for('showCategories'))
    form = deleteCategoryForm()
    if form.validate_on_submit():
        db_session.delete(deletedCategory)
        db_session.commit()
        flash('Category %s successfully deleted' % deletedCategory.name)
        return redirect(url_for('showCategories'))
    return render_template('deleteCategory.html',
                           form=form,
                           category=deletedCategory)
예제 #7
0
def editCategory(category_id):
    # filter for the passed in category_id
    editedCategory = db_session.query(Category).filter_by(id=category_id).one()
    creator = getUserInfo(editedCategory.user_id)

    if creator.id != login_session['user_id']:
        flash('You must be the owner to edit')
        return redirect(url_for('showCategories'))
    form = editCategoryForm()
    # validate_on_submit checks that the request is POST and that all validators
    # are True
    if form.validate_on_submit():
        editedCategory.name = form.name.data
        db_session.commit()
        flash('Category successfully edited')
        return redirect(url_for('showCategories'))
    return render_template('editCategory.html',
                           form=form,
                           category=editedCategory)
예제 #8
0
 def __init__(self, *args, **kwargs):
     super(editItemForm, self).__init__(*args, **kwargs)
     self.categories.choices = [(category.id, category.name)
                                for category in db_session.query(Category)]
예제 #9
0
def getUserID(email):
    try:
        user = db_session.query(Users).filter_by(email=email).one()
        return user.id
    except:
        return None
예제 #10
0
def getUserInfo(user_id):
    user = db_session.query(Users).filter_by(id=user_id).one()
    return user
예제 #11
0
def showItemJSON(item_id):
    items = db_session.query(CatalogItem).filter_by(id=item_id).one()
    return jsonify(items.serialize)
예제 #12
0
def showItemsJSON():
    items = db_session.query(CatalogItem)
    return jsonify(items=[i.serialize for i in items])
예제 #13
0
def showCategoryItemsJSON(category_id):
    items = db_session.query(CatalogItem).filter_by(id=category_id)
    return jsonify(items=[i.serialize for i in items])
예제 #14
0
def showCategoriesJSON():
    categories = db_session.query(Category)
    return jsonify(categories=[c.serialize for c in categories])