def place(request, place_id): place = get_object_or_404(Place, pk=place_id) # Save position if request.method == 'POST': p = geojson.Point([request.POST['lat'], request.POST['lng']]) place.geojson = geojson.dumps(p) place.find_subways() # Update subways place.find_city() # Update city place.save() # Find address af = AddressFinder(place.address, place.city) res = af.search() return { 'place' : place, 'results' : res, 'point' : place.get_point(), }
def process_item(self, item, spider): # Check we don't already have this bar or this address # A bit dummy ... :/ bars = Place.objects.filter(name__icontains=item['name']) if len(bars) > 0: raise DropItem('Existing bar by name') bars = Place.objects.filter(address=item['address']) if len(bars) > 0: raise DropItem('Existing bar by address') # This is a bar item['type'] = 'bar' # Lookup real city item['city'], _ = City.objects.get_or_create(name=item['city']) # Add creator item['creator'] = self._creator # Search a geocoded position af = AddressFinder(item['address'], item['city']) res = af.search() from pprint import pprint if len(res) == 0: raise DropItem('No position found') pos = res[0] p = geojson.Point([pos['lat'], pos['lon']]) item['geojson'] = geojson.dumps(p) # Find subways & city place = item.save() place.find_subways() place.find_city() place.save() return item