Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from sqlalchemy.orm import *
from sqlalchemy import Table, Column, ForeignKey, Integer
from sqlalchemy.types import Integer, Unicode, String, DateTime
from pylons_openid.model import meta
def init_model(engine):
"""Call me before using any of the tables or classes in the model"""
meta.Session.configure(bind=engine)
meta.engine = engine
user_table = Table('user', meta.metadata,
Column('id', Integer, primary_key=True),
Column('username', String(128), nullable=False),
Column('password', String(128), nullable=False),
Column('acl', String(16), nullable=False),
Column('name', String(32), nullable=False),
Column('dateLogin', DateTime),
Column('sessionId', String(32)),
Column('ip', String(16)),
useexisting=True
)
user_openid_table = Table('user_openid', meta.metadata,
Column('id', Integer, primary_key=True),
Column('verifiedEmail', String(200), nullable=False),
Column('displayName', String(200), nullable=False),
Column('preferredUsername', String(200), nullable=False),
Column('providerName', String(100), nullable=False),
Column('identifier', String(200), nullable=False),
Column('email', String(200), nullable=False),
Column('user_id', Integer, ForeignKey("user.id")),
useexisting=True
)
class User(object):
def __init__(self, id=None, username=None, password=None, acl=None, name=None, dateLogin=None, sessionId=None, ip=None):
self.id = id
self.username = username
self.password = password
self.acl = acl
self.name = name
self.dateLogin = dateLogin
self.sessionId = sessionId
self.ip = ip
def __repr__(self):
return self.name
class UserOpenId(object):
def __init__(self, id=None, verifiedEmail=None, displayName=None, preferredUsername=None, providerName=None, identifier=None, email=None, user_id=None):
self.id = id
self.verifiedEmail = verifiedEmail
self.displayName = displayName
self.preferredUsername = preferredUsername
self.providerName = providerName
self.identifier = identifier
self.email = email
self.user_id = user_id
def __repr__(self):
return "%s (%s) %s" % (self.providerName, self.verifiedEmail, self.identifier)
mapper(User, user_table, properties={
"openids": relation(UserOpenId)
})
mapper(UserOpenId, user_openid_table, properties={
"user": relation(User)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.