I created appwizard application and added user login validation to main file
(eeva.py). I want that dabo application user = Postgres user and Postgres
validates login

Any attempt to open table after logging in causes error

AttributeError:  'Alamdok' object has no attribute '_CurrentCursor'

When I'm doing wrong ?

Also Paul or Ed wrote some time ago that the line

cursor = self.connection.getConnection().cursor()

in ValidateLogin() is not good to use for sending commands to backend. How
to replace it with better one ?

Andrus.


eeva.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#!/usr/bin/env python

import sys
import os
import dabo

if sys.platform[:3] == "win":
dabo.settings.MDI = True

from App import App
import db
import biz
import ui

class TestSecurityManager(dabo.dSecurityManager.dSecurityManager):
""" This is a simple subclass of dSecurityManager, to show how it works.

Try changing self.RequireAppLogin to True, and you should get a login
form at app startup.
"""
def initProperties(self):
 #self.LoginMessage = "For this demo, user=dabo, pass=dabo"
 self.RequireAppLogin = True
 #self.User = 'admin'
 #self.PlainTextPassword = 'aaaa'

       def validateLogin(self, user, password):
                   """ Return True to tell the security manager to accept
the login.

                   This is your hook to do whatever validation is required
to determine whether
                   the user can login or not.
                   """

                   # http://dabodev.com/wiki/FAQs#connect

                   from dabo.db.dConnectInfo import dConnectInfo
                   from dabo.db.dConnection import dConnection

                   #
                   # enter data
                   #con =
dabo.db.dConnection(self.Application.dbConnectionDefs("[EMAIL PROTECTED]"))
                   #cur = con.getDaboCursor()
                   #cur.executemany("INSERT......", data)
                   #cur.commitTransaction()

                   # verify
                   #cur.execute("SELECT COUNT(*) FROM .....")
                   #print cur.fetchall()


                   #ci = dConnectInfo() # 'PostgreSQL')
                   #
                   #ci.DbType = "PostgreSQL"
                   #ci.Host = "localhost"

                   ci =
self.Application.dbConnectionDefs["[EMAIL PROTECTED]"]

                   ci.Name = "mainConnection"
                   ci.User = user
                   ci.PlainTextPassword = password
                   ci.Database = "eeva"
                   #Setting the port is not realy needed.
                   import exceptions
                   try:
                       self.connection = dConnection(ci) ##
.getConnection()
                   except exceptions.StandardError, err:
                       dabo.ui.exclaim( str(err))
                       return False

                   ##Executing queries in the main cursor is not
recommended, since it is
                   ##needed for data management, and its internal props get
wiped out when
                   ##a non-select statement is execute. There is an
internal auxiliary
                   ##cursor object used by the Dabo Cursor to handle such
statements, such
                   ##as delete, update, etc. Perhaps I could modify the
Dabo Cursor's
                   ##execute() method to check to see if the statement
begins with
                   ##'select', and if not, pass it to its auxiliary cursor
for execution.
                   ##I could then add a bizobj.execute() method that would
essentially be
                   ##a pass-through to its Dabo Cursor


                   #cursor = self.connection.getDaboCursor()
                   #cursor.superCursor.execute("set search_path to
public,firma1")

                   cursor = self.connection.getConnection().cursor()
                   cursor.execute("set search_path to public,firma1")
                   return True

def getUserCaptionFromUserName(self, user):
 """ Whatever you return here becomes the value of the UserCaption
property.

 This is your hook to set the UserCaption to something more descriptive and
 friendly, such as converting pmcnett to 'Paul McNett'.
 """
 #if user == 'dabo':
 # return 'Dabo Test User'
 #else:
 return user

def getUserGroupsFromUserName(self, user):
 """ Return a tuple that lists the user's group membership.

 This is your hook to set the groups this user belongs to, using whatever
 means to determine this your application requires. For instance, perhaps
 there is a group called 'BaseUser' that all logged in users belong to.
 """
 return ("BaseUser",)

app = App()

# If we are running frozen, let's reroute the errorLog:
if hasattr(sys, "frozen"):
dabo.errorLog.Caption = ""
dabo.errorLog.LogObject = open(os.path.join(app.HomeDirectory,
  "error.log"), "a")

# Make it easy to find any images or other files you put in the resources
# directory.
sys.path.append(os.path.join(app.HomeDirectory, "resources"))

# Define namespaces in the Application object where the biz, db and ui
# packages can be accessed globally:
app.db = db
app.ui = ui
app.biz = biz

app.SecurityManager = TestSecurityManager()

app.setup()

# Set up a global connection to the database that all bizobjs will share:
app.dbConnection = app.getConnectionByName("postgres dmeo baasiga")

# Open one of the defined forms:
#frm = ui.FrmAlamdok(app.MainForm)
#frm.show()

#

# Start the application event loop:
app.start()




Dabo Info Log: Sun Jun 11 17:02:35 2006: 1 database connection definition(s)
loa
ded.
Dabo Info Log: Sun Jun 11 17:02:35 2006: User interface already set to 'wx',
so
dApp didn't  touch it.
Dabo Info Log: Sun Jun 11 17:02:35 2006: wxPython Version: 2.6.3.2 wxMSW
(unicod
e)
Traceback (most recent call last):
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\lib\eventMixin.py
", line 87, in raiseEvent
   bindingFunction(event)
 File "C:\daboide\wizards\AppWizard\eeva\ui\MenFileOpen.py", line 81, in
openFo
rm
   frm = evt.EventObject.Tag(mainForm)
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\lib\datanav\Form.
py", line 59, in __init__
   super(Form, self).__init__(parent, *args, **kwargs)
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\ui\uiwx\dForm.py"
, line 756, in __init__
   BaseForm.__init__(self, preClass, parent, properties, *args, **kwargs)
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\ui\uiwx\dForm.py"
, line 39, in __init__
   fm.dFormMixin.__init__(self, preClass, parent, properties, *args,
**kwargs)
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\ui\uiwx\dFormMixi
n.py", line 57, in __init__
   attProperties, *args, **kwargs)
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\ui\uiwx\dPemMixin
.py", line 170, in __init__
   self._afterInit()
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\lib\datanav\Form.
py", line 65, in _afterInit
   super(Form, self)._afterInit()
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\ui\uiwx\dForm.py"
, line 61, in _afterInit
   super(BaseForm, self)._afterInit()
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\ui\uiwx\dFormMixi
n.py", line 93, in _afterInit
   super(dFormMixin, self)._afterInit()
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\ui\uiwx\dPemMixin
.py", line 231, in _afterInit
   self.afterInit()
 File "C:\daboide\wizards\AppWizard\eeva\ui\FrmAlamdok.py", line 26, in
afterIn
it
   primaryBizobj = app.biz.Alamdok(app.dbConnection)
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\biz\dBizobj.py",
line 41, in __init__
   self._initProperties()
 File "C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\dObject.py",
line
110, in _initProperties
   self.initProperties()
 File "C:\daboide\wizards\AppWizard\eeva\biz\Alamdok.py", line 11, in
initPrope
rties
   self.DataSource = "alamdok"
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\biz\dBizobj.py",
line 141, in __setattr__
   super(dBizobj, self).__setattr__(att, val)
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\biz\dBizobj.py",
line 1358, in _setDataSource
   cursor = self._CurrentCursor
 File
"C:\Python24\Lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\biz\dBizobj.py",
line 123, in __getattr__
   raise AttributeError, _(" '%s' object has no attribute '%s' ") %
(self.__cla
ss__.__name__, att)
AttributeError:  'Alamdok' object has no attribute '_CurrentCursor'



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to