def showItem(category_name, item_name): item = item_dao.find_by_item_name(item_name) categories = category_dao.get_all_category() return render_template('itemdetail.html', item=item, category=category_name, categories=categories)
def json_viewer(): json_data = None if 'json_data' in request.args: json_data = request.args['json_data'] categories = category_dao.get_all_category() items = item_dao.get_all_items() return render_template("json_view.html", categories=categories, items=items, json_data=json_data)
def showCategory(category_name): categories = category_dao.get_all_category() category = category_dao.find_by_category_name(category_name) items = item_dao.find_by_category(category) print(items) count = len(items) print('count: {}'.format(count)) return render_template('items.html', category=category.name, categories=categories, items=items, count=count)
def all_category_items_json(): json_data = dict() categories = category_dao.get_all_category() category_dict = [c.serialize for c in categories] for c in range(len(category_dict)): items = [ i.serialize for i in item_dao.find_by_category_id(category_dict[c]["id"]) ] if items: category_dict[c]["Item"] = items json_data['Category'] = category_dict return redirect( url_for('main_app.json_viewer', json_data=to_pretty_json(json_data)))
def addItem(): categories = category_dao.get_all_category() if request.method == 'POST': if 'name' not in request.form or not request.form['name'].strip(): flash("Item name cannot be empty") return render_template('additem.html', categories=categories) if 'category' not in request.form: flash("Category cannot be empty") return render_template('additem.html', categories=categories) category = category_dao.find_by_category_name(request.form['category']) item_dao.add_new_item(name=request.form['name'], description=request.form['description'], picture=request.form['picture'], category=category, date=datetime.datetime.now(), user_id=login_session['user_id']) flash('Item Successfully Added!') return redirect(url_for('main_app.showCatalog')) else: return render_template('additem.html', categories=categories)
def editItem(category_name, item_name): editedItem = item_dao.find_by_item_name(item_name) categories = category_dao.get_all_category() # See if the logged in user is the owner of item creator = get_user_info(editedItem.user_id) user = get_user_info(login_session['user_id']) # If logged in user != item owner redirect them if creator.id != int(login_session['user_id']): flash("You cannot edit this item. This item belongs to %s (%s)" % (creator.name, creator.email)) return redirect(url_for('main_app.showCatalog')) # POST methods if request.method == 'POST': if request.form['name']: editedItem.name = request.form['name'] if request.form['description']: editedItem.description = request.form['description'] if request.form['picture']: editedItem.picture = request.form['picture'] if request.form['category']: # category = session.query(Category).filter_by(name=request.form['category']).one() category = category_dao.find_by_category_name(category_name) editedItem.category = category time = datetime.datetime.now() editedItem.date = time db.session.add(editedItem) db.session.commit() flash('Category Item Successfully Edited!') return redirect( url_for('main_app.showCategory', category_name=editedItem.category.name)) else: return render_template('edititem.html', item=editedItem, categories=categories)
def categories_json(): json_data = dict() categories = category_dao.get_all_category() json_data['categories'] = [c.serialize for c in categories] return redirect( url_for('main_app.json_viewer', json_data=to_pretty_json(json_data)))
def showCatalog(): categories = category_dao.get_all_category() items = item_dao.get_limited_items() return render_template('catalog.html', categories=categories, items=items)