+import elixir
import logging
from openid.consumer.consumer import Consumer
from openid.extensions.sreg import SRegRequest, SRegResponse
from pylons.controllers.util import abort, redirect_to
from routes import url_for, request_config
-from floof import model
-from floof.model.meta import Session
from floof.lib.base import BaseController, render
+from floof.model.users import IdentityURL, User
log = logging.getLogger(__name__)
try:
# Grab an existing user record, if one exists
- q = Session.query(model.User) \
- .filter(model.User.identity_urls.any(url=res.identity_url))
+ q = User.query.filter(User.identity_urls.any(url=res.identity_url))
user = q.one()
except NoResultFound:
# Try to pull a name out of the SReg response
username = 'Anonymous'
# Create db records
- user = model.User(name=username)
- Session.add(user)
- identity_url = model.IdentityURL(url=res.identity_url)
+ user = User(name=username)
+ identity_url = IdentityURL(url=res.identity_url)
user.identity_urls.append(identity_url)
- Session.commit()
+ elixir.session.commit()
# Remember who's logged in, and we're good to go
session['user_id'] = user.id
session.save()
- return "Hello, %s from %s" % (user.name, res.identity_url)
+ # XXX send me where I came from
+ redirect_to('/')
import logging
+import elixir
from pylons import request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect_to
from floof.lib.base import BaseController, render
-from floof.model import meta
from floof.model.art import Art
log = logging.getLogger(__name__)
class MainController(BaseController):
def index(self):
- c.artwork = meta.Session.query(Art).order_by(Art.id.desc()).all()
+ c.artwork = Art.query.order_by(Art.id.desc()).all()
return render('/index.mako')
from pylons.controllers import WSGIController
from pylons.templating import render_mako as render
-from floof import model
-from floof.model import meta
+from floof.model.users import User
class BaseController(WSGIController):
def __before__(self, action, **params):
# Fetch current user object
try:
- c.user = meta.Session.query(model.User).get(session['user_id'])
+ c.user = User.query.get(session['user_id'])
except:
pass
from floof.model import meta
import elixir
-elixir.session = meta.Session
-Session = elixir.session
elixir.options_defaults.update({ 'autoload': True, 'shortnames': True })
metadata = elixir.metadata
-"""SQLAlchemy Metadata and Session object"""
+"""SQLAlchemy Metadata object"""
from sqlalchemy import MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
-__all__ = ['Session', 'engine', 'metadata']
+__all__ = ['engine', 'metadata']
# SQLAlchemy database engine. Updated by model.init_model()
engine = None
-# SQLAlchemy session manager. Updated by model.init_model()
-Session = scoped_session(sessionmaker())
-
metadata = MetaData()