[Mpuls-commits] r2938 - in base/trunk: . mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jun 9 12:18:20 CEST 2010


Author: bh
Date: 2010-06-09 12:18:18 +0200 (Wed, 09 Jun 2010)
New Revision: 2938

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/model/user.py
Log:
* mpulsweb/model/user.py (parse_dblogin): New.  Helper function to
extract the web login name and agency name from the full database
login name.
(SessionUser.__init__, SessionSuperAdmin.__init__)
(UserObject.setAdmUser, UserObject._fetchData): Use parse_dblogin
instead of equivalent inline code.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-06-09 10:12:20 UTC (rev 2937)
+++ base/trunk/ChangeLog	2010-06-09 10:18:18 UTC (rev 2938)
@@ -1,3 +1,12 @@
+2010-06-09  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/model/user.py (parse_dblogin): New.  Helper function to
+	extract the web login name and agency name from the full database
+	login name.
+	(SessionUser.__init__, SessionSuperAdmin.__init__)
+	(UserObject.setAdmUser, UserObject._fetchData): Use parse_dblogin
+	instead of equivalent inline code.
+
 2010-06-09  Torsten Irländer <torsten.irlaender at intevation.de>
 
 	* mpulsweb/lib/translation.py: New. Copied from

Modified: base/trunk/mpulsweb/model/user.py
===================================================================
--- base/trunk/mpulsweb/model/user.py	2010-06-09 10:12:20 UTC (rev 2937)
+++ base/trunk/mpulsweb/model/user.py	2010-06-09 10:18:18 UTC (rev 2938)
@@ -87,6 +87,15 @@
 """
 
 
+def parse_dblogin(dblogin):
+    """Extract web login name and agency name from the full database login name.
+    The return value is a tuple (LOGIN, AGENCY) where LOGIN is the web
+    login name and AGENCY the agency name.
+    """
+    split = dblogin.split('_')
+    return ("_".join(split[2:]), split[1])
+
+
 class UserGroupList:
 
     def __init__(self):
@@ -375,10 +384,8 @@
 
     def __init__(self, lname, password):
         User.__init__(self, None)
-        tok = lname.split('_')
         self.full_login = lname
-        self.login = "_".join(tok[2:])
-        self.agency = tok[1]
+        self.login, self.agency = parse_dblogin(lname)
         self.password = password
 
     def setData(self, data):
@@ -402,8 +409,7 @@
         self.role = 'ka_%s_admin' % getDbName()
         self.full_login = lname
         tok = lname.split('_')
-        self.login = "_".join(tok[2:])
-        self.agency = tok[1]
+        self.login, self.agency = parse_dblogin(lname)
         self.password = password
         self.last_login = datetime.datetime.now()
 
@@ -443,9 +449,7 @@
         self.needs_passrefresh = False
         self.role = 'ka_%s_admin_ka' % getDbName()
         self.full_login = 'ka_%s_adm' % getDbName()
-        tok = self.full_login.split('_')
-        self.login = "_".join(tok[2:])
-        self.agency = tok[1]
+        self.login, self.agency = parse_dblogin(self.full_login)
 
     def setPassword(self, password):
         conn, cur = None, None
@@ -504,9 +508,7 @@
                 self.role = ud[11]
                 self.gid = ud[12] # id usergroup of the user
                 self.last_login = ud[13] # timestamp
-                tok = self.full_login.split('_')
-                self.login = "_".join(tok[2:])
-                self.agency = tok[1]
+                self.login, self.agency = parse_dblogin(self.full_login)
         finally:
             db.recycleConnection(conn, cur)
 



More information about the Mpuls-commits mailing list