def studio_sched(): if request.method == 'GET': ## TO DO: add a decorator that will check if studio information has already been retrieved this session-- look at fibonnaci example # Feed venue_id into function to retrieve html if session['venue_id'] not in session['cached_studios'].keys(): print 'not cached' session['class_deets'] = studio_soupify(session['venue_id']) session['cached_studios'][session['venue_id']] = session['class_deets'] print session['cached_studios'] else: session['class_deets'] = session['cached_studios'][session['venue_id']] if len(session['class_deets']) == 0: return render_template('noclass.html', venue_name=session['venue_name']) else: return render_template( 'studio.html', venue_name=session['venue_name'], class_deets=session['class_deets'] ) else: # If the request is a POST, it means someone was trying to add class(es) to cart # Class details come in as a string, so they need to be converted back to a list for cl in request.form.getlist("selected_class"): session['classes_in_cart'].append(clean_class(cl)) return redirect(url_for('look_cart'))
def look_cart(): if request.method == 'GET': return render_template( 'cart.html', cart_contents=session['classes_in_cart'] ) else: # If request is POST, user is trying to remove classes for cl in request.form.getlist("remove_class"): classy = clean_class(cl) for i, workout in enumerate(session['classes_in_cart']): if workout[2] == classy[2]: break session['classes_in_cart'].pop(i) return redirect(url_for('look_cart'))