Exemplo n.º 1
0
 def edit(self, user_name):
     if not (identity.current.user.user_name == user_name
             or "admin" in identity.current.groups):
         raise identity.IdentityFailure("Not authorized")
     try:
         u = UserAcct.by_user_name(user_name)
     except SQLObjectNotFound:
         flash("Invalid username")
         util.redirect("/")
     return dict(user_name=user_name, user_form=user_form,
         form_vals=u)
Exemplo n.º 2
0
 def validate_python(self, field_dict, state):
     if not field_dict['old_pass']:
         return
     try:
         u = UserAcct.by_user_name(field_dict['user_name'])
         enc_pass = identity.current_provider.encrypt_password(field_dict['old_pass'])
         if enc_pass != u.password:
             raise formencode.Invalid("", field_dict, state,
                 error_dict = {'old_pass':"******"})
     except SQLObjectNotFound:
         raise formencode.Invalid("", field_dict, state,
             error_dict = {'old_pass':'******'})
Exemplo n.º 3
0
    def showtracked(self, user_name):
        try:
            u = UserAcct.by_user_name(user_name)
            artists = u.artists.orderBy(Artist.q.name)

            viewing_self = False
            if identity.current.user and identity.current.user.user_name == user_name:
                viewing_self = True
        except SQLObjectNotFound:
            flash("User not found")
            util.redirect("/")

        return dict(user=u, artists=artists, viewing_self=viewing_self,
            artist_list=artist_list)
Exemplo n.º 4
0
    def save(self, user_name, old_pass, pass1, **kw):
        if not (identity.current.user.user_name == user_name
                or "admin" in identity.current.groups):
            raise identity.IdentityFailure("Not authorized")

        try:
            u = UserAcct.by_user_name(user_name)
            u.set(**u.clean_dict(kw))
            # old pw checked by validator, if present
            if (old_pass or "admin" in identity.current.groups) and pass1:
                # model does hash, not us
                u.password = pass1
            flash("Saved")
        except SQLObjectNotFound:
            flash("Error saving changes")
        util.redirect("/users/%s" % u.user_name)
Exemplo n.º 5
0
    def show(self, user_name):
        try:
            u = UserAcct.by_user_name(user_name)
            artists = u.artists.orderBy(Artist.q.name)
            venues = u.venues.orderBy(Venue.q.name)
            attendances = Attendance.selectBy(user=u)

            viewing_self = False
            if identity.current.user and identity.current.user.user_name == user_name:
                viewing_self = True
        except SQLObjectNotFound:
            flash("User not found")
            util.redirect("/")

        return dict(user=u, artists=artists, venues=venues,
            attendances=attendances, viewing_self=viewing_self,
            description=util.desc_format(u.description))
Exemplo n.º 6
0
    def icalendar(self, user_name):
        try:
            u = UserAcct.by_user_name(user_name)
        except SQLObjectNotFound:
            return "User not found."

        events = set()
        desc = "Event listed by Bandradar.com because you are tracking this %s."
        events.update(it.izip(u.events, it.repeat(desc % "event")))
        for artist in u.artists:
            events.update(it.izip(artist.future_events, it.repeat(desc % "artist")))
        for venue in u.venues:
            events.update(it.izip(venue.future_events, it.repeat(desc % "venue")))

        cal = ical.Calendar()
        cal.add('x-wr-calname', "BandRadar: events for %s" % u.user_name)
        cal.add('prodid', '-//bandradar//calendar//')
        cal.add('version', '1.0')
        for event, src in events:
            cal_event = ical.Event()
            cal_event.add('summary', event.name)
            if event.description:
                src += "\n\n" + event.description
            cal_event.add('description', src)
            location = event.venue.name
            if event.venue.address:
                location += " (" + event.venue.address + ")"
            cal_event.add('location', location)
            cal_event.add('uid', event.id)
            cal_event.add('url', "http://bandradar.com/events/%s" % event.id)
            cal_event.add('dtstart', datetime(event.date.year, event.date.month,
                event.date.day,21,0,0))
            cal_event.add('dtend', datetime(event.date.year, event.date.month,
                event.date.day,23,0,0))
            cal_event.add('dtstamp', datetime(event.date.year, event.date.month,
                event.date.day,21,0,0))
            cal.add_component(cal_event)
        cherrypy.response.headers['content-type'] = "text/calendar"
        return cal.as_string()