コード例 #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