def biomePage(): monNames = db.session.query(User).filter_by( username=session["username"]).first().monNames if request.method == "GET": biomeIndex = biomeCheck(session["username"], db.session.query(DEXmon).all()) return render_template("biomes.html", biomeList=biomeList, biomeIndex=biomeIndex, monNames=monNames) elif request.method == "POST": if request.form["submit"] == "Go": if giveFullName(request.form["search"]) in monNames: return redirect( url_for("result", monName=giveFullName(request.form["search"]))) else: return render_template("biomes.html", monNames=monNames, error="Not found.") elif request.form["submit"] == "Update": monName = giveFullName(request.form["search"]) if session["username"] == BACKDOOR[0]: return redirect(url_for("result", monName=monName)) else: checklist = makeChecklist(request) if checklist != "" and monName in allMonNames: updateMon(monName, checklist) return redirect(url_for("result", monName=monName)) elif monName in allMonNames: return render_template("biomes.html", monNames=monNames, error="Select changes.") else: return render_template("biomes.html", monNames=monNames, error="Not found.") elif request.form["submit"] == "Home": return redirect(url_for("home")) elif request.form["submit"] == "Record": return redirect(url_for("recordChanges")) elif request.form["submit"] == "List": return redirect(url_for("dexList")) elif request.form["submit"] == "Map": return redirect(url_for("mapPage")) elif request.form["submit"] == "Type Chart": return redirect(url_for("typeChart")) elif request.form["submit"] == "Calculate": return redirect(url_for("calcPage")) elif request.form["submit"] == "Logout": return redirect(url_for("logout")) else: return "Error: Uncaught POST request, biomePage()"
def home(): monNames = db.session.query(User).filter_by( username=session["username"]).first().monNames if request.method == "GET": return render_template("home.html", monNames=monNames) elif request.method == "POST": if request.form["submit"] == "Go": monName = giveFullName(request.form["search"]) if monName in monNames: return redirect(url_for("result", monName=monName)) else: return render_template("home.html", monNames=monNames, errorGo="Not found.") elif request.form["submit"] == "Update": monName = giveFullName(request.form["searchUpdate"]) checklist = makeChecklist(request) if monName in allMonNames and checklist != "": updateMon(monName, checklist) return redirect(url_for("result", monName=monName)) elif monName in allMonNames: return render_template("home.html", monNames=monNames, errorUpdate="Select changes.") else: return render_template("home.html", monNames=monNames, errorUpdate="Not found.") elif request.form["submit"] == "List": return redirect(url_for("dexList")) elif request.form["submit"] == "Record": return redirect(url_for("recordChanges")) elif request.form["submit"] == "Map": return redirect(url_for("mapPage")) elif request.form["submit"] == "Biomes": return redirect(url_for("biomePage")) elif request.form["submit"] == "Type Chart": return redirect(url_for("typeChart")) elif request.form["submit"] == "Calculate": return redirect(url_for("calcPage")) elif request.form["submit"] == "Logout": return redirect(url_for("logout")) else: return "Error: Uncaught POST request, home()"
def calcPage(): monNames = db.session.query(User).filter_by( username=session["username"]).first().monNames if request.method == "GET": return render_template("calc.html", monNames=monNames, damage="0", draw="0") elif request.method == "POST": monName = giveFullName(request.form["search"]) if request.form["submit"] == "Go": if monName in monNames: return redirect(url_for("result", monName=monName)) else: return render_template("calc.html", monNames=monNames, damage="0", draw="0", error="Not found.") elif request.form["submit"] == "Update": checklist = makeChecklist(request) if monName in allMonNames and checklist != "": updateMon(monName, checklist) return redirect(url_for("result", monName=monName)) elif monName in allMonNames: return render_template("calc.html", monNames=monNames, damage="0", draw="0", error="Select changes.") else: return render_template("calc.html", monNames=monNames, damage="0", draw="0", error="Not found.") elif request.form["submit"] == "Calculate": if request.form["Atk"] == "" or request.form[ "Def"] == "" or request.form["Pwr"] == "" or ( request.form["Lvl"] == "" and request.form["lvl"] == "Manual"): return render_template( "calc.html", monNames=monNames, damage="0", draw="0", error="Must enter Atk, Def, Pwr, and Lvl") else: damage = calcDamage(request) draw = str(random.randint(1, 100)) return render_template("calc.html", monNames=monNames, damage=damage, draw=draw) elif request.form["submit"] == "Draw": draw = str(random.randint(1, 100)) return render_template("calc.html", monNames=monNames, damage="0", draw=draw) elif request.form["submit"] == "Home": return redirect(url_for("home")) elif request.form["submit"] == "Record": return redirect(url_for("recordChanges")) elif request.form["submit"] == "List": return redirect(url_for("dexList")) elif request.form["submit"] == "Map": return redirect(url_for("mapPage")) elif request.form["submit"] == "Type Chart": return redirect(url_for("typeChart")) elif request.form["submit"] == "Logout": return redirect(url_for("logout")) else: return "Error: Uncaught POST request calcPage()"
def dexList(): monNames = db.session.query(User).filter_by( username=session["username"]).first().monNames if request.method == "GET": if session["username"] == BACKDOOR[0]: return render_template("list.html", monNames=monNames, index=pickle.load(open("listIndex.p", "rb")), monList=pickle.load( open("listIndexKeys.p", "rb"))) else: dexIndex = prepareListIndex(session["username"], db.session.query(DEXmon).all()) return render_template("list.html", monNames=monNames, index=dexIndex[0], monList=dexIndex[1]) elif request.method == "POST": if request.form["submit"] == "Go" or request.form["submit"] == "Update": monName = giveFullName(request.form["search"]) if request.form["submit"] == "Go": if monName in monNames: return redirect(url_for("result", monName=monName)) else: if session["username"] == BACKDOOR[0]: return render_template( "list.html", monNames=monNames, index=pickle.load(open("listIndex.p", "rb")), monList=pickle.load(open("listIndexKeys.p", "rb")), error="Logged in as admin") else: dexIndex = prepareListIndex( session["username"], db.session.query(DEXmon).all()) return render_template("list.html", monNames=monNames, index=dexIndex[0], monList=dexIndex[1], error="Not found.") elif request.form["submit"] == "Update": if session["username"] == BACKDOOR[0]: return render_template( "list.html", monNames=monNames, index=pickle.load(open("listIndex.p", "rb")), monList=pickle.load(open("listIndexKeys.p", "rb")), error="Logged in as admin") else: checklist = makeChecklist(request) if checklist != "" and monName in allMonNames: updateMon(giveFullName(request.form["search"]), checklist) return redirect(url_for("result", monName=monName)) elif monName in allMonNames: dexIndex = prepareListIndex( session["username"], db.session.query(DEXmon).all()) return render_template("list.html", monNames=monNames, index=dexIndex[0], monList=dexIndex[1], error="Select changes.") else: dexIndex = prepareListIndex( session["username"], db.session.query(DEXmon).all()) return render_template("list.html", monNames=monNames, index=dexIndex[0], monList=dexIndex[1], error="Not found.") elif request.form["submit"] == "Filter": filters = makeFilters(request) if type(filters) == str: dexIndex = prepareListIndex(session["username"], db.session.query(DEXmon).all()) if "Move" in filters: return render_template("list.html", monNames=monNames, index=dexIndex[0], monList=dexIndex[1], errorFilter="Move not found.") elif "Ability" in filters: return render_template("list.html", monNames=monNames, index=dexIndex[0], monList=dexIndex[1], errorFilter="Ability not found.") else: return 'Error: Uncaught POST request, dexList(), request.form["submit"]=="Filter"' else: allUserMons = db.session.query(DEXmon).all() dexIndex = prepareListIndex( session["username"], allUserMons, filterMons(session["username"], filters, monNames, allUserMons)) return render_template("list.html", monNames=monNames, index=dexIndex[0], monList=dexIndex[1]) elif request.form["submit"] == "Home": return redirect(url_for("home")) elif request.form["submit"] == "Record": return redirect(url_for("recordChanges")) elif request.form["submit"] == "Map": return redirect(url_for("mapPage")) elif request.form["submit"] == "Type Chart": return redirect(url_for("typeChart")) elif request.form["submit"] == "Calculate": return redirect(url_for("calcPage")) elif request.form["submit"] == "Logout": return redirect(url_for("logout")) else: return "Error: Uncaught POST request, dexList()"
def recordChanges(): monNames = db.session.query(User).filter_by( username=session["username"]).first().monNames if request.method == "GET": return render_template("recordChanges.html", monNames=monNames) elif request.method == "POST": monName = request.form["searchUpdate"] if monName[-3:] == "mom": monName = monName[:-1] + "n" monName = giveFullName(monName) if request.form["submit"] == "Go": monName = giveFullName(request.form["search"]) if monName in monNames: return redirect(url_for("result", monName=monName)) else: return render_template("recordChanges.html", errorGo="Not found.") elif request.form["submit"] == "Update": if session["username"] == BACKDOOR[0]: return render_template("recordChanges.html", monNames=monNames) else: checklist = makeChecklist(request) if monName in allMonNames and checklist != "": updateMon(monName, checklist) return render_template("recordChanges.html", monNames=monNames) elif monName in allMonNames: return render_template("recordChanges.html", monNames=monNames, errorUpdate="Select changes.") else: return render_template("recordChanges.html", monNames=monNames, errorUpdate="Not found.") elif request.form["submit"] == "Clear": if session["username"] == BACKDOOR[0]: return render_template("recordChanges.html", monNames=monNames, errorUpdate="What are you doing?") else: if monName in allMonNames: clearStatus(monName) return render_template("recordChanges.html", monNames=monNames) else: return render_template("recordChanges.html", monNames=monNames, errorUpdate="Not found.") elif request.form["submit"] == "Home": return redirect(url_for("home")) elif request.form["submit"] == "List": return redirect(url_for("dexList")) elif request.form["submit"] == "Map": return redirect(url_for("mapPage")) elif request.form["submit"] == "Type Chart": return redirect(url_for("typeChart")) elif request.form["submit"] == "Calculate": return redirect(url_for("calcPage")) elif request.form["submit"] == "Logout": return redirect(url_for("logout")) else: return "Error: Uncaught POST request, recordChanges()"
def result(monName ): #If redirect here, monName must be in monNames and a FullName monNames = db.session.query(User).filter_by( username=session["username"]).first().monNames if request.method == "GET": monName = giveFullName(monName) if monName in monNames: session[ "lastResult"] = monName #session["lastResult"] would make more sense as pageIndex, possible? status = db.session.query(DEXmon).filter_by( fullName=monName).first().status[session["username"]] pageIndex = pageMake.createPokepage(index[giveIndexNum(monName)], monNames, session["username"], status) return render_template("monTemplate.html", monNames=monNames, pageIndex=pageIndex) else: return redirect(url_for("home")) if request.method == "POST": monName = giveFullName(request.form["search"]) if request.form["submit"] == "Go": if monName in monNames: session["lastResult"] = monName status = db.session.query(DEXmon).filter_by( fullName=monName).first().status[session["username"]] pageIndex = pageMake.createPokepage( index[giveIndexNum(monName)], monNames, session["username"], status) return redirect(url_for("result", monName=monName)) else: status = db.session.query(DEXmon).filter_by( fullName=monName).first().status[session["username"]] pageIndex = pageMake.createPokepage( index[giveIndexNum(session["lastResult"])], monNames, session["username"], status) return render_template("monTemplate.html", monNames=monNames, pageIndex=pageIndex, error="Not found.") elif request.form["submit"] == "Update": if session["username"] == BACKDOOR[0]: pageIndex = pageMake.createPokepage( index[giveIndexNum(session["lastResult"])], monNames, session["username"], "SABC") return render_template("monTemplate.html", monNames=monNames, pageIndex=pageIndex) else: checklist = makeChecklist(request) if checklist != "" and monName in allMonNames: updateMon(monName, checklist) status = db.session.query(DEXmon).filter_by( fullName=monName).first().status[session["username"]] pageIndex = pageMake.createPokepage( index[giveIndexNum(monName)], monNames, session["username"], status) return render_template("monTemplate.html", monNames=monNames, pageIndex=pageIndex) elif checklist != "" and request.form["search"] == "": updateMon(session["lastResult"], checklist) status = db.session.query(DEXmon).filter_by( fullName=session["lastResult"]).first().status[ session["username"]] pageIndex = pageMake.createPokepage( index[giveIndexNum(session["lastResult"])], monNames, session["username"], status) return render_template("monTemplate.html", monNames=monNames, pageIndex=pageIndex) elif checklist != "" or (checklist == "" and monName not in allMonNames): status = db.session.query(DEXmon).filter_by( fullName=session["lastResult"]).first().status[ session["username"]] pageIndex = pageMake.createPokepage( index[giveIndexNum(session["lastResult"])], monNames, session["username"], status) return render_template("monTemplate.html", monNames=monNames, pageIndex=pageIndex, error="Not found.") elif monName in allMonNames: status = db.session.query(DEXmon).filter_by( fullName=session["lastResult"]).first().status[ session["username"]] pageIndex = pageMake.createPokepage( index[giveIndexNum(session["lastResult"])], monNames, session["username"], status) return render_template("monTemplate.html", monNames=monNames, pageIndex=pageIndex, error="Select changes.") else: return 'Error: Uncaught POST request, result(), request.form["submit"]="Update"' elif request.form["submit"] == "Home": return redirect(url_for("home")) elif request.form["submit"] == "List": return redirect(url_for("dexList")) elif request.form["submit"] == "Record": return redirect(url_for("recordChanges")) elif request.form["submit"] == "Map": return redirect(url_for("mapPage")) elif request.form["submit"] == "Type Chart": return redirect(url_for("typeChart")) elif request.form["submit"] == "Calculate": return redirect(url_for("calcPage")) elif request.form["submit"] == "Logout": return redirect( url_for("logout") ) #create a switchboard method in order to get rid of this madness? else: return "Error: Uncaught POST request, result()"