def commit(): """ This method is a replacement for the meta.Session.commit() method. This commits both sessions and removes the need to act with Session's or metadata in logic. """ Session.commit()
def find_cmsuser(id=None, username=None): if id is not None: return Session.query(CMSUser).get(id) elif username is not None: return Session.query(CMSUser).filter(CMSUser.username == username)\ .one() else: raise Exception("No id or username supplied. Go away.")
def __call__(self, environ, start_response): """Invoke the Controller""" # WSGIController.__call__ dispatches to the Controller method # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] try: return WSGIController.__call__(self, environ, start_response) finally: Session.remove()
def list_news(**kargs): q = Session.query(News) if not session.get('cmsuser'): q = q.filter(News.active == True) # noqa q = q.order_by(News.created.desc()) num = q.count() if 'limit' not in kargs: q = q.limit(int(config['items_per_page'])) else: if kargs.get('limit'): q = q.limit(kargs.get('limit')) if kargs.get('page'): q = q.offset(_getOffset(kargs.get('page'))) return num, q
def find_news(id): return Session.query(News).get(id)
def find_document(id): return Session.query(Document).get(id)
def find_image(id): return Session.query(Image).get(id)
def listImages(): q = Session.query(Image).order_by(Image.filename) return q.count(), q
def listDocuments(): q = Session.query(Document).order_by(Document.filename) return q.count(), q
def listCMSUsers(): q = Session.query(CMSUser).order_by(CMSUser.fullname) return q.count(), q
def save(obj): Session.add(obj)
def delete(obj): Session.delete(obj)
def reattach(obj): Session.add(obj)
def init_model(engine): """Call me before using any of the tables or classes in the model""" Session.configure(bind=engine)