1 | """The application's model objects""" |
---|
2 | |
---|
3 | from zope.sqlalchemy import ZopeTransactionExtension |
---|
4 | from sqlalchemy.orm import scoped_session, sessionmaker |
---|
5 | #from sqlalchemy import MetaData |
---|
6 | from sqlalchemy.ext.declarative import declarative_base |
---|
7 | |
---|
8 | # Global session manager. DBSession() returns the session object |
---|
9 | # appropriate for the current web request. |
---|
10 | maker = sessionmaker(autoflush=True, autocommit=False, |
---|
11 | extension=ZopeTransactionExtension()) |
---|
12 | DBSession = scoped_session(maker) |
---|
13 | |
---|
14 | # By default, the data model is defined with SQLAlchemy's declarative |
---|
15 | # extension, but if you need more control, you can switch to the traditional |
---|
16 | # method. |
---|
17 | |
---|
18 | DeclarativeBase = declarative_base() |
---|
19 | |
---|
20 | # Global metadata. |
---|
21 | # The default metadata is the one from the declarative base. |
---|
22 | metadata = DeclarativeBase.metadata |
---|
23 | |
---|
24 | # If you have multiple databases with overlapping table names, you'll need a |
---|
25 | # metadata for each database. Feel free to rename 'metadata2'. |
---|
26 | #metadata2 = MetaData() |
---|
27 | |
---|
28 | ##### |
---|
29 | # Generally you will not want to define your table's mappers, and data objects |
---|
30 | # here in __init__ but will want to create modules them in the model directory |
---|
31 | # and import them at the bottom of this file. |
---|
32 | # |
---|
33 | ###### |
---|
34 | |
---|
35 | def init_model(engine): |
---|
36 | """Call me before using any of the tables or classes in the model.""" |
---|
37 | |
---|
38 | DBSession.configure(bind=engine) |
---|
39 | # If you are using reflection to introspect your database and create |
---|
40 | # table objects for you, your tables must be defined and mapped inside |
---|
41 | # the init_model function, so that the engine is available if you |
---|
42 | # use the model outside tg2, you need to make sure this is called before |
---|
43 | # you use the model. |
---|
44 | |
---|
45 | # |
---|
46 | # See the following example: |
---|
47 | |
---|
48 | #global t_reflected |
---|
49 | |
---|
50 | #t_reflected = Table("Reflected", metadata, |
---|
51 | # autoload=True, autoload_with=engine) |
---|
52 | |
---|
53 | #mapper(Reflected, t_reflected) |
---|
54 | |
---|
55 | # Import your model modules here. |
---|
56 | from sipbmp3web.model.auth import User, Group, Permission |
---|