def show(self, id, list_all=0): try: a = Artist.get(id) except SQLObjectNotFound: flash("Artist ID not found") util.redirect("/artists/list") except ValueError: try: a = Artist.byNameI(urllib.unquote_plus(id)) except SQLObjectNotFound: flash("Artist ID not found") util.redirect("/artists/list") if identity.current.user and a in identity.current.user.artists: is_tracked = True else: is_tracked = False past_events = a.events.filter(Event.q.date < date.today()).orderBy('-date') if not list_all: past_events = past_events[:5] future_events = a.events.filter(Event.q.date >= date.today()).orderBy('date') return dict(artist=a, past_events=past_events, future_events=future_events, tracked_count=a.users.count(), is_tracked=is_tracked, description=util.desc_format(a.description), artist_list=artist_list)
def lastfm_artist_update(artist): artist_info = lastfm.artist_info(artist.name) artist.img_url = artist_info["img_url"] artist.tags = artist_info["tags"] sims_objs = [] sims_names = artist_info["similars"] for artist_name in sims_names: try: sim_artist = Artist.byNameI(artist_name) except SQLObjectNotFound: # keep out too-short names if len(artist_name) < 3: continue try: sim_artist = Artist(name=artist_name, added_by=UserAcct.get(1)) except SQLObjectIntegrityError: print "trying to add '%s'" % artist_name hub.rollback() hub.begin() # Artists added this way are *not* approved. This keeps them from # also having sims generated (when they could be non-local bands # that we really don't care much about.) # If they have events approved, then of course they are, too. sims_objs.append(sim_artist) artist.similars = sims_objs
def artists_clean(self, artists): artists = [self.artist_name_fix(a) for a in artists] # prev line may result in blank artist names artists = [a for a in artists if len(a)] # break all "john foo & susan bar" into separate artists, if "john foo" # already exists in the db for artist in artists: if artist.find("&") != -1: artist1, artist2 = artist.split("&", 1) try: if not len(artist1.strip()): continue a = Artist.byNameI(artist1) yield artist1.strip() yield artist2.strip() except SQLObjectNotFound: yield artist else: yield artist
def import_to_db(self, event): flag_for_review = False venue_name = self.venue_name_fix(event['venue']['name']) try: v = Venue.byNameI(venue_name) except SQLObjectNotFound: v = Venue(name=venue_name, added_by=identity.current.user) flag_for_review = True if event['venue'].has_key('phone'): phone = event['venue']['phone'] if not len(phone) >= 8: phone = "503-" + phone p = validators.PhoneNumber() try: event['venue']['phone'] = p.to_python(phone) except: event['venue']['phone'] = None self._set_optional_fields(v, event['venue'], ("address", "phone", "zip_code", "url", "description")) event_name = self.event_name_fix(event['name']) event_date = event["date"] event_time = event.get("time") if event_time: event_time = event_time.lower() # check same venue, date, time db_events = Event.selectBy(date=event_date, time=event_time, venue=v) if db_events.count(): e = db_events[0] new_event = False else: # no time? still could be skippable, if event name is the same db_events = Event.selectBy(date=event_date, name=event_name, venue=v) if db_events.count(): e = db_events[0] new_event = False else: e = Event(venue=v, name=event_name, date=event_date, time=event_time, added_by=identity.current.user) new_event = True try: s = Source.byName(event["source"]) except SQLObjectNotFound: s = Source(name=event["source"]) flag_for_review = True e.addSource(s) self._set_optional_fields(e, event, ("cost", "ages", "url", "description", "ticket_url")) for artist in self.artists_clean(event['artists']): try: a = Artist.byNameI(artist) # artist was a similar, but now it's listed as having an event # so approve it if not a.approved: a.approved = datetime.now() except SQLObjectNotFound: a = Artist(name=artist, added_by=identity.current.user) flag_for_review = True if not e.id in [existing.id for existing in a.events]: a.addEvent(e) # flag all events from certain unreliable sources if event["source"] in ("ticketswest", "upcoming", "lastfm"): flag_for_review = True if new_event and not flag_for_review: e.approved = datetime.now() elif flag_for_review: e.approved = None return (new_event, flag_for_review)
def save(self, id, **kw): try: v = Venue.byName(kw['venue']['text']) except SQLObjectNotFound: v = Venue(name=kw['venue']['text'], added_by=identity.current.user) artists = kw.pop('artists') if not artists: artists = "" artist_name_list = [artist.strip() for artist in artists.split('\n')] # elim blank items in list artist_name_list = [artist for artist in artist_name_list if artist] if not kw.get('name'): kw['name'] = ", ".join(artist_name_list) # updating if id: try: e = Event.get(id) flash_msg = "updated" except SQLObjectNotFound: flash("Database error, please try again") redirect("/") # inserting else: e = Event(name=kw['name'], date=kw['date'], time=kw['time'], venue=v, added_by=identity.current.user) # mark user as going to all added events by default if not "admin" in identity.current.groups: att = Attendance(user=identity.current.user, event=e, planning_to_go=True) flash_msg = "added, will be reviewed and posted within 24 hrs" del kw['venue'] e.set(**e.clean_dict(kw)) old_venue = e.venue e.venue = v old_venue.destroy_if_unused() old_artists = set([a.name for a in e.artists]) # add new artists artist_list = [] for artist in artist_name_list: try: a = Artist.byNameI(artist) if not a in e.artists: e.addArtist(a) except SQLObjectNotFound: a = Artist(name=artist, added_by=identity.current.user) e.addArtist(a) artist_list.append(a) # remove old artists for artist in e.artists: if artist not in artist_list: e.removeArtist(artist) artist.destroy_if_unused() new_artists = set([a.name for a in e.artists]) # approve all artists at approved events if e.approved: for artist in e.artists: if not artist.approved: artist.approved = datetime.now() # add entry to UpdateLog if old_artists != new_artists and e.approved: u = UpdateLog( changed_by=identity.current.user.id, table_name="artist_event", table_id=e.id, attrib_name="artists", attrib_old_value=old_artists, attrib_new_value=new_artists ) flash("Event %s" % flash_msg) util.redirect("/events/%s" % e.id)