def update_attraction(id): name = request.form["name"] cost = request.form["cost"] city_id = request.form["city_id"] city = city_repository.select(city_id) attraction = Attraction(name, cost, city, id) attraction_repository.update(attraction) return redirect(f"/attractions/{id}")
def create_attraction(): name = request.form["name"] cost = request.form["cost"] city_id = request.form["city"] city = city_repository.select(city_id) attraction = Attraction(name, cost, city) attraction_repository.save(attraction) return redirect("/attractions")
def update_attraction(id): name = request.form['name'] land_id = request.form['land_id'] visited = request.form['visited'] notes = request.form['notes'] land = land_repository.select(land_id) attraction = Attraction(name, land, visited, notes, id) attraction_repository.update(attraction) attraction_repository.update_land(attraction) return redirect("/attractions")
def create_attraction(): name = request.form['name'] land_id = request.form['land_id'] visited = request.form['visited'] notes = request.form['notes'] land = land_repository.select(land_id) attraction = Attraction(name, land, visited, notes) attraction_repository.save(attraction) attraction_repository.update_land(attraction) return redirect("/still_to_see")
def select(id): attraction = None sql = "SELECT * FROM attractions WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: land = land_repository.select(result['land_id']) attraction = Attraction(result['name'], land, result['visited'], result['notes'], result['id']) return attraction
def select_attraction_by_city(id): attractions = [] sql = "SELECT * FROM attractions WHERE city_id = %s" values = [id] results = run_sql(sql, values) for row in results: city = city_repository.select(row['city_id']) attraction = Attraction(row['name'], row['cost'], city, row['id']) attractions.append(attraction) return attractions
def select(id): attraction = None sql = "SELECT * FROM attractions WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: city = city_repository.select(result['city_id']) attraction = Attraction(result['name'], result['cost'], city, result['id']) return attraction
def select_all(): attractions = [] sql = "SELECT * FROM attractions" results = run_sql(sql) for row in results: land = land_repository.select(row['land_id']) attraction = Attraction(row['name'], land, row['visited'], row['notes'], row['id']) attractions.append(attraction) return attractions
def select_all(): attractions = [] # I WANT TO ORDER THE ATTRACTIONS BY CITY sql = "SELECT * FROM attractions" # ORDER BY city.id" results = run_sql(sql) for row in results: city = city_repository.select(row['city_id']) attraction = Attraction(row['name'], row['cost'], city, row['id']) attractions.append(attraction) return attractions
country_repository.save(america) peru = Country("Peru", "South America") country_repository.save(peru) paris = City("Paris", france) city_repository.save(paris) rome = City("Rome", italy) city_repository.save(rome) venice = City("Venice", italy) city_repository.save(venice) new_york_city = City("New York City", america) city_repository.save(new_york_city) lima = City("Lima", peru) city_repository.save(lima) eiffel_tower = Attraction("Eiffel Tower", 25.90, paris) attraction_repository.save(eiffel_tower) the_louvre = Attraction("The Louvre", 17, paris) attraction_repository.save(the_louvre) the_colosseum = Attraction("The colosseum", 12, rome) attraction_repository.save(the_colosseum) st_marks_basilica = Attraction("Saint Mark's Basilica", 3, venice) attraction_repository.save(st_marks_basilica) central_park = Attraction("Central Park", 0, new_york_city) attraction_repository.save(central_park) natural_history_mueseum = Attraction("Natural History Museum", 23, new_york_city) attraction_repository.save(natural_history_mueseum) huaca_pucllana = Attraction("Huaca Pucllana", 15, peru) attraction_repository.save(huaca_pucllana)
land_repository.delete_all() park_repository.delete_all() park1 = Park("Disneyland Park") park_repository.save(park1) park2 = Park("Walt Disney Studios Park") park_repository.save(park2) land1 = Land("Fantasyland", park1, True) land_repository.save(land1) land2 = Land("Discoveryland", park1, False) land_repository.save(land2) land3 = Land("Toon Studio", park2, False) land_repository.save(land3) land4 = Land("Adventureland", park1, False) land_repository.save(land4) land5 = Land("Production Courtyard", park2, False) land_repository.save(land5) attraction1 = Attraction("It's a small world", land1, True, "So cute! Song in my head forver now!!") attraction_repository.save(attraction1) attraction2 = Attraction("Space Mountain", land2, False, "Bit scared! Hope it's not too fast!!!") attraction_repository.save(attraction2) attraction3 = Attraction("Peter Pan's Flight", land1, False, "So excited I could cry!!!") attraction_repository.save(attraction3) attraction4 = Attraction("Crush's Coaster", land3, False, "Looks awesome, dude!") attraction_repository.save(attraction4)
def createAttraction(self, key, attractionData): from google.appengine.api import users from django.utils import simplejson import urllib, md5 user = users.get_current_user() if type(user) == users.User: attractionData['userid'] = self.getUserId(user.email()) attractionData['username'] = user.nickname() else: attractionData['userid'] = None attractionData['username'] = self.request.remote_addr region = 'Unknown location' url = "http://maps.google.com/maps/geo?q=%.2f,%.2f&sensor=false" % ( float(attractionData['location']['lat']), float(attractionData['location']['lon'])) jsonString = urllib.urlopen(url).read() if jsonString: data = simplejson.loads(jsonString) for placemark in data['Placemark']: region = ", ".join(self.getLocationName(placemark)) if region: break if key: oldAttraction = db.get(key) attractionData['root'] = oldAttraction.root attractionData['previous'] = oldAttraction.id attractionData['free'] = oldAttraction.free attractionData['rating'] = oldAttraction.rating attractionData['free'] = oldAttraction.free else: oldAttraction = None attractionData['root'] = None attractionData['previous'] = None attractionData['free'] = True attractionData['rating'] = 0 attractionData['free'] = True if not attractionData['free']: import difflib s = difflib.SequenceMatcher(None, oldAttraction.description, attractionData['description']) if s.ratio() < 0.5: attractionData['free'] = True newAttraction = Attraction( parent=oldAttraction, root=attractionData['root'], previous=attractionData['previous'], name=attractionData['name'], region=region, description=attractionData['description'], location=db.GeoPt(lat=attractionData['location']['lat'], lon=attractionData['location']['lon']), geobox=str(round(float(attractionData['location']['lat']), 1)) + ',' + str(round(float(attractionData['location']['lon']), 1)), href=attractionData['href'], picture=attractionData['picture'], tags=attractionData['tags'], free=attractionData['free'], rating=attractionData['rating'], userid=attractionData['userid'], username=attractionData['username']) newAttraction.id = md5.new(unicode(newAttraction)).hexdigest() if not newAttraction.root: newAttraction.root = newAttraction.id newAttraction.put() if oldAttraction: oldAttraction.next = newAttraction.id oldAttraction.put() return newAttraction
def setUp(self): self.country = Country("France", "Europe") self.city = City("Paris", self.country) self.attraction = Attraction("Eiffel Tower", 25.90, self.city)
def post(self): n = int(self.request.get('n')) l = 50 f = self.request.get('f') import csv csvReader = csv.reader(open('attractions' + f + '.csv')) count = 1 for row in csvReader: if count >= n and count < n + l: q = Attraction.all() q.filter("id =", row[0]) if q.count() > 1: attractions = q.fetch(100) for attraction in attractions: attraction.delete() attraction = None else: attraction = q.get() if not attraction: location = row[1].split(',') if row[7] == 'y': freeVal = True else: freeVal = False name = row[2].decode('utf-8').replace("\n", ' ') if name == '': name = 'No name' try: newAttraction = Attraction( id=row[0], root=row[0], name=name, region=row[6].decode('utf-8').replace("\n", ' '), description=row[3].decode('utf-8'), location=db.GeoPt(lat=location[0], lon=location[1]), geobox=str(round(float(location[0]), 1)) + ',' + str(round(float(location[1]), 1)), href=row[4].decode('utf-8'), picture=row[5].decode('utf-8'), free=freeVal, datetime=datetime.datetime( year=int(row[8][0:4]), month=int(row[8][5:7]), day=int(row[8][8:10]), hour=int(row[8][11:13]), minute=int(row[8][14:16]), second=int(row[8][17:19]))) newAttraction.put() except db.BadValueError: pass elif count >= n: taskqueue.add(url='/import', params={'n': n + l, 'f': f}) break count = count + 1 if f < 4: taskqueue.add(url='/import', params={'n': n + l, 'f': f + 1})