ExoTagging with SQLAlchemy

 pycon, Python, SQLAlchemy, TurboGears  Comments Off on ExoTagging with SQLAlchemy
Feb 242007
 

ExoTagging
After listening to the wonderful things being said about SQLAlchemy at PyCon, I wondered if the following idiom could be implemented as a Domain Object with SQLAlchemy.

Often we have legacy data that we have read only access, to which we need to associate additional meta information. Before this has always meant that the application had to be aware of the relationship of the meta data record in the ExoTagging DB and how to map it to the legacy read-only data. If we could map the two into a single Domain Object it would make are apps a lot cleaner. I spoke to Mark Ramm and he believed that it would be possible and in fact it might even be easy although he hadn’t attempted it before.

I call the idiom ExoTagging because it is logically quite like the idea of Tags, except that tags are kept in a table that resides in a database that is separate from the data that is being tagged. Hence Exo-Tag.

Has anyone else already implemented something like this with SQLAlchemy, if so would you mind sharing your experiences?

 Posted by at 4:15 pm

Python WebFrameworks: How to move forward

 pycon, Python, TurboGears  Comments Off on Python WebFrameworks: How to move forward
Feb 242007
 

Of late there has been much to do about the crop of Python based web frameworks. Is one superior to another? Currently, I don’t believe so they all have strengths and weaknesses and I could make a good argument for most of them. However, in the midst of this current genesis there are some shining stars that I think are setting the way forward. These stars are not the frameworks themselves but components that are written to be framework agnostic. For example, Paste, WSGI, SQLAlchemy and ToscaWidgets. By supplying these fundamental and highly useful tools, they are empowering the current and future web frameworks.

I think that all of the frameworks should look for commonality that can be shared, that can be improved for the benefit of all. Even if you want to have a full single source stack as opposed to a best of breed stack plugin architectures should be the standard. So advancements can spread between the frameworks.

What about the frameworks? I believe that in the end their will be two major web frameworks, Django and TurboGears/Pylons. Twisted won’t go away and neither will Nevow but they won’t match the popularity of the two majors. However, I firmly believe that all of the frameworks will have similar traits and in time will tend to a center balance point using different toolkits as the “preferred”.

 Posted by at 10:32 am

Advanced TurboGears Part II

 pycon, Python, TurboGears  Comments Off on Advanced TurboGears Part II
Feb 222007
 

leader: Mark Ramm

ref: http://us.pycon.org/TX2007/TutorialsPM#PM2

AJAX ~ JSON
is the communication protocol between the client and server

  • @expose(allow_json=True) … JSONifies the return results(dictionary or string)

Widgets ~

  • Widget Browser
  • how widgets are written/disecting ala the AutoComplete widget
  • current form widgets vs. toscawidgets — when that time comes, it shouldn’t even cause a bump unless you are using nested forms, — that api will change (for the better)
  • setting form widgets to default values

Break

Hints:
In Controllers: Just inherit from controllers in your nested controllers, don’t use controllers.RootController everywhere otherwise you’ll end up with name space collisions and CP won’t behave as expected.

SQLAlchemy

  • ActiveMapper – SQLAlchemy splits the logical definition from the physical so you can map a logical def back to a backend(s) of your choice (like a legacy db) It implements the “data mapper” method, Domain objects/ mapping layer/ physical data. It has a session mapper that keeps a link between the logical and physical, keeps the identity mapped to the underlying db, plus it caches.
  • Hints:
    ActiveMapper is pretty much deprecated. Elixir is the upcoming replacement.

    Genshi

  • Change *.kid to *.html
  • Change template engine to Genshi @expose(‘mytemplate’) -> @expose(‘genshi:mytemplate’)
  • py:match tags
  • if you have python blocks — you’ll need to wait a couple weeks
  • you have to wrap your calls to widgets in a function call ET(widget) ET=elementTree you may receive ElementTree references in your output. You can display your widget like ${ET(table.display(data))}
  • change sitetemplates.kid -> sitetemplates.htm — more that just a name change
  • Why Genshi —

    1. Error Handling — kid explodes and gives the line # of the compiled kid template (.pyc) that blew, Genshi gives you the line, column in the original source code/template.
    2. Lets you use XML includes and do XML includes in “if” tags

    More SQLAlchemy
    http://www.sqlalchemy.org/docs/tutorial.myt

    More Genshi Mark will post the Ulitimate-Wiki code later today/night

    Authentication
    TurboGears includes the Identity module. It uses a simple db back end but that can be changed out to an LDAP if desired. There exists an SO provider and an SA provider. There is a page on the old trac, it might be in RoughDocs by now. There is an AD backend too. The LDAP and AD providers only do Authentication, Authorization is handled by the a db local to the app.

    Sites Using TurboGears
    Sessions
    There is a CherryPy (CP) session filter that you just turn on. In the .ini files — dev or app, etc
    3 backends: file, memory, postgresql
    In the future it will be the CP session Tool instead of Filter
    CherryPy.????? is a great place to put thread local stuff

    Performance and Filters: Cache Filters – is CP deprecating it? Will CP make it a Tool, or if it is more WSGI friendly, will it turn to beaker?

    mark.ramm@gmail.com

    MochiKit
    Is the most under appreciated js package. Mark prefers it to prototype.js. Bob Ippolito json — mochikit. Is tested on ie, ff and the mac browser — is tested hard. Javascript that Doesn’t make you want to shoot yourself in the head. It has a version of the script.acoul.us but uses mochikit instead of prototype. Bob is said to be a testing task master.

    hint:
    Don’t get caught in the DOM scripting cess pool. 2 secs to download and 20 secs to render. That is bad. DOM scripting is not evil but too much of it is.

    Mochikit and Animations and here

     Posted by at 4:59 pm
    Jan 052007
     

    I tried setting up a workingenv for playing with SQLAlchemy today but I ran into a number of problems. First, since I had installed pysqlite2 via Synaptix, easy_install was not finding the package. So I had to uninstall the pysqlite2 that I had installed with Synaptix and then install with easy_setup.

    However, there is a bug for pysqlite on cheeseshop and no download is listed. So after inquiring on the TG mailing list, I tried:
    easy_install -f http://initd.org/pub/software/pysqlite/releases/2.3/2.3.2/ pysqlite

    but that failed because it couldn’t find the sqlite headers.
    In file included from src/module.c:24:
    src/connection.h:33:21: error: sqlite3.h: No such file or directory
    ...
    error: Setup script exited with error: command 'gcc' failed with exit status 1

    So I installed the libsqlite3-dev package via Synaptix — and finally all was right with the world.

    I couldn’t get pysqlite to install fully into the workingenv, so I had to install it on the base system and then when I issued the
    easy_install -f http://initd.org/pub/software/pysqlite/releases/2.3/2.3.2/ pysqlite
    in the workingenv a proper entry was made pointing back to the package in site-packages
    Adding pysqlite 2.3.2 to easy-install.pth file
    Using /usr/lib/python2.4/site-packages/pysqlite-2.3.2-py2.4-linux-i686.egg

     Posted by at 9:48 pm