Beispiel #1
0
def missing_venues(request):
  venue_map_f = """
  function() {
    emit(this.venue.url, this.venue)
  }
  """

  reduce_f = """
  function(k, vals) {
    return vals[0];
  }
  """

  venue_map = { }

  for venue_doc in Show.objects.map_reduce(venue_map_f, reduce_f):
    venue_map[venue_doc.key] = venue_doc.value

  for venue in Venue.objects():
    if venue.url in venue_map:
      del venue_map[venue.url]

  venues = venue_map.values()

  venues.sort(lambda x,y: cmp(x['name'], y['name']))

  return render_to_response('fancy_admin/missing_venues.html', {'venues': venues})
Beispiel #2
0
    def shows(self):
        if not self._shows:
            range_filter = ShowDateRangeFilter(self.start_date, self.end_date)

            shows = range_filter.apply(Show.objects)

            venues = []

            if self.venue:
                venues.append(self.venue)
            elif self.location:
                if self.location.get("neighborhood"):
                    in_location = (
                        lambda v: self.location["city"].slug == v.city
                        and self.location["neighborhood"].slug == v.neighborhood
                    )
                else:
                    in_location = lambda v: self.location["city"].slug == v.city

                venues.extend(filter(in_location, Venue.objects()))

            if venues:
                shows = shows.filter(venue__url__in=[v.url for v in venues])

            shows.order_by("-rank")

            self._shows = list(shows)

        return list(self._shows)
Beispiel #3
0
    def load_venues(self, venue_file):      
      parser = CSVParser(venue_file)
      
      Venue.objects().delete()

      for record in parser:
        copy_over = ('name', 'url', 'address', 'city', 'neighborhood')
        
        v_map = { }
        
        if record.get('lat') and record.get('long'):
          v_map['location'] = [float(record.get('lat')), float(record.get('long'))]
        
        for field in copy_over:
          v_map[field] = record[field]
          
        v_map['normalized_name'] = normalize(v_map['name'])
        
        print v_map['name']
        
        v = Venue(**v_map)
        
        v.save()
Beispiel #4
0
def show_list(request, shows, template, context):
    today = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
    tomorrow = today + timedelta(days=1)

    artist_map = {}
    artist_to_show = {}
    venue_map = dict((v.url, v) for v in Venue.objects())
    venues = venue_map.values()

    venues.sort(key=lambda v: v.name.lower())

    for show in shows:
        for info in filter(lambda x: x.artist_id, show.artists):
            if info.artist_id not in artist_map:
                artist_to_show[info.artist_id] = {"artist": None, "shows": []}

            artist_to_show[info.artist_id]["shows"].append(show)
            artist_map[info.artist_id] = True

    if artist_map:
        artist_map = Artist.objects.in_bulk(artist_map.keys())

        for artist_id, artist_info in artist_to_show.iteritems():
            artist_info["artist"] = artist_map[artist_id]

    saved_shows = {}

    if request.user.is_authenticated():
        saved_shows = request.user.starred_show_set.get_id_dict()

    artists = artist_to_show.values()

    artists.sort(key=lambda i: i["artist"].name.lower().strip(" \r\n"))

    context.update(
        {
            "today": today,
            "tomorrow": tomorrow,
            "shows": shows,
            "artist_map": artist_map,
            "artists": artists,
            "venue_map": venue_map,
            "venues": venues,
            "hot_ranking": settings.ARTIST_HOT_RANKING,
            "saved_shows": saved_shows,
        }
    )

    return render_to_response(template, RequestContext(request, context))
Beispiel #5
0
def show_details(request, venue, year, month, day, artist):
    venue = Venue.objects.get(slug=venue)
    day = datetime(int(year), int(month), int(day))
    today = datetime.today()
    look_until = today + timedelta(days=30)

    matching_shows = Show.objects(venue__url=venue.url, date=day)
    show = None

    for prospect in matching_shows:
        if prospect.slug() == artist:
            show = prospect

            break

    if not show:
        return show_list(request, matching_shows, "fancy_main/shows_at_venue.html", {"venue": venue, "day": day})

    artist_ids = {}
    artist_map = {}
    artists = []
    shows_by_artist = {}

    for info in filter(lambda x: x.artist_id, show.artists):
        if info.artist_id not in artist_map:
            artist_ids[info.artist_id] = True

    if artist_ids:
        show_range = Q(date__gte=today) & Q(date__lte=look_until)
        artist_shows = (
            Show.objects(artist_ids__in=artist_ids.keys(), id__ne=show.id).filter(show_range).order_by("date")
        )

        for artist_show in artist_shows:
            for info in filter(lambda x: x.artist_id, artist_show.artists):
                if info.artist_id not in shows_by_artist:
                    shows_by_artist[info.artist_id] = []

                shows_by_artist[info.artist_id].append(artist_show)

        artist_map = Artist.objects.in_bulk(artist_ids.keys())

    for artist_info in show.artists:
        artists.append(
            {
                "info": artist_info,
                "artist": artist_map.get(artist_info.artist_id),
                "shows": shows_by_artist.get(artist_info.artist_id, []),
            }
        )

    venues = list(Venue.objects())

    saved_shows = {}

    if request.user.is_authenticated():
        saved_shows = request.user.starred_show_set.get_id_dict()

    context = {
        "show": show,
        "shows": [show],
        "artists": artists,
        "venue": Venue.objects.get(url=show.venue.url),
        "venues": venues,
        "saved_shows": saved_shows,
    }

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