def showItem(category_name, item_name): item = crud.findItem(item_name) creator = crud.getUserInfo(item.user_id) categories = crud.findAllCategories() if 'username' not in login_session or creator.id != login_session[ 'user_id']: return render_template('public_itemdetail.html', item=item, category=category_name, categories=categories, creator=creator) else: return render_template('itemdetail.html', item=item, category=category_name, categories=categories, creator=creator)
def addItem(): categories = crud.findAllCategories() if request.method == 'POST': new_item_name = request.form['name'] new_item_date = datetime.datetime.now() new_item_description = request.form['description'] new_item_picture = request.form['picture'] new_item_category = request.form.get('category') new_user_id = login_session['user_id'] crud_function = crud.newItem(new_item_name, new_item_date, new_item_description, new_item_picture, new_item_category, new_user_id) if crud_function: return render_template('additem.html', error=crud_function) else: flash('Pokemon Successfully Added!') return redirect(url_for('showCatalog')) else: return render_template('additem.html', categories=categories)
def deleteItem(item_name): itemToDelete = crud.findItem(item_name) categories = crud.findAllCategories() # See if the logged in user is the owner of Pokemon creator = crud.getUserInfo(itemToDelete.user_id) user = crud.getUserInfo(login_session['user_id']) # If logged in user != Pokemon owner redirect them if creator.id != login_session['user_id']: flash("You cannot delete this Pokemon. This Pokemon belongs to %s" % creator.name) return redirect(url_for('showCatalog')) if request.method == 'POST': crud_function = crud.deletingItem(item_name) if crud_function: return render_template('deleteitem.html', error=crud_function) else: flash('Pokemon Successfully Deleted! ' + itemToDelete.name) return redirect(url_for('showCatalog')) else: return render_template('deleteitem.html', item=itemToDelete)
def showCategory(category_name): categories = crud.findAllCategories() category = crud.findCategory(category_name) items = crud.findCategoryItems(category) print items count = crud.countItems(category) creator = crud.getUserInfo(category.user_id) if 'username' not in login_session or creator.id != login_session[ 'user_id']: return render_template('public_items.html', category=category.name, categories=categories, items=items, count=count) else: user = crud.getUserInfo(login_session['user_id']) return render_template('items.html', category=category.name, categories=categories, items=items, count=count, user=user)
def editItem(item_name): editedItem = crud.findItem(item_name) categories = crud.findAllCategories() # See if the logged in user is the owner of the Pokemon creator = crud.getUserInfo(editedItem.user_id) user = crud.getUserInfo(login_session['user_id']) # If logged in user != Pokemon owner redirect them if creator.id != login_session['user_id']: flash("You cannot edit this Pokemon. This Pokemon belongs to %s" % creator.name) return redirect(url_for('showCatalog')) # POST methods if request.method == 'POST': if request.form['name']: edited_item_name = request.form['name'] if request.form['description']: edited_item_description = request.form['description'] if request.form['picture']: edited_item_picture = request.form['picture'] if request.form['category']: edited_item_category = request.form.get('category') edited_item_date = datetime.datetime.now() crud_function = crud.editingItem(edited_item_name, edited_item_date, edited_item_description, edited_item_picture, edited_item_category) if crud_function: return render_template('edititem.html', error=crud_function) else: flash('Pokemon Successfully Edited!') return redirect( url_for('showCategory', category_name=edited_item_category)) else: return render_template('edititem.html', item=editedItem, categories=categories)
def showCatalog(): categories = crud.findAllCategories() items = crud.findAllLastItems() return render_template('catalog.html', categories=categories, items=items)