예제 #1
0
파일: __init__.py 프로젝트: ttyunix/proxyip
 def save(self, session=None):
     """Save this object."""
     if not session:
         session = get_session()
     session.add(self)
     try:
         session.flush()
     except IntegrityError, e:
         if str(e).endswith('is not unique'):
             raise e
         else:
             raise
예제 #2
0
파일: api.py 프로젝트: ttyunix/proxyip
def model_query(model, *args, **kwargs):
    session = kwargs.get('session') or get_session()
    read_deleted = kwargs.get('read_deleted') or 'no'

    query = session.query(model, *args)

    if read_deleted == 'no':
        query = query.filter_by(deleted=0)
    elif read_deleted == 'yes':
        pass  # omit the filter to include deleted and active
    elif read_deleted == 'only':
        query = query.filter_by(deleted=1)
    else:
        raise Exception(
                _("Unrecognized read_deleted value '%s'") % read_deleted)
    return query