def gear_snowbinding(): brands = database("select name from snowbinding_brands") sizes = database("select size from size") size_ids = database("select id, size from size") results = filter(brands, sizes, size_ids) size_id = results[0] filters = results[1] filter_options = results[2] type = results[3] keys = results[4] # sending all variables over to post session['keys'] = keys session['type'] = type session['filter_options'] = filter_options session['filters'] = filters session['size_id'] = size_id return render_template('gear_snowbinding.html', filter_options=filter_options, filter=filters, key=keys)
def gear_snow_boots(): # getting all the things to filter by brands = database("select name from snowboots_brands") sizes = database("select size from size") size_ids = database("select id,size from size") # getting the size id from database results = filter(brands, sizes, size_ids) size_id = results[0] filters = results[1] filter_options = results[2] type = results[3] keys = results[4] # sending all variables over to post session['keys'] = keys session['type'] = type session['filter_options'] = filter_options session['filters'] = filters session['size_id'] = size_id return render_template('gear_snow_boots.html', filter_options=filter_options, filter=filters, key=keys)
def forms(): all_forms = database("select * from formpost") personal_stat = database_var("select * from user where name =?", (session['username'], )) return render_template('forms.html', all_forms=all_forms, stat=personal_stat)
def forms_post(): content = None title = None if request.method == 'POST' and "title" in request.form: title = request.form['title'] if request.method == 'POST' and "content" in request.form: content = request.form['content'] if request.method == 'POST' and "search_form" in request.form: search = request.form['search_form'] if title is None: if content is None: # plain searching result = database("select * from formpost where title LIKE '%" + search + "%' OR post LIKE '%" + search + "%'") if title is None: if content is not None: # searching content result = database("select * from formpost where post LIKE '%" + search + "%'") if title is not None: # searching title if content is None: result = database("select * from formpost where title LIKE '%" + search + "%'") if title is not None: if content is not None: # searching both content and title result = database("select * from formpost where title LIKE '%" + search + "%' OR post LIKE '%" + search + "%'") personal_stat = database_var("select * from user where name =?", (session['username'], )) return render_template('forms.html', user=session['username'], stat=personal_stat, all_forms=result)
def gear_clothes(): result = database("select * from clothes where id >= 1") if request.method == 'POST' and "search_bar" in request.form: search = request.form['search_bar'] conn = sqlite3.connect("snowbaord.db") c = conn.cursor() c.execute("select * from clothes where name LIKE '%" + search + "%'") result = c.fetchall() conn.close() return render_template('gear_clothes.html', tests=result) return render_template('gear_clothes.html', tests=result)
def gear_clothes_post(): queries = { "1": "brand = ", "2": "id in (select clothes_id from clothes_size where size_id = " } # getting al variables keys = session.get('keys') type = session.get('type') filter_options = session.get('filter_options') filters = session.get('filters') size_id = session.get('size_id') query_start = "select * from clothes " query = filter_post(queries, keys, type, filter_options, filters, size_id, query_start) print(query) print(keys) conn = sqlite3.connect('snowbaord.db') c = conn.cursor() c.execute(query) query_r = c.fetchall() conn.close() if request.method == 'POST' and "search_bar" in request.form: search_clothes = request.form['search_bar'] query_r = database("select * from clothes where name LIKE '%" + search_clothes + "%'") return render_template('gear_clothes.html', clothes_r=query_r, filter_options=filter_options, filter=filters, key=keys)
def people(): query = "select * from people where id >= 1" result = database(query) return render_template('people.html', results=result)
def gear_snowbaord(): search_bar = request.form.get('search_bar') #brands request Burton = request.form.get('Burton') Salomon = request.form.get('Salomon') Lib_Tech = request.form.get('Lib_Tech') Jones_Snowboards = request.form.get('Jones_Snowboards') Gnu = request.form.get('Gnu') #colour blue = request.form.get('blue') red = request.form.get('red') orange = request.form.get('orange') pink = request.form.get('pink') white = request.form.get('white') black = request.form.get('black') yellow = request.form.get('yellow') other = request.form.get('other') green = request.form.get('green') # sizes one_forty = request.form.get('140') one_forty_two = request.form.get('142') one_forty_four = request.form.get('144') one_forty_six = request.form.get('146') one_forty_eight = request.form.get('148') #prices l200 = request.form.get('200') l300 = request.form.get('300') l400 = request.form.get('400') l500 = request.form.get('500') l600 = request.form.get('600') g600 = request.form.get('600+') # search bar code if search_bar is not None: query = "select * from snowbaord where name LIKE '%" + search_bar + "%'" # so anything that has a like term shows result = database(query) return render_template('gear_snowbaord.html', tests=result) bcount = 0 # counting how many brand request forms we have ccount = 0 # counting how many color request forms we have scount = 0 # counting how many size request forms we have pcount = 0 # counting how many price request forms we have #counting the request forms brands if Burton is not None: bcount += 1 if Salomon is not None: bcount += 1 if Lib_Tech is not None: bcount += 1 if Jones_Snowboards is not None: bcount += 1 if Gnu is not None: bcount += 1 #counting the request forms color if blue is not None: ccount += 1 if red is not None: ccount += 1 if orange is not None: ccount += 1 if pink is not None: ccount += 1 if white is not None: ccount += 1 if black is not None: ccount += 1 if yellow is not None: ccount += 1 if other is not None: ccount += 1 if one_forty is not None: scount += 1 if one_forty_two is not None: scount += 1 if one_forty_four is not None: scount += 1 if one_forty_six is not None: scount += 1 if one_forty_eight is not None: scount += 1 #counting the request forms price if l200 is not None: pcount += 1 if l300 is not None: pcount += 1 if l400 is not None: pcount += 1 if l500 is not None: pcount += 1 if l600 is not None: pcount += 1 if g600 is not None: pcount += 1 # braqndssssssssssssssssssssssssssssssss fcount = 0 # using this to see how many brands have been placed in the query query = "SELECT * FROM snowbaord " if bcount or ccount or scount or pcount > 0: if fcount == 0: query += "WHERE " if bcount > 1: query += "(" # if there is more than one brand to be filtered if Burton is not None: # checking if the reqeust form is empty query += filterbrand(fcount, bcount, "brand = 'Burton'") fcount += 1 if Salomon is not None: query += filterbrand(fcount, bcount, "brand = 'Salomon'") fcount += 1 if Lib_Tech is not None: query += filterbrand(fcount, bcount, "brand = 'Lib_Tech'") fcount += 1 if Jones_Snowboards is not None: query += filterbrand(fcount, bcount, "brand = 'Jones_Snowboards'") fcount += 1 if Gnu is not None: query += filterbrand(fcount, bcount, "brand = 'Gnu'") fcount += 1 if bcount > 1: query += ")" # colorsssssssssssssssssssssss fcount = 0 # counting how many color have been put into the query if bcount >= 1: if ccount > 1: query += "AND (" #checks if there has been a brand and if there is more than one color if bcount == 0: if ccount > 1: query += "(" # if no brand but more that one color if yellow is not None: # checking weather form is empty or not query += filtercolor( lcount, bcount, ccount, "id =(select snowbaord_id from snowbaord_colour where colour_id =1) " ) lcount += 1 if blue is not None: query += filtercolor( lcount, bcount, ccount, "id =(select snowbaord_id from snowbaord_colour where colour_id =2) " ) lcount += 1 if orange is not None: query += filtercolor( lcount, bcount, ccount, "id =(select snowbaord_id from snowbaord_colour where colour_id =7) " ) lcount += 1 if pink is not None: query += filtercolor( lcount, bcount, ccount, "id =(select snowbaord_id from snowbaord_colour where colour_id =8) " ) lcount += 1 if other is not None: query += filtercolor( lcount, bcount, ccount, "id =(select snowbaord_id from snowbaord_colour where colour_id =3) " ) lcount += 1 if white is not None: query += filtercolor( lcount, bcount, ccount, "id =(select snowbaord_id from snowbaord_colour where colour_id =4) " ) lcount += 1 if black is not None: query += filtercolor( lcount, bcount, ccount, "id =(select snowbaord_id from snowbaord_colour where colour_id =5) " ) lcount += 1 if red is not None: query += filtercolor( lcount, bcount, ccount, "id =(select snowbaord_id from snowbaord_colour where colour_id =6) " ) lcount += 1 if ccount > 1: query += ")" print(query) #debug # sizesssssssssssssssssssssssssssssssss gcount = 0 if bcount or ccount >= 1: # checking if and is neccessary and brackets if scount > 1: query += "AND (" if one_forty is not None: # checking if the form is empty query += filtersize(bcount, ccount, scount, gcount, "size = 140 ") gcount += 1 if one_forty_two is not None: query += filtersize(bcount, ccount, scount, gcount, "size = 142 ") gcount += 1 if one_forty_four is not None: query += filtersize(bcount, ccount, scount, gcount, "size = 144 ") gcount += 1 if one_forty_six is not None: query += filtersize(bcount, ccount, scount, gcount, "size = 146 ") gcount += 1 if one_forty_eight is not None: query += filtersize(bcount, ccount, scount, gcount, "size = 148 ") gcount += 1 if bcount or ccount >= 1: if scount > 1: query += ")" # price kcount = 0 # counting if there has been a query if pcount > 0: if bcount or ccount or scount > 0: query += " AND " if g600 is not None: # checking if its not none query += filterprice(bcount, ccount, scount, gcount, "price > 600") gcount += 1 if g600 is None: if l600 is not None: if kcount == 0: query += "price <= 600" kcount += 1 if g600 or l600 is None: if l500 is not None: if kcount == 0: query += "price <= 500" kcount += 1 if g600 or l600 or l500 is None: if l400 is not None: if kcount == 0: query += "price <= 400" kcount += 1 if g600 or l600 or l500 or l400 is None: if l300 is not None: if kcount == 0: query += "price <= 300" kcount += 1 if g600 or l600 or l500 or l400 or l300 is None: if l200 is not None: if kcount == 0: query += "price <= 200" kcount += 1 print(query) #debug print(scount, gcount) #debug conn = sqlite3.connect('snowbaord.db') c = conn.cursor() c.execute(query) test = c.fetchall() conn.close() return render_template("gear_snowbaord.html", tests=test) return render_template('gear_snowbaord.html', tests=result)