Exemple #1
0
    def load_cities(self, city_file):
      parser = CSVParser(city_file)

      City.objects().delete()
      
      city_map = { }

      for record in parser:
        LOG.debug(record)
        city, city_slug = record.get('city'), record.get('city slug')

        if city_slug not in city_map:
          city_map[city_slug] = {
            'city':          City(name = city, slug = city_slug),
            'neighborhoods': { }
          }
          
        city_map[city_slug]['neighborhoods'][record.get('neighborhood slug')] = record.get('neighborhood')
        
      for city_info in city_map.values():
        city = city_info['city']
        
        neighborhoods = [Neighborhood(name = name, slug = slug) for slug, name in city_info['neighborhoods'].iteritems()]

        neighborhoods.sort(key = lambda n: n.name)

        city.neighborhoods = neighborhoods
        
        LOG.debug("Saving neighborhoods for city: %s - %s: %s" % (city.name, city.slug, city_info['neighborhoods']))

        city.save()
Exemple #2
0
def venues(request):
    neighborhood_map = {}

    today = datetime.now().date()

    show_context = ShowContext(today, today)

    shows_by_venue = {}

    for show in show_context.shows:
        if not show.venue.url in shows_by_venue:
            shows_by_venue[show.venue.url] = []

        shows_by_venue[show.venue.url].append(show)

    for v in Venue.objects.order_by("name"):
        key = (v.city, v.neighborhood)

        if key not in neighborhood_map:
            neighborhood_map[key] = []

        neighborhood_map[key].append({"venue": v, "shows": shows_by_venue.get(v.url, [])})

    cities = []

    for city in City.objects():
        city_info = {"city": city, "neighborhoods": []}

        cities.append(city_info)

        for neighborhood in city.neighborhoods:
            city_info["neighborhoods"].append(
                {"neighborhood": neighborhood, "venues": neighborhood_map.get((city.slug, neighborhood.slug), [])}
            )

    context = {"cities": cities}

    return render_to_response("fancy_main/venues.html", RequestContext(request, context))