[Mpuls-commits] r1013 - in wasko/branches/2.0: . waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jan 29 15:13:53 CET 2010


Author: bh
Date: 2010-01-29 15:13:52 +0100 (Fri, 29 Jan 2010)
New Revision: 1013

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/waskaweb/model/user.py
Log:
* waskaweb/model/user.py: Fix formatting.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-01-29 13:37:26 UTC (rev 1012)
+++ wasko/branches/2.0/ChangeLog	2010-01-29 14:13:52 UTC (rev 1013)
@@ -1,5 +1,9 @@
 2010-01-29  Bernhard Herzog  <bh at intevation.de>
 
+	* waskaweb/model/user.py: Fix formatting.
+
+2010-01-29  Bernhard Herzog  <bh at intevation.de>
+
 	* waskaweb/model/appointment.py: Remove unused imports
 
 2010-01-29  Bernhard Herzog  <bh at intevation.de>

Modified: wasko/branches/2.0/waskaweb/model/user.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/user.py	2010-01-29 13:37:26 UTC (rev 1012)
+++ wasko/branches/2.0/waskaweb/model/user.py	2010-01-29 14:13:52 UTC (rev 1013)
@@ -1,61 +1,96 @@
 # Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-# 
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS - 
+#
+# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
 # Web-Anwendungs-Server fuer Kompetenzagenturen).
-# 
+#
 # mpuls WASKA is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Affero General Public License as published by the
 # Free Software Foundation, either version 3 of the License, or (at your
 # option) any later version.
-# 
+#
 # mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 # License for more details.
-# 
+#
 # You should have received a copy of the GNU Affero General Public
 # License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
-# 
-# mpuls WASKA has been developed on behalf of the 
+#
+# mpuls WASKA has been developed on behalf of the
 # Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
 # within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and 
+# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
 # European Social Fund resources.
+
+import sys
+import datetime
+
+from pylons import config, session
+
 import waskaweb.lib.helpers as h
-from waskaweb.lib.security import getDbName 
+from waskaweb.lib.security import getDbName
 from waskaweb.lib.db import db
 
-from pylons import config, session
-import datetime
-import sys
 MARK_NEWS_AS_READ_SQL = """SELECT markNewsAsRead(%(user_id)s, %(news_id)s)"""
-FETCH_USER_LIST_SQL = """SELECT id, vorname, nachname, rolle, login, gid from ka_benutzer_tbl_view order by nachname""" 
-FETCH_USERGROUP_LIST_SQL = """SELECT id, name from ka_benutzergruppe_tbl_view order by name"""
-FETCH_USERGROUP_DATA_SQL = """SELECT id, name from ka_benutzergruppe_tbl_view WHERE id = %(id)s"""
-FETCH_USER_DATA_SQL = """SELECT id, vorname, nachname, telefon, aktiviert, passwort_aendern, login, raumnummer, filiale, usesysid, vertreter, rolle, gid, last_login from ka_benutzer_tbl_view WHERE id = %s"""
+FETCH_USER_LIST_SQL = """\
+SELECT id, vorname, nachname, rolle, login, gid
+FROM ka_benutzer_tbl_view
+ORDER BY nachname
+"""
+FETCH_USERGROUP_LIST_SQL = """\
+SELECT id, name FROM ka_benutzergruppe_tbl_view ORDER BY name"""
+FETCH_USERGROUP_DATA_SQL = """\
+SELECT id, name FROM ka_benutzergruppe_tbl_view WHERE id = %(id)s"""
+FETCH_USER_DATA_SQL = """\
+SELECT
+    id,
+    vorname,
+    nachname,
+    telefon,
+    aktiviert,
+    passwort_aendern,
+    login,
+    raumnummer,
+    filiale,
+    usesysid,
+    vertreter,
+    rolle,
+    gid,
+    last_login
+FROM ka_benutzer_tbl_view
+WHERE id = %s"""
 FETCH_USER_SYS_ID_SQL = """SELECT usesysid FROM pg_user WHERE usename = '%s'"""
-STORE_USERGROUP_DATA_SQL = """UPDATE ka_benutzergruppe_tbl_view SET name = %(name)s WHERE id = %(id)s"""
+STORE_USERGROUP_DATA_SQL = """\
+UPDATE ka_benutzergruppe_tbl_view SET name = %(name)s WHERE id = %(id)s"""
 CREATE_USERGROUP_DATA_SQL = """SELECT create_benutzergruppe_ds(%(name)s)"""
 DELETE_USERGROUP_DATA_SQL = """SELECT delete_benutzergruppe_ds(%(id)s)"""
 ADD_USER_TO_GROUP = """SELECT create_nm_benutzer_gruppe_ds(%(bid)s, %(gid)s)"""
-DELETE_USER_FROM_GROUP = """SELECT delete_nm_benutzer_gruppe_ds(%(bid)s, %(gid)s)"""
-GET_USERS_IN_GROUP = """select benutzer_id from nm_benutzer_gruppe_tbl_view where gruppe_id = %(id)s;"""
-CREATE_USER_SQL_M = """SELECT ka_create_role(%(agency)s, %(grouprole)s, %(loginname)s, %(firstname)s, %(surname)s, %(phone)s, %(room)s, %(branchoffice)s, %(activated)s , %(setpassword)s)"""
+DELETE_USER_FROM_GROUP = """\
+SELECT delete_nm_benutzer_gruppe_ds(%(bid)s, %(gid)s)"""
+GET_USERS_IN_GROUP = """\
+SELECT benutzer_id FROM nm_benutzer_gruppe_tbl_view WHERE gruppe_id = %(id)s;"""
+CREATE_USER_SQL_M = """\
+SELECT ka_create_role(%(agency)s, %(grouprole)s, %(loginname)s,
+                      %(firstname)s, %(surname)s, %(phone)s, %(room)s,
+                      %(branchoffice)s, %(activated)s , %(setpassword)s)"""
 DELETE_USER_SQL = """SELECT ka_delete_role(%(login)s, %(agency)s)"""
-RESET_USER_PASSWORD_SQL = """SELECT waska_reset_password(%(login)s, %(agency)s)"""
+RESET_USER_PASSWORD_SQL = """SELECT waska_reset_password(%(login)s, %(agency)s)
+"""
 ALTER_USER_PASSWORD_SQL = """SELECT ka_set_password(%(login)s, %(password)s)"""
 ALTER_USER_STANDIN_SQL = """SELECT ka_set_standin(%(standin)s, %(userid)s)"""
-STORE_USER_DATA_SQL = """UPDATE ka_benutzer_tbl_view SET %s WHERE id = %%(id)s"""
-#GET_USERROLE_SQL = """select groname from pg_group where %(useroid)s = ANY (grolist)"""
+STORE_USER_DATA_SQL = """UPDATE ka_benutzer_tbl_view SET %s WHERE id = %%(id)s
+"""
 
+
 class UserGroupList:
+
     def __init__(self):
         self.list = []
         try:
             conn, cur = None, None
             try:
                 conn = db.getConnection()
-                cur  = conn.cursor()
+                cur = conn.cursor()
                 cur.execute(FETCH_USERGROUP_LIST_SQL)
                 for r in cur.fetchall():
                     name = unicode(str(r[1]), 'utf-8')
@@ -73,7 +108,10 @@
             return [e for e in self.list if e.id not in filter]
         else:
             return self.list
+
+
 class UserGroupFactory:
+
     def create(self, name):
         try:
             conn, cur = None, None
@@ -81,7 +119,7 @@
             fields = {'name': name}
             try:
                 conn = db.getConnection()
-                cur  = conn.cursor()
+                cur = conn.cursor()
                 cur.execute(CREATE_USERGROUP_DATA_SQL, fields)
                 r = cur.fetchone()
                 conn.commit()
@@ -100,7 +138,7 @@
             group = UserGroup()
             try:
                 conn = db.getConnection()
-                cur  = conn.cursor()
+                cur = conn.cursor()
                 cur.execute(FETCH_USERGROUP_DATA_SQL, fields)
                 r = cur.fetchone()
                 name = unicode(str(r[1]), 'utf-8')
@@ -112,9 +150,11 @@
             print >> sys.stderr, "Error on loading user group overview: %s" % str(err)
         return group
 
+
 class UserGroup:
+
     def __init__(self, id=None):
-        self.id   = '' 
+        self.id = ''
         self.name = ''
 
         if id:
@@ -124,13 +164,14 @@
             self.name = group.name
 
     def setData(self, data):
-        self.id   = data.get('id', '')
+        self.id = data.get('id', '')
         self.name = data.get('name', '')
 
     def setUser(self, list):
-        if not list: return
-        old_user  = set(self._getCurrentUserIds())
-        new_user  = set([int(id) for id in list])
+        if not list:
+            return
+        old_user = set(self._getCurrentUserIds())
+        new_user = set([int(id) for id in list])
 
         to_add = new_user.difference(old_user)
         to_delete = old_user.difference(new_user)
@@ -138,9 +179,10 @@
             conn, cur = None, None
             try:
                 conn = db.getConnection()
-                cur  = conn.cursor()
+                cur = conn.cursor()
                 for id in to_delete:
-                    cur.execute(DELETE_USER_FROM_GROUP, {'bid': id, 'gid': self.id})
+                    cur.execute(DELETE_USER_FROM_GROUP, {'bid': id,
+                                                         'gid': self.id})
 
                 for id in to_add:
                     cur.execute(ADD_USER_TO_GROUP, {'bid': id, 'gid': self.id})
@@ -157,7 +199,7 @@
             fields = {'id': self.id}
             try:
                 conn = db.getConnection()
-                cur  = conn.cursor()
+                cur = conn.cursor()
                 cur.execute(GET_USERS_IN_GROUP, fields)
                 for id in cur.fetchall():
                     list.append(int(id[0]))
@@ -183,7 +225,7 @@
             fields = {'id': self.id}
             try:
                 conn = db.getConnection()
-                cur  = conn.cursor()
+                cur = conn.cursor()
                 cur.execute(DELETE_USERGROUP_DATA_SQL, fields)
                 conn.commit()
             finally:
@@ -198,7 +240,7 @@
             fields = {'id': self.id, 'name': self.name}
             try:
                 conn = db.getConnection()
-                cur  = conn.cursor()
+                cur = conn.cursor()
                 cur.execute(STORE_USERGROUP_DATA_SQL, fields)
                 conn.commit()
             finally:
@@ -208,19 +250,22 @@
 
 
 class UserListObject:
+
     def __init__(self):
         self.user = []
         try:
             conn, cur = None, None
             try:
                 conn = db.getConnection()
-                cur  = conn.cursor()
+                cur = conn.cursor()
                 cur.execute(FETCH_USER_LIST_SQL)
                 for r in cur.fetchall():
                     firstname = unicode(str(r[1]), 'utf-8')
                     lastname = unicode(str(r[2]), 'utf-8')
                     login = unicode(str(r[4]), 'utf-8')
-                    data = {'id': r[0], 'gid': r[5], 'firstname': firstname, 'lastname': lastname, 'role': r[3], 'login': login}
+                    data = {'id': r[0], 'gid': r[5],
+                            'firstname': firstname, 'lastname': lastname,
+                            'role': r[3], 'login': login}
                     uo = UserObject()
                     uo.setData(data)
                     self.user.append(uo)
@@ -234,33 +279,35 @@
         if filter:
             return [e for e in admins if e.id not in filter]
         else:
-            return admins 
+            return admins
 
     def getUserList(self, filter=None):
         if filter:
             return [e for e in self.user if e.id not in filter]
         else:
             return self.user
+
+
 class User:
+
     def __init__(self, id=None):
         self.id = id
-        self.gid = None 
-        #self.oid = '' 
+        self.gid = None
         self.login = ''
         self.full_login = '' #full login: ka_dbname_login
-        self.role = '' 
+        self.role = ''
         self.agency = ''
-        self.last_name = '' 
-        self.first_name = '' 
-        self.activated = True 
-        self.needs_passrefresh = True 
+        self.last_name = ''
+        self.first_name = ''
+        self.activated = True
+        self.needs_passrefresh = True
 
     def getLogin(self):
         return self.login
 
     def getAgency(self):
         return self.agency
-        
+
     def getPermissionRole(self):
         '''Returns the users permissionrole
            Available rolenames:
@@ -272,15 +319,15 @@
             tok = self.role.split('_')
             return "_".join(tok[-1:])
         except:
-            return None 
-        
+            return None
+
     def getRole(self):
-        '''Returns the string of the users role which is meant to be displayed in the ui
+        """Return the user's role as a string to display in the ui
            Translate Roles:
              * admin -> Admin
              * cm    -> CM
              * pt   -> PT
-        '''
+        """
         permrole = self.getPermissionRole()
         if permrole == 'cm':
             return 'CM'
@@ -292,7 +339,7 @@
             return permrole
 
     def isActivated(self):
-        return self.activated 
+        return self.activated
 
     def needsNewPass(self):
         return self.needs_passrefresh
@@ -310,32 +357,36 @@
             name.append(self.first_name[0])
             name.append(".")
 
-        if not name: return ""
+        if not name:
+            return ""
 
         return "".join(name)
-        
 
+
 class SessionUser(User):
+
     def __init__(self, lname, password):
-        User.__init__(self, None) 
+        User.__init__(self, None)
         tok = lname.split('_')
         self.full_login = lname
         self.login = "_".join(tok[2:])
         self.agency = tok[1]
-        self.password = password 
+        self.password = password
 
     def setData(self, data):
         self.id = data.get('id', '')
         self.gid = data.get('gid', '')
-        self.first_name = data.get('firstname', '') 
-        self.last_name = data.get('lastname', '') 
-        self.activated = data.get('activated', False) 
-        self.needs_passrefresh = data.get('newpass', True) 
-        self.role = data.get('role', '') 
+        self.first_name = data.get('firstname', '')
+        self.last_name = data.get('lastname', '')
+        self.activated = data.get('activated', False)
+        self.needs_passrefresh = data.get('newpass', True)
+        self.role = data.get('role', '')
         self.last_login = data.get('last_login') or datetime.datetime.now()
-        self.standin = data.get('standin') 
+        self.standin = data.get('standin')
 
+
 class SessionSuperAdmin(User):
+
     def __init__(self, lname, password):
         User.__init__(self, 0)
         self.last_name = 'Zentrale Administration'
@@ -345,13 +396,14 @@
         tok = lname.split('_')
         self.login = "_".join(tok[2:])
         self.agency = tok[1]
-        self.password = password 
+        self.password = password
         self.last_login = datetime.datetime.now()
 
+
 class UserObject(User):
+
     def __init__(self, id=None):
         User.__init__(self, id)
-
         self.telephone = ''
         self.room = ''
         self.branchoffice = ''
@@ -379,13 +431,13 @@
         return 1
 
     def setAdmUser(self):
-        self.last_name         = 'Zentrale Administration'
+        self.last_name = 'Zentrale Administration'
         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.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]
 
     def setPassword(self, password):
         conn, cur = None, None
@@ -397,10 +449,10 @@
             new_pass = cur.fetchone()[0]
             conn.commit()
             self.needs_passrefresh = False
-            return new_pass 
+            return new_pass
         finally:
             db.recycleConnection(conn, cur)
-        return None 
+        return None
 
     def resetPassword(self):
         conn, cur = None, None
@@ -435,7 +487,7 @@
                 self.last_name = unicode(str(ud[2]), 'utf-8')
                 self.telephone = unicode(str(ud[3]), 'utf-8')
                 self.activated = ud[4]
-                self.needs_passrefresh = ud[5] 
+                self.needs_passrefresh = ud[5]
                 self.full_login = unicode(str(ud[6]), 'utf-8')
                 self.room = unicode(str(ud[7]), 'utf-8')
                 self.branchoffice = unicode(str(ud[8]), 'utf-8')
@@ -443,13 +495,13 @@
                 self.standin = ud[10]
                 self.role = ud[11]
                 self.gid = ud[12] # id usergroup of the user
-                self.last_login = ud[13] # timestamp 
+                self.last_login = ud[13] # timestamp
                 tok = self.full_login.split('_')
                 self.login = "_".join(tok[2:])
                 self.agency = tok[1]
         finally:
             db.recycleConnection(conn, cur)
-    
+
     def setStandin(self, gid):
         con, cur = None, None
         fields = {'userid': self.id, 'standin':gid}
@@ -464,20 +516,22 @@
             db.recycleConnection(con, cur)
 
     def setData(self, data):
-        """Eats dictionary holding valid data returned from the formencode validation"""
-        self.id = data.get('id', self.id) 
-        self.gid = data.get('gid', self.gid) 
-        self.first_name = data.get('firstname', self.first_name) 
-        self.role = data.get('role', self.role) 
-        self.last_name= data.get('lastname', self.last_name) 
-        self.telephone = data.get('telephone', self.telephone) 
-        self.room = data.get('room', self.room) 
-        self.branchoffice = data.get('branchoffice', self.branchoffice) 
+        """Set the user data from the dictionary data.
+        Usually data is the dictionary returned from the formencode validation.
+        """
+        self.id = data.get('id', self.id)
+        self.gid = data.get('gid', self.gid)
+        self.first_name = data.get('firstname', self.first_name)
+        self.role = data.get('role', self.role)
+        self.last_name= data.get('lastname', self.last_name)
+        self.telephone = data.get('telephone', self.telephone)
+        self.room = data.get('room', self.room)
+        self.branchoffice = data.get('branchoffice', self.branchoffice)
         self.full_login = data.get('login', self.full_login)
         tok = self.full_login.split('_')
         self.login = "_".join(tok[2:])
-        self.activated = data.get('activated', self.activated) 
-        self.needs_passrefresh = data.get('newpass', self.needs_passrefresh) 
+        self.activated = data.get('activated', self.activated)
+        self.needs_passrefresh = data.get('newpass', self.needs_passrefresh)
 
     def createLogin(self, login=None, role=None, agency=None):
         self.login = login
@@ -488,17 +542,17 @@
         try:
             conn = db.getConnection()
             cur = conn.cursor()
-            fields = {'loginname': self.login, 
-                    'grouprole': self.role, 
-                    'agency': self.agency,
-                    'firstname': self.first_name,
-                    'surname': self.last_name,
-                    'phone': self.telephone,
-                    'room': self.room,
-                    'branchoffice': self.branchoffice,
-                    'activated': self.activated,
-                    'setpassword': self.needs_passrefresh 
-                    }
+            fields = {'loginname': self.login,
+                      'grouprole': self.role,
+                      'agency': self.agency,
+                      'firstname': self.first_name,
+                      'surname': self.last_name,
+                      'phone': self.telephone,
+                      'room': self.room,
+                      'branchoffice': self.branchoffice,
+                      'activated': self.activated,
+                      'setpassword': self.needs_passrefresh
+                      }
             cur.execute(CREATE_USER_SQL_M, fields)
             result = cur.fetchone()
             password = result[0]
@@ -509,13 +563,13 @@
 
     def store(self):
         fields = {
-                    'vorname': self.first_name,  
-                    'nachname': self.last_name,
-                    'telefon': self.telephone, 
-                    'aktiviert': self.activated,
-                    'raumnummer': self.room,
-                    'filiale': self.branchoffice,
-                    'passwort_aendern': self.needs_passrefresh
+            'vorname': self.first_name,
+            'nachname': self.last_name,
+            'telefon': self.telephone,
+            'aktiviert': self.activated,
+            'raumnummer': self.room,
+            'filiale': self.branchoffice,
+            'passwort_aendern': self.needs_passrefresh
         }
         update_str = []
         for key in fields.iterkeys():



More information about the Mpuls-commits mailing list