Beispiel #1
0
def location_editor(response, id):
    context = {"error": None}
    location = Location.find_id(id)
    orig_name = location.name
    context["location"] = location
    if location is None:
        context["error"] = "Place does not exist"
        render_page("edit_location.html", response, context)
        return

    try:
        lat = float(response.get_field("lat"))
        lon = float(response.get_field("long"))
    except ValueError:
        context["error"] = "Invalid latitude or longitude"
        render_page("create_location.html", response, context)
        return
    name = response.get_field("name")
    if orig_name != name:
        if Location.find_name(name):
            context["error"] = "Place already exists"
            render_page("edit_location.html", response, context)
            return None

    description = response.get_field("description")
    address = response.get_field("address")
    Location.change_location(id, name, description, location.picture, address, lat, lon)
    response.redirect("/location/" + id)
Beispiel #2
0
def location_editor(response, id):
    # 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}
    location = Location.find_id(id)
    orig_name = location.name
    context["location"] = location
    if location is None:
        context["error"] = "Place does not exist"
        render_page("edit_location.html", response, context)
        return
    name = response.get_field("name")
    if orig_name != name:
        if Location.find_name(name):
            context["error"] = "Place already exists"
            render_page("edit_location.html", response, context)
            return None

    description = response.get_field("description")
    address = response.get_field("address")
    username = get_login(response)
    user = User.find(username)
    Location.change_location(id, name, description, location.picture, address, location.latitude, location.longitude)
    response.redirect("/location/" + id)