Charles Duffy wrote:
My initial impression is positive, even though it's just been a quick
glance so far. One issue: Identity and visit tracking haven't been
updated to match. I'll try my hand at a patch in an hour or so if
nobody's beat me to it.
Okay. Here are the issues I ran into:
- Defining default tables (inside visit.savisit and identity.saprovider)
with the same turbogears.database.metadata which users may later use to
define their *own* tg_user, tg_visit, etc. classes just doesn't work. I
solved this by simply taking the default tables/classes out of
identity.saprovider (since the templates should be providing their own
models for these, right?). That may not be the Right Way, though, since
it forces everyone to define their own identity classes even if they're
not changing anything; perhaps the configuration should be checked, and
these classes should be defined only if the identity.saprovider.model.*
configuration settings point to the classes in question?
- assign_mapper takes a ctx argument, which savisit's TG_Visit
definition wasn't providing. I sidestepped the whole thing by using
ActiveMapper.
- TG_Visit.created wasn't being assigned a value; I had exceptions being
thrown because of attempts to create columns with null values in the
mandatory timestamp field. Set default=datetime.now for the column,
resolving this.
This patch does not yet attempt to make quickstarted SQLAlchemy apps
work out-of-the-box.
Index: turbogears/identity/saprovider.py
===================================================================
--- turbogears/identity/saprovider.py (revision 1602)
+++ turbogears/identity/saprovider.py (working copy)
@@ -7,16 +7,19 @@
from datetime import *
from sqlalchemy import *
from sqlalchemy.ext.activemapper import *
+import sqlalchemy.ext.activemapper as activemapper
import logging
log = logging.getLogger("turbogears.identity.saprovider")
from turbogears import identity
+from turbogears.database import metadata
-__engine__= turbogears.database.PackageEngine( 'turbogears.identity' )
-
from turbogears.util import load_class
+turbogears.database.bind_meta_data()
+activemapper.metadata = turbogears.database.metadata
+
try:
set, frozenset
except NameError:
@@ -208,78 +211,3 @@
'''
return SqlAlchemyIdentity( None )
-
-user_group = Table("tg_user_group", __engine__,
- Column("user_id", Integer,
- ForeignKey("tg_user.user_id"),
- primary_key = True),
- Column("group_id", Integer,
- ForeignKey("tg_group.group_id"),
- primary_key = True))
-
-group_permission = Table("tg_group_permission", __engine__,
- Column("group_id", Integer,
- ForeignKey("tg_group.group_id"),
- primary_key = True),
- Column("permission_id", Integer,
- ForeignKey("permission.permission_id"),
- primary_key = True))
-
-
-class VisitIdentity(ActiveMapper):
- class mapping:
- __table__ = "tg_visit_identity"
- visit_key = column(String, # foreign_key = "visit.visit_key",
- primary_key = True)
- user_id = column(Integer, foreign_key = "tg_user.user_id", index = True)
-
-
-class Group(ActiveMapper):
- """
- An ultra-simple group definition.
- """
- class mapping:
- __table__ = "tg_group"
- group_id = column(Integer, primary_key = True)
- group_name = column(Unicode(16), unique = True)
- display_name = column(Unicode(255))
- created = column(DateTime, default = datetime.now)
-
- #users = many_to_many("User", user_group, backref = "groups")
- #permissions = many_to_many("Permission", group_permission,
- # backref = "groups")
-
-
-class User(ActiveMapper):
- """
- Reasonably basic User definition. Probably would want additional attributes.
- """
- class mapping:
- __table__ = "tg_user"
- user_id = column(Integer, primary_key = True)
- user_name = column(Unicode(16), unique = True)
- email_address = column(Unicode(255), unique = True)
- display_name = column(Unicode(255))
- password = column(Unicode(40))
- created = column(DateTime, default = datetime.now)
-
- groups = many_to_many("Group", user_group, backref = "users")
-
- @property
- def permissions(self):
- perms = set()
- for g in self.groups:
- perms = perms | set(g.permissions)
- return perms
-
-
-class Permission(ActiveMapper):
- class mapping:
- __table__ = "tg_permission"
- permission_id = column(Integer, primary_key = True)
- permission_name = column(Unicode(16), unique = True)
- description = column(Unicode(255))
-
- groups = many_to_many("Group", group_permission,
- backref = "permissions")
-
Index: turbogears/visit/savisit.py
===================================================================
--- turbogears/visit/savisit.py (revision 1602)
+++ turbogears/visit/savisit.py (working copy)
@@ -1,15 +1,16 @@
import turbogears
from datetime import *
+from turbogears.database import metadata
from turbogears.visit.api import BaseVisitManager, Visit
+import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext.activemapper import *
import logging
log = logging.getLogger("turbogears.identity.savisit")
-__engine__= turbogears.database.PackageEngine( 'turbogears.visit' )
+turbogears.database.bind_meta_data()
-
class SqlAlchemyVisitManager(BaseVisitManager):
def __init__(self, timeout):
super(SqlAlchemyVisitManager,self).__init__( timeout )
@@ -17,13 +18,13 @@
def create_model(self):
try:
TG_Visit.table.create()
- objectstore.commit()
- except SQLError:
+ except sqlalchemy.exceptions.SQLError:
pass
+ except sqlalchemy.exceptions.ArgumentError:
+ pass
def new_visit_with_key(self, visit_key):
visit= TG_Visit( visit_key=visit_key, expiry=datetime.now()+self.timeout )
- visit.commit()
return Visit( visit_key, True )
def visit_for_key(self, visit_key):
@@ -54,20 +55,14 @@
raise
-tbl__tgvisit = Table('tg_visit', __engine__,
- Column('visit_key', String(40) , primary_key=True),
- Column('created', DateTime , nullable = False ),
- Column('expiry', DateTime ),
-)
+class TG_Visit(ActiveMapper):
+ class mapping:
+ __table__ = 'tg_visit'
+ visit_key = column(String(40), primary_key=True)
+ created = column(DateTime, nullable=False, default=datetime.now)
+ expiry = column(DateTime)
-
-class TG_Visit(object):
- table = tbl__tgvisit
-
def lookup_visit( cls, visit_key ):
return TG_Visit.get( visit_key );
lookup_visit= classmethod(lookup_visit)
-assign_mapper( TG_Visit , tbl__tgvisit )
-
-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users