Here is solution I found using decorators.

...
from tg.decorators import before_call
...
def updateactivity(*l, **kw):
    now = datetime.now()
 
DBSession.query( User ).filter( User.user_name==request.environ['REMOTE_USER'] 
).one().last_activity
= datetime(now.year, now.month, now.day, now.hour, now.minute,
now.second)
...
class RootController(BaseController):
...
    @expose('myproject.templates.mytemplate')
    @require(predicates.not_anonymous)
    @before_call(updateactivity)
    def mymethod(self, **kw):
...
        return dict(page='mypage')
...
Is there any way to use it for whole controller? Like using
"allow_only" for controller instead of "@require" for each method.

Best Regards.
Maxim.
On 2 мар, 16:45, Maxim Oganesyan <[email protected]> wrote:
> Hi all.
> I'm looking for easier way for monitoring user activity on my site.
>
> I have a record in User class:
>
> class User(DeclarativeBase):
>     ...
>     last_activity = Column(DateTime)
>     ...
>
> ...and I have a code:
>
> if 'REMOTE_USER' in request.environ:
>
> DBSession.query( User ).filter( 
> User.user_name==request.environ['REMOTE_USER'] ).one().last_activity
> = datetime.now()
>
> Where should I insert this code to be called each time when logged-in-
> user visits my pages.
>
> I could insert it into each function, but it must be easier way.
>
> Thank You.
> Maxim.

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to