def home(): sn = request.forms.get('spotNumber') hl = request.forms.get('headline') org = request.forms.get('organization') desc = request.forms.get('description') pw = request.forms.get('password') img_url = request.forms.get('image_url') #img = uploadImage(img_url) if isValidSpot(sn): snInt = int(sn) snInt = str(snInt) snDatabase = Occupant.get_by_id(snInt) if snDatabase == None: occupant = Occupant(id = snInt, headline = hl, description = desc, date_time = datetime.datetime.now(), spot_id = snInt, organization = org, spot_image = img_url, password = pw, report = 0) occupant.put() time.sleep(2) response.set_cookie("submittedForm", "yes") redirect('/') else: header = template('header', home="", vendor="active", edit="", about="") content = template('vendor', message = "*Sorry, the Spot Number entered has already been taken.*", sn = "", hl = hl, org = org, desc = desc, pw = pw) footer = template('footer',"") return header + content + footer else: header = template('header', home="", vendor="active", edit="", about="") content = template('vendor', message = "*Sorry, the spot number must be a valid spot number.*", sn = "", hl = hl, org = org, desc = desc, pw = pw) footer = template('footer',"") return header + content + footer
def home(): o1 = Occupant(id = "1", headline = "Selling chicken nuggets!", description = "Chicken nuggets! 5 for $1", date_time = datetime.datetime.now(), spot_id = "1", organization = "Circle K", spot_image = "", password = "", report = 0) o2 = Occupant(id = "2", headline = "Free drinks!", description = "Answer a simple survey to get a free drink!", date_time = datetime.datetime.now(), spot_id = "2", organization = "Mahjong Club", spot_image = "", password = "", report = 0) o3 = Occupant(id = "3", headline = "Resume Critque", description = "Stop by to get your resume up in shape!", date_time = datetime.datetime.now(), spot_id = "3", organization = "Career Center", spot_image = "", password = "", report = 0) o4 = Occupant(id = "76", headline = "Study at our Booth!", description = "Come study with us at our booth and learn about stuff!", date_time = datetime.datetime.now(), spot_id = "76", organization = "Study Club", spot_image = "", password = "", report = 0) o5 = Occupant(id = "233", headline = "Boats", description = "Boats, Boats BOATS!!!", date_time = datetime.datetime.now(), spot_id = "233", organization = "Touch the Boat", spot_image = "", password = "", report = 0) o6 = Occupant(id = "314", headline = "Don't Smile at Strangers", description = "Have you ever wanted to see what goes on behind the Don't Smile at Strangers group meetings? Come by to find out! We're always happy to show you!", date_time = datetime.datetime.now(), spot_id = "314", organization = "INFX 151", spot_image = "", password = "", report = 0) o7 = Occupant(id = "106", headline = "ASUCI Elections", description = "Vote today!", date_time = datetime.datetime.now(), spot_id = "106", organization = "ASUCI", spot_image = "", password = "", report = 0) o1.put() o2.put() o3.put() o4.put() o5.put() o6.put() o7.put() return "Occupant Data successfully added!"
def home(): #if the user has not submitted the new editted form, it will enter this branch if request.get_cookie("edittingForm") == "no": sn = request.forms.get('spotNumber') pw = request.forms.get('password') if isValidSpot(sn): #gets rid of leading 0s snInt = int(sn) snInt = str(snInt) snDatabase = Occupant.get_by_id(snInt) if snDatabase == None: header = template('header', home="", vendor="", edit="active", about="") content = template('edit', message="*The entered Spot Number has not been reserved yet.") footer = template('footer',"") return header + content + footer else: if snDatabase.password == pw: #if the user chose to delete a spot, here they go! if request.forms.get("delete") == "Delete Spot": spot = Occupant.get_by_id(snInt) spot.key.delete() response.set_cookie("deleted", "yes") time.sleep(2) redirect('/') else: response.set_cookie("edittingForm", "yes") snInt = int(sn) snInt = str(snInt) response.set_cookie("originalSN", snInt) hl = snDatabase.headline org = snDatabase.organization desc = snDatabase.description header = template('header', home="", vendor="", edit="active", about="") content = template('vendor', message = "Spot Information has been loaded!", sn = sn, hl = hl, org = org, desc = desc, pw = pw) footer = template('footer',"") return header + content + footer else: header = template('header', home="", vendor="", edit="active", about="") content = template('edit', message="*Invalid Password") footer = template('footer',"") return header + content + footer else: header = template('header', home="", vendor="", edit="active", about="") content = template('edit', message = "*Sorry, the spot number must be a valid spot number.*") footer = template('footer',"") return header + content + footer #if the user has submitted a new editted spot form it will enter this branch #this branch is basically the check in vnedor that validates input else: sn = request.forms.get('spotNumber') hl = request.forms.get('headline') org = request.forms.get('organization') desc = request.forms.get('description') pw = request.forms.get('password') img_url = request.forms.get('image_url') if isValidSpot(sn): snInt = int(sn) snInt = str(snInt) snDatabase = Occupant.get_by_id(snInt) if snDatabase == None or snInt == str(request.get_cookie("originalSN")): occupant = Occupant(id = snInt, headline = hl, description = desc, date_time = datetime.datetime.now(), spot_id = snInt, organization = org, spot_image = img_url, password = pw, report = 0) occupant.put() #if the new spot number does not exist that means that changed the spot number #so the old can be deleted because it is being replaced if snDatabase == None: oldSpot = Occupant.get_by_id(str(request.get_cookie("originalSN"))) oldSpot.key.delete() response.set_cookie("edittingForm", "no") response.set_cookie("originalSN", "no") time.sleep(2) response.set_cookie("submittedForm", "yes") redirect('/') else: header = template('header', home="", vendor="", edit="active", about="") content = template('vendor', message = "*Sorry, the Spot Number entered has already been taken.*", sn = "", hl = hl, org = org, desc = desc, pw = pw) footer = template('footer',"") return header + content + footer else: header = template('header', home="", vendor="", edit="active", about="") content = template('vendor', message = "*Sorry, the spot number must be a valid spot number.*", sn = "", hl = hl, org = org, desc = desc, pw = pw) footer = template('footer',"") return header + content + footer