def deleteCategory(category_id): category = getCategory(category_id) if category.user_id != login_session['user_id']: return "<script>function myFunction() {alert('You are not authorized" \ " to delete this category. Please create your own category in " \ "order to delete.');}</script><body onload='myFunction()''>" if request.method == 'POST': removeCategory(category_id) flash('%s Successfully Deleted' % category.name) return redirect(url_for('showCatalog')) else: return render_template('deleteCategory.html', category=category)
def showItem(category_id, item_id): category = getCategory(category_id) item = getItem(item_id) creator = getUserInfo(item.user_id) if 'username' not in login_session: return render_template('publicItem.html', item=item, category=category, creator=creator) else: return render_template('item.html', item=item, category=category, creator=creator)
def showCategory(category_id): category = getCategory(category_id) creator = getUserInfo(category.user_id) items = getItems(category_id) if 'username' not in login_session: return render_template('publicCategory.html', items=items, category=category, creator=creator) else: return render_template('category.html', items=items, category=category, creator=creator)
def newItem(category_id): category = getCategory(category_id) if request.method == 'POST': if 'image' in request.files: image = store_image(request.files['image']) else: image = '' addItem(request.form['name'], request.form['description'], request.form['cost'], request.form['weight'], image, category_id, login_session['user_id']) flash('New Item, %s, In Category, %s, Successfully Created' % (request.form['name'], category.name)) return redirect(url_for('showCategory', category_id=category_id)) else: return render_template('newItem.html', category=category)
def editCategory(category_id): editedCategory = getCategory(category_id) if editedCategory.user_id != login_session['user_id']: return "<script>function myFunction() {alert('You are not authorized" \ " to edit this category. Please create your own category in " \ " order to edit.');}</script><body onload='myFunction()''>" if request.method == 'POST': if request.form['name']: oldName = editedCategory.name editedCategory.name = request.form['name'] flash('Category Successfully Renamed From %s To %s' % (oldName, editedCategory.name)) if 'banner' in request.files: if editedCategory.banner != '': remove_image(editedCategory.banner) editedCategory.banner = store_image(request.files['banner']) flash('Category Banner Image Successfully Updated') updateCategory(editedCategory) return redirect(url_for('showCatalog')) else: return render_template('editCategory.html', category=editedCategory)