Esempio n. 1
0
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()
Esempio n. 2
0
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.")
Esempio n. 3
0
 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()
Esempio n. 4
0
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
Esempio n. 5
0
def find_news(id):
    return Session.query(News).get(id)
Esempio n. 6
0
def find_document(id):
    return Session.query(Document).get(id)
Esempio n. 7
0
def find_image(id):
    return Session.query(Image).get(id)
Esempio n. 8
0
def listImages():
    q = Session.query(Image).order_by(Image.filename)
    return q.count(), q
Esempio n. 9
0
def listDocuments():
    q = Session.query(Document).order_by(Document.filename)
    return q.count(), q
Esempio n. 10
0
def listCMSUsers():
    q = Session.query(CMSUser).order_by(CMSUser.fullname)
    return q.count(), q
Esempio n. 11
0
def save(obj):
    Session.add(obj)
Esempio n. 12
0
def delete(obj):
    Session.delete(obj)
Esempio n. 13
0
def reattach(obj):
    Session.add(obj)
Esempio n. 14
0
def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    Session.configure(bind=engine)