def add_location(data, location_key=""): if location_key: location = Location.get_by_id(location_key) else: location_id = slugify(data["name"]) temp_location_id = location_id while True: count = 1 if Location.get_by_id(temp_location_id): temp_location_id = location_id + str(count) count += 1 else: location = Location(id=temp_location_id) break if data["name"]: location.name = data["name"] if data["needs"]: location.needs = data["needs"] if data["centers"]: location.centers = data["centers"] if data["latlong"]: location.latlong = data["latlong"] if data["featured_photo"]: location.featured_photo = data["featured_photo"] if data["death_count"]: location.death_count = int(data["death_count"]) if data["death_count_text"]: location.death_count_text = data["death_count_text"] if data["affected_count"]: location.affected_count = int(data["affected_count"]) if data["affected_count_text"]: location.affected_count_text = data["affected_count_text"] if data["status_board"]: location.status_board = data["status_board"] if data["needs"]: location.needs = data["needs"] if data["status"]: location.status = data["status"] if data["images"]: location.images = data["images"] if data["hash_tag"]: location.hash_tag = data["hash_tag"] location.put() return location