def delete_beer(beer_id): beer = List_history.query.get_or_404(beer_id) if beer.venue_db_id != current_user.id: abort(403) db.session.delete(beer) db.session.commit() user = User.query.filter_by(id=current_user.id).first() beers = user.beerlist_current beers = db.session.query( List_history.id, List_history.name, List_history.style, List_history.abv, List_history.ibu, List_history.brewery, List_history.location, List_history.website, List_history.description, List_history.draft_bottle_selection, List_current.id_dropdown).outerjoin( List_current, List_history.id == List_current.id_history).filter( List_current.venue_db_id == current_user.id).all() settings = { "venue_db_id": current_user.id, "updated": True, } ####################################### #PUSHER pusher_client.trigger('myDelBeer-evemt-channel', 'delBeerFromDb-event', {'message': settings}) #PUSHER ####################################### flash('The beer has been deleted!', 'success') return redirect(url_for('list_history.beer_dashboard'))
def _delete_update_ui(): settings = { "venue_db_id": current_user.id, "updated": True, } ###################################### #PUSHER pusher_client.trigger('my-update-channel', 'new-deleteUpdate-event', {'message': settings}) #PUSHER ####################################### return jsonify(settings)
def add_wine(): form = WineForm(request.form) user = User.query.filter_by(id=current_user.id).first() datas = db.session.query( Wine_type.id, Wine_type.type, ).filter(Wine_type.venue_db_id == current_user.id).order_by( Wine_type.type.asc()).all() print(datas) typelist = [] for data in datas: type = {"id": data.id, "type": data.type} typelist.append(type) types = typelist form.type.choices = [(type['id'], type['type']) for type in types] if request.method == 'POST' and form.validate(): # SQLAlchemy to add to database wine = Wine(name=form.name.data, location=form.location.data, varietal=form.varietal.data, type=form.type.data, glass=form.glass.data, bottle=form.bottle.data, description=form.description.data, food_pairings=form.food_pairings.data, website=form.website.data, venue_db_id=current_user.id) db.session.add(wine) db.session.commit() settings = { "venue_db_id": current_user.id, "updated": True, } ####################################### #PUSHER pusher_client.trigger('wine-event-channel', 'add-wine-event', {'message': settings}) #PUSHER ####################################### flash('Wine Created', 'success') return redirect(url_for('wine.wine_dashboard')) return render_template('add_wine.html', title='Add Wine', legend='Add Wine', form=form)
def _add_update_ui(): # print("***********************************************") # print("***********************************************") # print("***********************************************") settings = { "venue_db_id": current_user.id, "updated": True, } # print(settings) # print("***********************************************") # print("***********************************************") # print("***********************************************") ###################################### #PUSHER pusher_client.trigger('my-update-channel', 'new-addUpdate-event', {'message': settings}) #PUSHER ####################################### return jsonify(settings)
def edit_beer_list(): print("``````````````````````````````````````````````````````````````````") print("``````````````````````````````````````````````````````````````````") print("EDIT_BEER_LIST") print("``````````````````````````````````````````````````````````````````") print("``````````````````````````````````````````````````````````````````") screenId = 1 beerscreenSettings = db.session.query( Beerscreen_setting.beer_settings_screen_id).filter( Beerscreen_setting.venue_db_id == current_user.id).all() beerscreenSettingsIds = [] for id in beerscreenSettings: beerscreenSettingsIds.append(id[0]) user = User.query.filter_by(id=current_user.id).first() datas = user.beerlist_sort_asc beersDropdown = [] for data in datas: beer = { "id": data.id, "name": data.name, "style": data.style, "abv": data.abv, "ibu": data.ibu, "brewery": data.brewery, "location": data.location, "website": data.website, "description": data.description, "draft_bottle_selection": data.draft_bottle_selection, "venue_db_id": data.venue_db_id, } beersDropdown.append(beer) beers = db.session.query( List_history.id, List_history.name, List_history.style, List_history.abv, List_history.ibu, List_history.brewery, List_history.location, List_history.website, List_history.description, List_history.draft_bottle_selection, List_history.venue_db_id, List_current.id, List_current.id_dropdown, List_current.beer_of_month, List_current.coming_soon, ).outerjoin(List_current, List_history.id == List_current.id_history).filter( List_current.venue_db_id == current_user.id).filter( List_current.beer_screen_id == screenId).order_by( List_current.id.asc()).all() beerlist = [] for b in beers: beer = {} beer['id'] = b.id beer['name'] = b.name beer['style'] = b.style beer['abv'] = b.abv beer['ibu'] = b.ibu beer['brewery'] = b.brewery beer['location'] = b.location beer['website'] = b.website beer['description'] = b.description beer['draft_bottle_selection'] = b.draft_bottle_selection beer['venue_db_id'] = b.venue_db_id beer['id_dropdown'] = b.id_dropdown beer['beer_of_month'] = b.beer_of_month beer['coming_soon'] = b.coming_soon beer['defaultDropdown'] = getDefaultSelect(b.id_dropdown) beerlist.append(beer) tickerInfo = db.session.query( Ticker.id, Ticker.ticker_text, Ticker.ticker_screen_id, Ticker.venue_db_id, Ticker_type_id.ticker_type).join( Ticker_type_id, Ticker_type_id.ticker_type_id_fk == Ticker.ticker_type).filter( Ticker.venue_db_id == current_user.id).filter( Ticker.ticker_screen_id == screenId).first() if (tickerInfo): tickerText = tickerInfo.ticker_text else: tickerText = '' newTicker = Ticker(ticker_text='', tickerscreen_id=screenId, venue_db_id=current_user.id) db.session.add(newTicker) db.session.commit() if request.method == 'POST': rdata = request.form # print("rdata: {}".format(rdata)) print("`````````````````````````````````````````````````````````") print("`````````````````````````````````````````````````````````") for data in rdata: print("data: {}".format(data)) # print("len(rdata): {}".format(len(rdata))) print("`````````````````````````````````````````````````````````") print("`````````````````````````````````````````````````````````") newData = rdata.copy() print("newData: {}".format(newData)) print("`````````````````````````````````````````````````````````") screenId = newData.get("beerscreen-display-id") print("screenId: {}".format(screenId)) print("`````````````````````````````````````````````````````````") tickerText = newData.popitem()[1] print("tickerText: {}".format(tickerText)) print("`````````````````````````````````````````````````````````") print("`````````````````````````````````````````````````````````") beerCandidateList = [] for i, (key, value) in enumerate(rdata.items()): print("620 -- key: {}".format(key)) if key != 'ticker-text' and key != 'beerscreen-display-id': print("622 -- key, value: {}, {}".format(key, value)) beerCandidate = { "id_dropdown": "", "id_history": "", "bom": "", "cs": "" } print("629 -- i+1 , key, value: {} -- {} -- {}".format( i + 1, key, value)) splitData = key.split('_') print("631 -- splitData: {}".format(splitData)) splitKeyName = splitData[0] splitKeyIter = splitData[1] if splitKeyName == 'beer': beerCandidate['id_dropdown'] = splitKeyIter beerCandidate['id_history'] = value beerCandidate['bom'] = 0 beerCandidate['cs'] = 0 print("beerCandidate: {}".format(beerCandidate)) beerCandidateList.append(beerCandidate) for i, (key, value) in enumerate(rdata.items()): if key != 'ticker-text' and key != 'beerscreen-display-id': print(i + 1, key, value) splitData = key.split('_') splitKeyName = splitData[0] splitKeyIter = splitData[1] splitKeyIterNum = int(splitKeyIter) if splitKeyName == 'beer-of-month': print(splitKeyName + "_" + splitKeyIter + " ---- value= " + value) print(splitKeyIter) print(splitKeyIterNum - 1) print(beerCandidateList[splitKeyIterNum - 1]['bom']) if value != "": beerCandidateList[splitKeyIterNum - 1]['bom'] = True else: beerCandidateList[splitKeyIterNum - 1]['bom'] = False elif splitKeyName == 'coming-soon': print(splitKeyName + "_" + splitKeyIter + " ---- value= " + value) print(splitKeyIter) print(splitKeyIterNum - 1) print(beerCandidateList[splitKeyIterNum - 1]['cs']) if value != "": beerCandidateList[splitKeyIterNum - 1]['cs'] = True else: beerCandidateList[splitKeyIterNum - 1]['cs'] = False # for b in beerCandidateList: # print(b) print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ) print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ) beerCandidate = List_current.query.filter_by( id_dropdown=1, beer_screen_id=screenId, venue_db_id=current_user.id).first() print("beerCandidate: {}".format(beerCandidate)) print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ) print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ) for x in range(1, len(beerCandidateList) + 1, 1): beerCandidate = List_current.query.filter_by( id_dropdown=x, beer_screen_id=screenId, venue_db_id=current_user.id).first() print("beerCandidate: {}".format(beerCandidate)) beerCandidate.id_history = beerCandidateList[x - 1]['id_history'] beerCandidate.beer_of_month = beerCandidateList[x - 1]['bom'] beerCandidate.coming_soon = beerCandidateList[x - 1]['cs'] db.session.commit() if (tickerInfo): # print(tickerText) tickerCandidate = Ticker.query.filter_by( ticker_screen_id=screenId, venue_db_id=current_user.id).first() tickerCandidate.ticker_text = tickerText db.session.commit() settings = { "venue_db_id": current_user.id, "updated": True, } ###################################### #PUSHER pusher_client.trigger('my-event-channel', 'new-event', {'message': settings}) #PUSHER ####################################### flash('Beer List Updated', 'success') return redirect(url_for('list_history.edit_beer_list')) return render_template('edit_beer_list.html', title='Edit Beerlist', legend='Edit Beerlist', currentUserId=current_user.id, beersDropdown=beersDropdown, beerlist=beerlist, tickerText=tickerText, beerscreenSettingsIds=beerscreenSettingsIds)
def edit_beer(beer_id): beer = List_history.query.get_or_404(beer_id) if beer.venue_db_id != current_user.id: abort(403) form = BeerForm() # get beer sizes to populate dropdowns drink_sizes = _getDrinkSizes(current_user.id) # get beer prices to populate dropdowns drink_prices = _getDrinkPrices(current_user.id) # populates the dropdowns with correct information form.size_1.choices = [(size['drink_size_id'], size['drink_size']) for size in drink_sizes] form.price_1.choices = [(price['drink_price_id'], price['drink_price']) for price in drink_prices] form.size_2.choices = [(size['drink_size_id'], size['drink_size']) for size in drink_sizes] form.price_2.choices = [(price['drink_price_id'], price['drink_price']) for price in drink_prices] form.size_3.choices = [(size['drink_size_id'], size['drink_size']) for size in drink_sizes] form.price_3.choices = [(price['drink_price_id'], price['drink_price']) for price in drink_prices] form.size_4.choices = [(size['drink_size_id'], size['drink_size']) for size in drink_sizes] form.price_4.choices = [(price['drink_price_id'], price['drink_price']) for price in drink_prices] # check if form is validated and method == post if form.validate_on_submit(): beer.name = form.name.data beer.style = form.style.data beer.abv = form.abv.data beer.ibu = form.ibu.data beer.brewery = form.brewery.data beer.location = form.location.data beer.website = form.website.data beer.description = form.description.data beer.size_id_1 = form.size_1.data beer.price_id_1 = form.price_1.data beer.size_id_2 = form.size_2.data beer.price_id_2 = form.price_2.data beer.size_id_3 = form.size_3.data beer.price_id_3 = form.price_3.data beer.size_id_4 = form.size_4.data beer.price_id_4 = form.price_4.data beer.draft_bottle_selection = form.draftBottle.data # commits beer info to the DB db.session.commit() # use settings to tell pusher info has been updated settings = { "venue_db_id": current_user.id, "updated": True, } ####################################### #PUSHER pusher_client.trigger('myEditBeer-evemt-channel', 'editBeerToDb-event', {'message': settings}) #PUSHER ####################################### # show success message flash('Beer has been updated!', 'success') return redirect(url_for('list_history.beer_dashboard')) elif request.method == 'GET': # populate fields with DB info form.name.data = beer.name form.style.data = beer.style form.abv.data = beer.abv form.ibu.data = beer.ibu form.brewery.data = beer.brewery form.location.data = beer.location form.website.data = beer.website form.description.data = beer.description form.size_1.data = beer.size_id_1 form.price_1.data = beer.price_id_1 form.size_2.data = beer.size_id_2 form.price_2.data = beer.price_id_2 form.size_3.data = beer.size_id_3 form.price_3.data = beer.price_id_3 form.size_4.data = beer.size_id_4 form.price_4.data = beer.price_id_4 form.draftBottle.data = beer.draft_bottle_selection return render_template('edit_beer.html', title='Edit Beer: ' + beer_id, legend='Edit Beer ' + beer_id, form=form, beer=beer, drink_sizes=drink_sizes, drink_prices=drink_prices)
def add_beer(): form = BeerForm() # get beer sizes to populate dropdowns drink_sizes = _getDrinkSizes(current_user.id) # get beer prices to populate dropdowns drink_prices = _getDrinkPrices(current_user.id) # populates the dropdowns with correct information form.size_1.choices = [(size['drink_size_id'], size['drink_size']) for size in drink_sizes] form.price_1.choices = [(price['drink_price_id'], price['drink_price']) for price in drink_prices] form.size_2.choices = [(size['drink_size_id'], size['drink_size']) for size in drink_sizes] form.price_2.choices = [(price['drink_price_id'], price['drink_price']) for price in drink_prices] form.size_3.choices = [(size['drink_size_id'], size['drink_size']) for size in drink_sizes] form.price_3.choices = [(price['drink_price_id'], price['drink_price']) for price in drink_prices] form.size_4.choices = [(size['drink_size_id'], size['drink_size']) for size in drink_sizes] form.price_4.choices = [(price['drink_price_id'], price['drink_price']) for price in drink_prices] # defaults draft/bottle/can radio buttons form.draftBottle.data = "Draft" # if request.method == 'POST' and form.validate: # check if form is validated and method == post if form.validate_on_submit(): # queries db to submit a beers info beer = List_history(name=form.name.data, style=form.style.data, abv=form.abv.data, ibu=form.ibu.data, brewery=form.brewery.data, location=form.location.data, website=form.website.data, description=form.description.data, size_id_1=form.size_1.data, price_id_1=form.price_1.data, size_id_2=form.size_2.data, price_id_2=form.price_2.data, size_id_3=form.size_3.data, price_id_3=form.price_3.data, size_id_4=form.size_4.data, price_id_4=form.price_4.data, draft_bottle_selection=request.form['draftBottle'], venue_db_id=current_user.id) # print(beer) # adds beer to be commited db.session.add(beer) # commits beer info to the DB db.session.commit() # use settings to tell pusher info has been updated settings = { "venue_db_id": current_user.id, "updated": True, } ####################################### #PUSHER pusher_client.trigger('myAddBeer-event-channel', 'addBeerToDb-event', {'message': settings}) #PUSHER ####################################### # show success message flash('Beer has been created and added to the list!', 'success') return redirect(url_for('list_history.beer_dashboard')) return render_template('add_beer.html', title='Add Beer', legend='Add Beer', form=form)
def on_tap_next_editor(): user = User.query.filter_by(id=current_user.id).first() datas = user.beerlist_sort_asc selectBeerlist = [] for data in datas: beer = { "id": data.id, "name": data.name, "style": data.style, "abv": data.abv, "ibu": data.ibu, "brewery": data.brewery, "location": data.location, "website": data.website, "description": data.description, "draft_bottle_selection": data.draft_bottle_selection, } selectBeerlist.append(beer) currentBeers = user.beerlist_current currentBeers = db.session.query( List_history.id, List_history.name, List_history.style, List_history.abv, List_history.ibu, List_history.brewery, List_history.location, List_history.website, List_history.description, List_history.draft_bottle_selection, List_current.id_history, List_current.id_dropdown).outerjoin( List_current, List_history.id == List_current.id_history).filter( List_current.venue_db_id == current_user.id).all() beerlistLength = len(currentBeers) nextBeers = user.beerlist_current nextBeers = db.session.query( List_history.id, List_history.name, List_history.style, List_history.abv, List_history.ibu, List_history.brewery, List_history.location, List_history.website, List_history.description, List_history.draft_bottle_selection, List_current.id_on_next, List_current.id_dropdown).outerjoin( List_current, List_history.id == List_current.id_on_next).filter( List_current.venue_db_id == current_user.id).all() if request.method == 'POST': data = request.form for x in range(1, beerlistLength + 1, 1): beer = request.form['beer_{}'.format(x)] # print(beer) beerCandidate = List_current.query.filter_by( id_dropdown=x, venue_db_id=current_user.id).first() beerCandidate.id_on_next = beer db.session.commit() settings = { "venue_db_id": current_user.id, "updated": True, # "data": data } ####################################### #PUSHER pusher_client.trigger('my-update-channel', 'new-nextUpdate-event', {'message': settings}) #PUSHER ####################################### flash('Next Beer list updated', 'success') return redirect(url_for('list_history.on_tap_next_editor')) return render_template('on_tap_next_editor.html', title='Tapping Next', legend='Tapping Next Editor', currentUserId=current_user.id, selectBeerlist=selectBeerlist, currentBeers=currentBeers, nextBeers=nextBeers, beerlistLength=beerlistLength)
def testing_winelist_editor(): user = User.query.filter_by(id=current_user.id).first() datas = _getWine(current_user.id) wines = [] for data in datas: wine = { "id": data.id, "name": data.name, "varietal": data.varietal, "location": data.location, "glass": data.glass, "bottle": data.bottle, "description": data.description, "food_pairings": data.food_pairings, "website": data.website, } wines.append(wine) for wine in wines: print(wine) # wine1select = getDefaultCurrentWinelist('1') # wine2select = getDefaultCurrentWinelist('2') # wine3select = getDefaultCurrentWinelist('3') # wine4select = getDefaultCurrentWinelist('4') # wine5select = getDefaultCurrentWinelist('5') # wine6select = getDefaultCurrentWinelist('6') # wine7select = getDefaultCurrentWinelist('7') # wine8select = getDefaultCurrentWinelist('8') # wine9select = getDefaultCurrentWinelist('9') # wine10select = getDefaultCurrentWinelist('10') # wine11select = getDefaultCurrentWinelist('11') # wine12select = getDefaultCurrentWinelist('12') # wine13select = getDefaultCurrentWinelist('13') # wine14select = getDefaultCurrentWinelist('14') # wine15select = getDefaultCurrentWinelist('15') # wine16select = getDefaultCurrentWinelist('16') # wine17select = getDefaultCurrentWinelist('17') # wine18select = getDefaultCurrentWinelist('18') # wine19select = getDefaultCurrentWinelist('19') # wine20select = getDefaultCurrentWinelist('20') # wine21select = getDefaultCurrentWinelist('21') # wine22select = getDefaultCurrentWinelist('22') # wine23select = getDefaultCurrentWinelist('23') # wine24select = getDefaultCurrentWinelist('24') # wine25select = getDefaultCurrentWinelist('25') # wine26select = getDefaultCurrentWinelist('26') # wine27select = getDefaultCurrentWinelist('27') # wine28select = getDefaultCurrentWinelist('28') # # form = CurrentWinelistForm(request.form, # wine1=wine1select.id_wine, # wine2=wine2select.id_wine, # wine3=wine3select.id_wine, # wine4=wine4select.id_wine, # wine5=wine5select.id_wine, # wine6=wine6select.id_wine, # wine7=wine7select.id_wine, # wine8=wine8select.id_wine, # wine9=wine9select.id_wine, # wine10=wine10select.id_wine, # wine11=wine11select.id_wine, # wine12=wine12select.id_wine, # wine13=wine13select.id_wine, # wine14=wine14select.id_wine, # wine15=wine15select.id_wine, # wine16=wine16select.id_wine, # wine17=wine17select.id_wine, # wine18=wine18select.id_wine, # wine19=wine19select.id_wine, # wine20=wine20select.id_wine, # wine21=wine21select.id_wine, # wine22=wine22select.id_wine, # wine23=wine23select.id_wine, # wine24=wine24select.id_wine, # wine25=wine25select.id_wine, # wine26=wine26select.id_wine, # wine27=wine27select.id_wine, # wine28=wine28select.id_wine # ) # # form.wine1.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine2.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine3.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine4.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine5.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine6.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine7.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine8.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine9.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine10.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine11.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine12.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine13.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine14.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine15.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine16.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine17.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine18.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine19.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine20.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine21.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine22.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine23.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine24.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine25.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine26.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine27.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] # form.wine28.choices = [(wine['id'], wine['name'] + ' - ' + wine['varietal']) for wine in wines] if request.method == "POST": for x in range(1, 29, 1): wine = request.form['wine{}'.format(x)] wineCandidate = Winelist_current.query.filter_by( id_dropdown=x, venue_db_id=current_user.id).first() wineCandidate.id_wine = wine db.session.commit() wines = _getWinelistDisplay(current_user.id) settings = { "venue_db_id": current_user.id, "updated": True, # "winelist": wines } # settings = json.dumps(settings) ####################################### #PUSHER pusher_client.trigger('wine-event-channel', 'new-wine-event', {'message': settings}) #PUSHER ####################################### # Flash success message on the screen flash('Winelist Updated!!!', 'success') return redirect(url_for('wine.testing_winelist_editor')) return render_template('testing_winelist_editor.html', title='Winelist Editor', legend='Winelist Editor', wines=wines)
def edit_wine(wine_id): wine = Wine.query.get_or_404(wine_id) if wine.venue_db_id != current_user.id: abort(403) # Get form form = WineForm(request.form, type=wine.type) rdata = _getWinetypes(current_user.id) wineTypes = _convertToWinelist(rdata) form.type.choices = [(type['id'], type['type']) for type in wineTypes] if form.validate_on_submit(): # if request.method == 'POST': wine.name = form.name.data wine.location = form.location.data wine.varietal = form.varietal.data wine.type = form.type.data wine.glass = form.glass.data wine.bottle = form.bottle.data wine.description = form.description.data wine.food_pairings = form.food_pairings.data wine.website = form.website.data db.session.add(wine) db.session.commit() settings = { "venue_db_id": current_user.id, "updated": True, } ####################################### #PUSHER pusher_client.trigger('wine-event-channel', 'edit-wine-event', {'message': settings}) #PUSHER ####################################### flash('Wine Updated!!!', 'success') return redirect(url_for('wine.wine_dashboard')) elif request.method == 'GET': rdata = _getWinetypes(current_user.id) wineTypes = _convertToWinelist(rdata) # # print(wineTypes) # for x in wineTypes: # print("x['type']: {}".format(x['type'])) # # print("wine.type: {}".format(wine.type)) # Populate wine form fields # Populate the type select with values from the DB form.type.data = wine.type form.type.choices = [(type['id'], type['type']) for type in wineTypes] form.name.data = wine.name form.location.data = wine.location form.varietal.data = wine.varietal form.glass.data = wine.glass form.bottle.data = wine.bottle form.description.data = wine.description form.food_pairings.data = wine.food_pairings form.website.data = wine.website return render_template('edit_wine.html', title='Edit Wine', legend='Edit Wine', form=form)