def location_creator(response): file_input = response.get_file("picture") filename_hash = hashlib.sha1(file_input[2]).hexdigest() file_output = open("./static/place-images/{}".format(filename_hash), "wb") file_output.write(file_input[2]) file_output.close() context = {"error": None} name = response.get_field("name") description = response.get_field("description") address = response.get_field("address") username = get_login(response) user = User.find(username) try: lat = float(response.get_field("lat")) long = float(response.get_field("long")) except ValueError: context["error"] = "Invalid latitude or longitude" render_page("create_location.html", response, context) return if Location.find_name(name): context["error"] = "Place already exists" render_page("create_location.html", response, context) else: Location.create(name, description, filename_hash, user.id, address, lat, long) response.redirect("/location/{}".format(Location.find_name(name).id)) tags = response.get_field("tags").split(",") if tags == [""]: tags = [] for tag in tags: Tag.create_tag(tag, Location.find_name(name).id) return
def location_handler(response, id): logged_in = get_login(response) context = {} user_object = User.find(get_login(response)) location = Location.find_id(id) loc_tags = Tag.find_from_place(location.id) if logged_in: stars = location.get_user_rating(user_object.id) context["user_rating"] = stars if location: context["location"] = location context["loc_tags"] = loc_tags context["comments"] = Comment.find_place(location.id) render_page("location.html", response, context) else: error_handler(response)