Showing posts with label TurboGears. Show all posts
Showing posts with label TurboGears. Show all posts

Saturday, June 20, 2009

Turbogears debugging in Eclipse

Setting up debug enabled environment for a Turbogears application in Eclipse is not really straightforward. I struggled a lot before I could set it up. Initially I wasnt even sure if I could set up break points and debug the application like in microsoft visual studio. It is very much possible although some of the things are not very obvious. Here is a list of things to check up, if you are facing problems.

1. You can install Pydev by following the instructions mentioned on pydev website. You can also have a look at this ibm site which helps you make the necessary settings in Eclipse.

2. You can patch the Decorators file from pydev blog. If you are facing any problems drop your email id I will send you the patched file.

3. Pydev gives problems with certain turbojson package versions. You may try to downgrade and install a previous version of turbojson package. Use the following command to do so:
>easy_install -U turbojson==1.1.4

>easy_install -U DecoratorTools==1.4 

4. Remember, you will still see the following error when you start the debug session.

PYDEV DEBUGGER WARNING:

sys.settrace() should not be used when the debugger is being used.

This may cause the debugger to stop working correctly.

If this is needed, please check: 

http://pydev.blogspot.com/2007/06/why-cant-pydev-debugger-work-with.html

to see how to restore the debug tracing back correctly.

Call Location:

  File "C:\Python24\lib\site-packages\decoratortools-1.4-py2.4.egg\peak\util\decorators.py", line 562, in uninstall


But, wait for a few seconds and eclipse will start the debug session after the error message.

Tuesday, March 3, 2009

Existing database tables and SQLObject

Define the existing table "Bookmark" as a class in python:-

class Bookmark(SQLObject):

_fromDatabase = True # the table structure will be loaded from the database
BookmarkName = StringCol (dbName="bookmark_name")
# dbName is the name of the column in the database, BookmarkName is the name reference in code.
ProjectId = IntCol(dbName="project_id")

(Make sure the indentation is correct)

Connecting to an existing database using TurboGears framework

Your application would need a DB connection to access the database. A connection is how you tell SQLObject to locate your database. SQLObject is an object relational mapper, a software layer that maps data stored in a relational database to an object model in an object-oriented programming language. The connection string resembles a URI in the following format:


scheme://[user[:password]@]host[:port]/database[?parameters]
For instance:
postgres://user:pwd@localhost:5432/db


SQLObject provides a debug mechanism, which can be turned on easily by appending ?debug=True to the end of your database URI in the dev.cfg file.

postgres://user:pwd@localhost:5432/db?debug=True
This would publish the query generated onto the console.
..........

Define the existing table Bookmark as a class in model.py:-

class Bookmark(SQLObject):

_fromDatabase = True # the table schema be loaded from the database

BookmarkName = StringCol (dbName="bookmark_name")

ProjectId = IntCol(dbName="project_id")

# dbName is the name of the column in the database, BookmarkName is the name reference in code.

..........
Using the following code in controller.py you should be able to retrieve the second record from the Bookmark table

 
b=Bookmark.select()
print ": %s " % b[2].BookmarkName