On Mon, Oct 14, 2013 at 10:01 AM, Arnon Marcus <a.m.mar...@gmail.com> wrote:
> I ended-up embedding my code into web2py instead of injecting it - it's > simpler this way (for me) - it looks like this: > > *In gluon.contrib.logstash.py:* > > > def log(request, response, session, logger): > > user = '' > sessionDict = dict(session) > if sessionDict.has_key('auth') and sessionDict['auth']: > authDict = dict(sessionDict['auth']) > if authDict.has_key('user') and authDict['user']: > userDict = dict(authDict['user']) > if userDict.has_key('first_name') and userDict.has_key( > 'last_name'): > user = userDict['first_name'] + ' ' + userDict['last_name' > ] > > I would write the above with something (not tested) like: def log(request, response, session, logger): user = '' if session and session.auth and session.auth.user: auth_user = session.auth.user first_name = auth_user.firstname or '' last_name = auth_user.lastname or '' user = firstname + ' ' + lastname or def log(request, response, session, logger): try: auth_user = session.auth.user first_name = auth_user.firstname or '' last_name = auth_user.lastname or '' user = first_name + ' ' + last_name except AttributeError: user = '' -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.