Permalink
Browse files

fix some bug

  • Loading branch information...
1 parent 6140463 commit 078a6592c48e9df807b84e7fe9e41ad91f25cda0 David committed Mar 5, 2010
Showing with 8 additions and 9 deletions.
  1. +1 −3 models.py
  2. +7 −6 views.py
View
@@ -4,10 +4,8 @@
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)
+engine = create_engine('mysql://root:root@localhost/davidblog_new?charset=utf8', echo=False)
Base = declarative_base()
metadata = Base.metadata
View
@@ -7,7 +7,7 @@
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
@@ -20,22 +20,23 @@ def getTags():
def getLinks():
return web.ctx.orm.query(Link).order_by('links.name').all()
-def my_handler(handler):
- d['startTime'] = time.time()
+def my_loadhook():
web.ctx.session = web.config._session
- web.ctx.orm = Session()
+ d['startTime'] = time.time()
+
+def my_handler(handler):
+ web.ctx.orm = scoped_session(sessionmaker(bind=engine))
d['tags'] = getTags()
d['links'] = getLinks()
try:
return handler()
- web.ctx.orm.close()
except web.HTTPError:
web.ctx.orm.commit()
raise
except:
web.ctx.orm.rollback()
raise
- else:
+ finally:
web.ctx.orm.commit()
class captcha:

0 comments on commit 078a659

Please sign in to comment.