def add_spot(request): """ View to add a new spot to upspot. """ if request.method == 'GET': spots = Spot.objects.filter(owner=request.user) return render(request, 'park/spot.html', {'spots': spots}) elif request.method == 'POST': owner = request.user lat = float(request.POST.get("lat")) lng = float(request.POST.get("lng")) sv_lat = float(request.POST.get("sv_lat")) sv_lng = float(request.POST.get("sv_lng")) address = request.POST.get("address") spot_number = request.POST.get("spot_number") instructions = request.POST.get("instructions") new_spot = Spot() new_spot.owner = owner new_spot.location = Point(lng, lat) new_spot.sv_location = Point(sv_lng, sv_lat) new_spot.address = address new_spot.spot_number = spot_number new_spot.instructions = instructions new_spot.save() # Find geohash to get grid value and retrieve geobucket. spot_geohash = geohash_encode(lat, lng)[:6] geobucket, _ = GeoBucket.objects.get_or_create(geohash=spot_geohash) # Add a spot to the given geobucket and save. geobucket.spot() geobucket.save() return redirect('/park/spots')
def load_spots(self): spots_data = self.__read_csv("spots") localized_spots_data = self.__read_csv("spots_localized") #load content self.spots = {} for item in spots_data: s = Spot() self.__fill_members_with_csv_data( s, ('spot_id', 'name', 'image', 'category', 'location', 'content', 'tags'), item) s.tags = s.tags.split(',') #split tags s.location = s.location.split(',') #split location s.category = int(s.category) #parse category to int self.spots[s.spot_id] = s #add to spots #load localized info for item in localized_spots_data: lang = LocalizedSpotInformation() self.__fill_members_with_csv_data( lang, ('spot_id', 'language', 'display_name', 'description'), item) #add to right content if self.spots.has_key(item[0]): self.spots[item[0]].localized_information[item[1]] = lang else: logging.warn("Localized Spot Data with invalid spot id: " + item[0])
def load_spots(self): spots_data = self.__read_csv("spots") localized_spots_data = self.__read_csv("spots_localized") #load content self.spots = {} for item in spots_data: s = Spot() self.__fill_members_with_csv_data(s,('spot_id','name','image','category','location','content','tags'),item) s.tags = s.tags.split(',') #split tags s.location = s.location.split(',') #split location s.category = int(s.category) #parse category to int self.spots[s.spot_id] = s #add to spots #load localized info for item in localized_spots_data: lang = LocalizedSpotInformation() self.__fill_members_with_csv_data(lang,('spot_id','language','display_name','description'),item) #add to right content if self.spots.has_key(item[0]): self.spots[item[0]].localized_information[item[1]] = lang else: logging.warn("Localized Spot Data with invalid spot id: " + item[0])