Commits

Anonymous committed 08a7ca7

Updated shorty and plnt to SQLAlchemy 0.6. Also upgraded plnt to Jinja2.

Comments (0)

Files changed (7)

docs/tutorial.rst

 
     metadata = MetaData()
     session = scoped_session(lambda: create_session(application.database_engine,
-                             transactional=True), local_manager.get_ident)
+                             autocommit=False, autoflush=False),
+                             local_manager.get_ident)
 
     url_map = Map()
     def expose(rule, **kw):

examples/manage-plnt.py

 
 def action_initdb():
     """Initialize the database"""
-    from plnt.database import Blog, Session
+    from plnt.database import Blog, session
     make_app().init_database()
     # and now fill in some python blogs everybody should read (shamelessly
     # added my own blog too)
-    Blog('Armin Ronacher', 'http://lucumr.pocoo.org/',
-         'http://lucumr.pocoo.org/cogitations/feed/'),
-    Blog('Georg Brandl', 'http://pyside.blogspot.com/',
-         'http://pyside.blogspot.com/feeds/posts/default')
-    Blog('Ian Bicking', 'http://blog.ianbicking.org/',
-         'http://blog.ianbicking.org/feed/')
-    Blog('Amir Salihefendic', 'http://amix.dk/',
-         'http://feeds.feedburner.com/amixdk')
-    Blog('Christopher Lenz', 'http://www.cmlenz.net/blog/',
-         'http://www.cmlenz.net/blog/atom.xml')
-    Blog('Frederick Lundh', 'http://online.effbot.org/',
-         'http://online.effbot.org/rss.xml')
+    blogs = [
+        Blog('Armin Ronacher', 'http://lucumr.pocoo.org/',
+             'http://lucumr.pocoo.org/cogitations/feed/'),
+        Blog('Georg Brandl', 'http://pyside.blogspot.com/',
+             'http://pyside.blogspot.com/feeds/posts/default'),
+        Blog('Ian Bicking', 'http://blog.ianbicking.org/',
+             'http://blog.ianbicking.org/feed/'),
+        Blog('Amir Salihefendic', 'http://amix.dk/',
+             'http://feeds.feedburner.com/amixdk'),
+        Blog('Christopher Lenz', 'http://www.cmlenz.net/blog/',
+             'http://www.cmlenz.net/blog/atom.xml'),
+        Blog('Frederick Lundh', 'http://online.effbot.org/',
+             'http://online.effbot.org/rss.xml')
+    ]
     # okay. got tired here.  if someone feels that he is missing, drop me
     # a line ;-)
-    Session().commit()
+    for blog in blogs:
+        session.add(blog)
+    session.commit()
     print 'Initialized database, now run manage-plnt.py sync to get the posts'
 
 

examples/plnt/database.py

 """
 from sqlalchemy import MetaData, Table, Column, ForeignKey, Boolean, \
      Integer, String, DateTime
-from sqlalchemy.orm import dynamic_loader, scoped_session, create_session
+from sqlalchemy.orm import dynamic_loader, scoped_session, create_session, \
+     mapper
 from plnt.utils import application, local_manager
 
 
 def new_db_session():
     return create_session(application.database_engine, autoflush=True,
-                          transactional=True)
+                          autocommit=False)
 
 metadata = MetaData()
-Session = scoped_session(new_db_session, local_manager.get_ident)
+session = scoped_session(new_db_session, local_manager.get_ident)
 
 
 blog_table = Table('blogs', metadata,
 
 
 class Blog(object):
+    query = session.query_property()
 
     def __init__(self, name, url, feed_url, description=u''):
         self.name = name
 
 
 class Entry(object):
+    query = session.query_property()
 
     def __repr__(self):
         return '<%s %r>' % (self.__class__.__name__, self.guid)
 
 
-Session.mapper(Entry, entry_table)
-Session.mapper(Blog, blog_table, properties=dict(
+mapper(Entry, entry_table)
+mapper(Blog, blog_table, properties=dict(
     entries=dynamic_loader(Entry, backref='blog')
 ))

examples/plnt/sync.py

 from time import time
 from datetime import datetime
 from werkzeug import escape
-from plnt.database import Blog, Entry, Session
+from plnt.database import Blog, Entry, session
 from plnt.utils import strip_tags, nl2p
 
 
             entry.text = text
             entry.pub_date = pub_date
             entry.last_update = updated
+            session.add(entry)
 
-    Session().commit()
+    session.commit()

examples/plnt/utils.py

 """
 import re
 from os import path
-from jinja import Environment, FileSystemLoader
+from jinja2 import Environment, FileSystemLoader
 from werkzeug import Response, Local, LocalManager, url_encode, \
      url_quote, cached_property
 from werkzeug.routing import Map, Rule

examples/plnt/webapp.py

 from werkzeug import SharedDataMiddleware, ClosingIterator, Request
 from werkzeug.exceptions import HTTPException, NotFound
 from plnt.utils import local, local_manager, url_map, endpoints
-from plnt.database import Session, metadata
+from plnt.database import session, metadata
 
 # import the views module because it contains setup code
 import plnt.views
         except HTTPException, e:
             response = e
         return ClosingIterator(response(environ, start_response),
-                               Session.remove)
+                               session.remove)
 
     def __call__(self, environ, start_response):
         return self._dispatch(environ, start_response)

examples/shorty/utils.py

 url_map = Map([Rule('/static/<file>', endpoint='static', build_only=True)])
 
 session = scoped_session(lambda: create_session(application.database_engine,
-                         transactional=True), local_manager.get_ident)
+                                                autocommit=False,
+                                                autoflush=False))
 jinja_env = Environment(loader=FileSystemLoader(TEMPLATE_PATH))