示例#1
0
def categoryAdd():
    categories = session.query(Category).order_by(asc(Category.name))
    if request.method == 'POST':
        newCategory = Category(name=request.form['name'],
                               description=request.form['description'],
                               user_id=login_session['user_id'])
        if request.files['image']:
            newCategory.photo = imgur_upload(request.files['image'], config.IMGUR_CLIENT_ID)
        session.add(newCategory)
        flash('New %s Category Successfully Added' % newCategory.name)
        session.commit()
        return redirect(url_for('index'))
    else:
        return render_template('category/categoryadd.html',
                                categories = categories,
                                privacy_status = privacy_check())
示例#2
0
def categoryAdd():
    categories = session.query(Category).order_by(asc(Category.name))
    if request.method == 'POST':
        newCategory = Category(name=request.form['name'],
                               description=request.form['description'],
                               user_id=login_session['user_id'])
        if request.files['image']:
            newCategory.photo = imgur_upload(request.files['image'],
                                             config.IMGUR_CLIENT_ID)
        session.add(newCategory)
        flash('New %s Category Successfully Added' % newCategory.name)
        session.commit()
        return redirect(url_for('index'))
    else:
        return render_template('category/categoryadd.html',
                               categories=categories,
                               privacy_status=privacy_check())
示例#3
0
def itemAdd(category_id):
    categories = session.query(Category).order_by(asc(Category.name))
    if request.method == 'POST':
        newItem = Item(name=request.form['name'],
                       description=request.form['description'],
                       category_id=request.form['category_id'],
                       user_id=login_session['user_id'])
        if request.files['image']:
            newItem.photo=imgur_upload(request.files['image'], config.IMGUR_CLIENT_ID)
        session.add(newItem)
        flash('%s Successfully Added' % newItem.name)
        session.commit()
        return redirect(url_for('categoryHome', category_id = newItem.category_id))
    else:
        return render_template('item/itemadd.html',
                                categories = categories,
                                privacy_status = privacy_check(),
                                target = category_id)
示例#4
0
def categoryEdit(category_id):
    categories = session.query(Category).order_by(asc(Category.name))
    targetCategory = session.query(Category).filter_by(id=category_id).one()
    if targetCategory.user_id != login_session['user_id']:
        return "<script>function reject() {alert('You do not have permission to edit this Category.');history.go(-1);}</script><body onload='reject()''>"
    if request.method == 'POST':
        targetCategory.name = request.form['name']
        targetCategory.description = request.form['description']
        if request.files['image']:
            targetCategory.photo = imgur_upload(request.files['image'], config.IMGUR_CLIENT_ID)
        flash('Category Information Updated')
        return redirect(url_for('categoryHome',
                                 category_id = targetCategory.id))
    else:
        return render_template('category/categoryedit.html',
                               category=targetCategory,
                               privacy_status = privacy_check(),
                               categories = categories)
示例#5
0
def categoryEdit(category_id):
    categories = session.query(Category).order_by(asc(Category.name))
    targetCategory = session.query(Category).filter_by(id=category_id).one()
    if targetCategory.user_id != login_session['user_id']:
        return "<script>function reject() {alert('You do not have permission to edit this Category.');history.go(-1);}</script><body onload='reject()''>"
    if request.method == 'POST':
        targetCategory.name = request.form['name']
        targetCategory.description = request.form['description']
        if request.files['image']:
            targetCategory.photo = imgur_upload(request.files['image'],
                                                config.IMGUR_CLIENT_ID)
        flash('Category Information Updated')
        return redirect(url_for('categoryHome', category_id=targetCategory.id))
    else:
        return render_template('category/categoryedit.html',
                               category=targetCategory,
                               privacy_status=privacy_check(),
                               categories=categories)
示例#6
0
def itemEdit(item_id):
    targetItem = session.query(Item).filter_by(id=item_id).one()
    categories = session.query(Category).order_by(asc(Category.name))
    if targetItem.user_id != login_session['user_id']:
        return "<script>function reject() {alert('You do not have permission to edit this Item.');history.go(-1);}</script><body onload='reject()''>"
    if request.method == 'POST':
        targetItem.category_id = request.form['category_id']
        targetItem.name = request.form['name']
        targetItem.description = request.form['description']
        if request.files['image']:
            targetItem.photo = imgur_upload(request.files['image'], config.IMGUR_CLIENT_ID)
        session.add(targetItem)
        session.commit()
        flash('Item Information Updated')
        return redirect(url_for('itemHome', item_id = item_id))
    else:
        return render_template('item/itemedit.html',
                                item = targetItem,
                                categories = categories,
                                privacy_status = privacy_check())
示例#7
0
def itemAdd(category_id):
    categories = session.query(Category).order_by(asc(Category.name))
    if request.method == 'POST':
        newItem = Item(name=request.form['name'],
                       description=request.form['description'],
                       category_id=request.form['category_id'],
                       user_id=login_session['user_id'])
        if request.files['image']:
            newItem.photo = imgur_upload(request.files['image'],
                                         config.IMGUR_CLIENT_ID)
        session.add(newItem)
        flash('%s Successfully Added' % newItem.name)
        session.commit()
        return redirect(
            url_for('categoryHome', category_id=newItem.category_id))
    else:
        return render_template('item/itemadd.html',
                               categories=categories,
                               privacy_status=privacy_check(),
                               target=category_id)
示例#8
0
def itemEdit(item_id):
    targetItem = session.query(Item).filter_by(id=item_id).one()
    categories = session.query(Category).order_by(asc(Category.name))
    if targetItem.user_id != login_session['user_id']:
        return "<script>function reject() {alert('You do not have permission to edit this Item.');history.go(-1);}</script><body onload='reject()''>"
    if request.method == 'POST':
        targetItem.category_id = request.form['category_id']
        targetItem.name = request.form['name']
        targetItem.description = request.form['description']
        if request.files['image']:
            targetItem.photo = imgur_upload(request.files['image'],
                                            config.IMGUR_CLIENT_ID)
        session.add(targetItem)
        session.commit()
        flash('Item Information Updated')
        return redirect(url_for('itemHome', item_id=item_id))
    else:
        return render_template('item/itemedit.html',
                               item=targetItem,
                               categories=categories,
                               privacy_status=privacy_check())