Dear all,

I'm quite confused to use Session like a global statement through
different parts of a web program. The directory structure is the
following:

WebML/
     +- webml.py (main program)
     +- globals.py 
     +- managers/
              +- __init__.py
              +- users_schema.py
              +- emails_schema.py
              +- ml_schema.py

So, in the main program webml.py I have:

from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import mapper, scoped_session, sessionmaker
from  managers import users_schema, ml_schema, emails_schema
class HttpProtected:
    def __init__(self):
        
        engine=create_engine('postgres://[EMAIL 
PROTECTED]/webml',strategy='threadlocal') 
        Session = scoped_session(sessionmaker(autoflush=True,
transactional=True)) 
        session=Session(bind=engine) 
        self.m=ml_schema.MLManager()
        self.u=users_schema.UsersManager()
        self.e=emails_schema.EmailsManager()

In managers/users_schema.py I have:

from sqlalchemy import Table, MetaData
from sqlalchemy.orm import  relation, class_mapper, mapper
import ml_schema

class Users(object):
    pass 

class UsersManager(object):
    def __init__(self):
        metadata=MetaData('postgres://[EMAIL PROTECTED]/webml')   
        users = Table('users', metadata, autoload=True)
        ml_users=Table('ml_users', metadata, autoload=True)
        usersmapper = mapper(Users, users, properties = {
            'ml' : relation(ml_schema.ML, secondary = ml_users,
backref='users') })
    
    def saveNewUser(self,  kw):
        session=Session()
        

It's clear that saveNewUser doesn't works, because doesn't find
Session(). I tried to put the Session initialization everywhere (except
where it has to be :-)) without success. Where I have to put Session
initialization to use it globally?


Thanks in advance
-- 
-------------------------------------------------------------------
       (o_
(o_    //\  Coltivate Linux che tanto Windows si pianta da solo.
(/)_   V_/_
+------------------------------------------------------------------+
|     ENRICO MORELLI         |  email: [EMAIL PROTECTED]       |
| *     *       *       *    |  phone: +39 055 4574269             |
|  University of Florence    |  fax  : +39 055 4574253             |
|  CERM - via Sacconi, 6 -  50019 Sesto Fiorentino (FI) - ITALY    |
+------------------------------------------------------------------+

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to