diff pylons_app/lib/utils.py @ 537:48be953851fc

extended user logs to create/delete/fork repositories for auditing some spelling corrections
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 02 Oct 2010 02:56:39 +0200
parents 39203995f2c4
children d8778cde98f0
line wrap: on
line diff
--- a/pylons_app/lib/utils.py	Sat Oct 02 01:52:43 2010 +0200
+++ b/pylons_app/lib/utils.py	Sat Oct 02 02:56:39 2010 +0200
@@ -26,7 +26,7 @@
 from mercurial import ui, config, hg
 from mercurial.error import RepoError
 from pylons_app.model import meta
-from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings,UserLog
+from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings, UserLog
 from vcs.backends.base import BaseChangeset
 from vcs.utils.lazy import LazyProperty
 import logging
@@ -57,21 +57,21 @@
     if not sa:
         sa = meta.Session 
         
-    
-    if hasattr(user, 'user_id'):
-        user_id = user.user_id
-    elif isinstance(user, basestring):
-        
-        user_id = sa.Query(User).filter(User.username == user).one()
-    else:
-        raise Exception('You have to provide user object or username')
-   
     try:
+        if hasattr(user, 'user_id'):
+            user_id = user.user_id
+        elif isinstance(user, basestring):
+            user_id = sa.query(User).filter(User.username == user).one()
+        else:
+            raise Exception('You have to provide user object or username')
+       
+        repo_name = repo.lstrip('/')
         user_log = UserLog()
         user_log.user_id = user_id
         user_log.action = action
+        user_log.repository_name = repo_name
         user_log.repository = sa.query(Repository)\
-            .filter(Repository.repo_name==repo.lstrip('/')).one()
+            .filter(Repository.repo_name == repo_name).one()
         user_log.action_date = datetime.datetime.now()
         user_log.user_ip = ipaddr
         sa.add(user_log)