Browse files

tring to fix sqlalchemy problem

  • Loading branch information...
1 parent 5ab2fc6 commit 61404635f62afef374b87f06bdcd30780e5080eb David Shieh committed Mar 4, 2010
Showing with 9 additions and 8 deletions.
  1. +2 −0 models.py
  2. +7 −8 views.py
View
2 models.py
@@ -4,8 +4,10 @@
from sqlalchemy import Column, Integer, String, Text, DateTime
from sqlalchemy.orm import relation, backref
from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import sessionmaker
engine = create_engine('mysql://root:root@localhost/davidblog_new?charset=utf8')
+Session = sessionmaker(bind=engine)
Base = declarative_base()
metadata = Base.metadata
View
15 views.py
@@ -7,29 +7,28 @@
from forms import commentForm
from settings import db, render, pageCount
from cache import mcache
-from sqlalchemy.orm import scoped_session, sessionmaker
+#from sqlalchemy.orm import scoped_session, sessionmaker
from models import *
from utils import Pagination, getCaptcha
from markdown import markdown
d = dict()
def getTags():
- return list(db.query(
- 'SELECT * FROM tags ORDER BY name ASC'))
+ return web.ctx.orm.query(Tag).order_by('tags.name').all()
def getLinks():
- return list(db.query(
- 'SELECT * FROM links ORDER BY name ASC'))
+ return web.ctx.orm.query(Link).order_by('links.name').all()
def my_handler(handler):
- d['tags'] = getTags()
- d['links'] = getLinks()
d['startTime'] = time.time()
web.ctx.session = web.config._session
- web.ctx.orm = scoped_session(sessionmaker(bind=engine))
+ web.ctx.orm = Session()
+ d['tags'] = getTags()
+ d['links'] = getLinks()
try:
return handler()
+ web.ctx.orm.close()
except web.HTTPError:
web.ctx.orm.commit()
raise

0 comments on commit 6140463

Please sign in to comment.