Ejemplo n.º 1
0
 def delete(self, id):
     try:
         e = Event.get(id)
         e.destroySelf()
         flash("Deleted")
     except SQLObjectNotFound:
         flash("Delete failed")
     util.redirect("/events/list")
Ejemplo n.º 2
0
 def show(self, id):
     try:
         e = Event.get(id)
         is_tracked = identity.current.user and e in identity.current.user.events
     except SQLObjectNotFound:
         flash("Event not found")
         util.redirect("/events/list")
     return dict(event=e, artist_list=artist_list, googlemap=googlemap,
         description=util.desc_format(e.description), is_tracked=is_tracked)
Ejemplo n.º 3
0
 def untrack(self, id, viewing="no"):
     u = identity.current.user
     try:
         e = Event.get(id)
         atts = Attendance.selectBy(user=u, event=e)
         for att in atts:
             att.destroySelf()
     except SQLObjectNotFound:
         flash("Event not found")
         redirect("/")
     if viewing == "no":
         util.redirect_previous()
     else:
         util.redirect("/events/%s" % e.id)
Ejemplo n.º 4
0
 def track(self, id, viewing="no", planning=False, went=False, comment=None):
     u = identity.current.user
     try:
         e = Event.get(id)
         try:
             att = Attendance.selectBy(user=u, event=e)[0]
         except IndexError:
             att = Attendance(user=u, event=e)
         att.planning_to_go = planning
         att.attended = went
         att.comment = comment
     except SQLObjectNotFound:
         flash("Event not found")
         redirect("/")
     if viewing == "no":
         util.redirect_previous()
     else:
         util.redirect("/events/%s" % e.id)
Ejemplo n.º 5
0
    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)