当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.query方法代码示例

本文整理汇总了Python中tap.models.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tap.models.DBSession的用法示例。


在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_userperm

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
    def get_userperm(self, perm_name):
        # import pdb; pdb.set_trace()
        with transaction.manager:
            need_permission, action = perm_name.split(':')
            permission = DBSession.query(TapPermission).filter_by(
                name=need_permission).first()
            user_perm = DBSession.query(TapUserPermission).filter_by(
                user_id=self.request.user.id, permission_id=permission.id).first()

            user_perm = TempPermission(user_perm)

            if not need_permission.startswith('SYS') and '.' in need_permission:
                # if parent-permission has the authorization,
                # also child-permission has it.
                permissions = need_permission.split('.')
                for i in range(len(permissions)):
                    permission = '.'.join(permissions[:i+1])
                    permission = DBSession.query(TapPermission).filter_by(
                        name=permission
                    ).first()
                    if not permission:
                        continue
                    _perm = DBSession.query(TapUserPermission).filter_by(
                        user_id=self.request.user.id,
                        permission_id=permission.id
                    ).first()
                    if _perm:
                        user_perm.a_add = (user_perm.a_add or _perm.a_add)
                        user_perm.a_edit = (user_perm.a_edit or _perm.a_edit)
                        user_perm.a_delete = (user_perm.a_delete or
                                              _perm.a_delete)
                        user_perm.a_view = (user_perm.a_view or _perm.a_view)
            return user_perm
开发者ID:vincentwyshan,项目名称:tap,代码行数:35,代码来源:security.py

示例2: user_save

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
 def user_save(self):
     result = dict(success=0, message="")
     try:
         with transaction.manager:
             user = None
             user_id = self.request.params.get('id')
             if user_id:
                 user = DBSession.query(TapUser).get(user_id)
             else:
                 name_valid(self.request.params['name'])
                 user = DBSession.query(TapUser).filter_by(
                     name=self.request.params['name']).first()
                 if user:
                     raise Exception("用户名重复")
                 user = TapUser()
                 DBSession.add(user)
                 user.name = self.request.params.get('name').strip()
             obj_setattr(user, 'full_name', self.request)
             obj_setattr(user, 'description', self.request)
             if 'is_admin' in self.request.params:
                 user.is_admin = int(self.request.params['is_admin'])
             if 'password' in self.request.params:
                 password = self.request.params.get('password').strip()
                 assert len(password) >= 6, '密码长度最少为6'
                 if 'password-repeat' in self.request.params:
                     password_repeat = self.request.params['password-repeat']
                     assert password == password_repeat, "两次输入密码不匹配"
                 user.password = encrypt_password(password.encode('utf8'))
         result["success"] = 1
     except BaseException, e:
         result["message"] = str(e)
开发者ID:vincentwyshan,项目名称:tap,代码行数:33,代码来源:actions.py

示例3: gen_breadcrumbs

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
def gen_breadcrumbs(request):
    result = []
    if request.path.startswith('/management/database'):
        result.append(
            {"url": '/management/database', "class": "active", "text": u"数据库"}
        )
        if request.matchdict.get('dbconn_id') is not None:
            with transaction.manager:
                dbconn_id = request.matchdict['dbconn_id']
                dbconn = DBSession.query(TapDBConn).get(dbconn_id)
                result.append(
                    {"class": "active", "text": dbconn.name}
                )
    elif request.path == '/management/project':
        result.append(
            {"url": '/management/project', "class": "active", "text": u"项目"}
        )
    elif re.match(ur"/management/project/\d+", request.path):
        project_id = re.findall(r'\d+', request.path)[0]
        with transaction.manager:
            project = DBSession.query(TapProject).get(project_id)
            result.append(
                {"url": '/management/project', "class": "", "text": u"项目"},
            )
            result.append(
                {"class": "active", "text": project.cnname},
            )
开发者ID:vincentwyshan,项目名称:tap,代码行数:29,代码来源:uicontrol.py

示例4: flush_log_stats

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
def flush_log_stats(occurrence_time, api_id, client_id, elapse):
    with transaction.manager:
        api = DBSession.query(TapApi).get(api_id)
        if not api:
            warnings.warn("API:%s is not exist." % api_id)
            return

        q = DBSession.query(TapApiStats)\
            .filter_by(api_id=api_id, occurrence_time=occurrence_time,
                       client_id=client_id)
        stats = q.first()
        if not stats:
            stats = TapApiStats(api_id=api_id, project_id=api.project_id,
                                occurrence_time=occurrence_time,
                                client_id=client_id)
            DBSession.add(stats)
            DBSession.flush()

        # row-lock update
        print '\tName:', api.name, ', ClientId:', client_id, \
            ', Occurrence:', elapse['occurrence_total']
        stats = DBSession.query(TapApiStats).with_lockmode('update')\
            .filter(TapApiStats.id == stats.id).first()

        stats.occurrence_time = occurrence_time
        stats.occurrence_total += elapse['occurrence_total']
        stats.exception_total += elapse['exception_total']
        if stats.elapse_max < elapse['elapse_max']:
            stats.elapse_max = elapse['elapse_max']
        if stats.elapse_min < elapse['elapse_min']:
            stats.elapse_min = elapse['elapse_min']
        stats.elapse_sum += elapse['elapse_sum']
        # print stats.occurrence_total, elapse
        stats.elapse_avg = stats.elapse_sum / stats.occurrence_total
开发者ID:vincentwyshan,项目名称:tap,代码行数:36,代码来源:rpcstats.py

示例5: permission_save

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
 def permission_save(self):
     result = dict(success=0, message="")
     with transaction.manager:
         user_id = self.request.params['user_id']
         permissions = self.request.params['permissions']
         db_list = DBSession.query(TapUserPermission).filter_by(
             user_id=user_id)
         for permission in db_list:
             DBSession.delete(permission)
         # permissionid-view:1,add:0,delete,0,edit,0;
         for section in permissions.split(';'):
             permission_id, permission_str = section.split('-')
             permission = DBSession.query(TapPermission).get(permission_id)
             if not permission:
                 result["message"] = "不存在的Permission Id: %s" \
                                     % permission_id
                 return result
             upermission = TapUserPermission(user_id=user_id,
                                             permission_id=permission_id)
             DBSession.add(upermission)
             for detail in permission_str.split(','):
                 print detail
                 permission_type, value = detail.split(':')
                 value = int(value)
                 if permission_type == 'view':
                     upermission.a_view = value
                 elif permission_type == 'add':
                     upermission.a_add = value
                 elif permission_type == 'delete':
                     upermission.a_delete = value
                 elif permission_type == 'edit':
                     upermission.a_edit = value
     result['success'] = 1
     return result
开发者ID:vincentwyshan,项目名称:tap,代码行数:36,代码来源:actions.py

示例6: cache_get

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
 def cache_get(self):
     result = dict(success=0, message="")
     api_id = int(self.request.params['api_id'])
     version = int(self.request.params['version'])
     with transaction.manager:
         api = DBSession.query(TapApi).get(api_id)
         release = DBSession.query(TapApiRelease)\
             .filter_by(api_id=api.id, version=version).first()
         config = dict2api(json.loads(release.content))
         data = cache_get(config, release.version, dict(self.request.params))
         result['data'] = data
     result['success'] = 1
     return result
开发者ID:vincentwyshan,项目名称:tap,代码行数:15,代码来源:actions.py

示例7: validate

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
def validate(captcha_id, code):
    with transaction.manager:
        captcha = DBSession.query(CaptchaCode).get(captcha_id)
        if not captcha:
            return False
        # 大约有 1% 的概率,执行清除一天前的旧数据任务
        if random.random() < 0.01:
            today = datetime.date.today()
            today = datetime.datetime(today.year, today.month, today.day)
            DBSession.query(CaptchaCode).filter(
                CaptchaCode.created<today).delete()

        result = captcha.code.lower() == code.lower()
        DBSession.delete(captcha)
        return result
开发者ID:vincentwyshan,项目名称:tap,代码行数:17,代码来源:tcaptcha.py

示例8: project_save

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
 def project_save(self):
     result = dict(success=0, message="")
     try:
         with transaction.manager:
             project = None
             project_id = self.request.params.get('id')
             if project_id:
                 project = DBSession.query(TapProject).get(project_id)
             else:
                 name_valid(self.request.params.get('name'))
                 assert self.request.params.get('cnname') not in ('', None), "名称不能为空"
                 project = TapProject()
                 DBSession.add(project)
                 project.uid_create = self.request.userid
                 project.uid_owner = self.request.userid
                 project.name = self.request.params.get('name').strip().upper()
                 project.cnname = self.request.params.get('cnname').strip()
                 project.description = self.request.params.get('description')  or ''
                 permission = add_permission(
                     project.name, u'项目:' + project.name)
                 DBSession.flush()
                 add_user_permission(self.request.user, permission,
                                     True, True, True, True)
             if 'name' in self.request.params:
                 name_valid(self.request.params.get('name'))
                 project.name = self.request.params.get('name').strip().upper()
             obj_setattr(project, 'cnname', self.request)
             obj_setattr(project, 'description', self.request)
         result["success"] = 1
     except BaseException, e:
         result["message"] = str(e)
开发者ID:vincentwyshan,项目名称:tap,代码行数:33,代码来源:actions.py

示例9: release_save

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
    def release_save(self):
        result = dict(success=0, message="")
        request = self.request
        try:

            with transaction.manager:
                api_id = request.params.get('api_id')
                api_id = int(api_id)
                api = DBSession.query(TapApi).get(api_id)

                # auth type, change api
                auth_type = request.params['auth_type']
                if auth_type != api.auth_type:
                    api.auth_type = auth_type

                release = TapApiRelease()
                release.api_id = api.id
                release.project_name = api.project.name
                release.api_name = api.name
                # release.dbconn_id = api.dbconn_id
                release.version = request.params['version']
                release.notes = request.params['notes']
                release.uid_release = request.userid
                release.content = json.dumps(api2dict(api), cls=TapEncoder)
                DBSession.add(release)
                api.status = 'RELEASE'
                result["success"] = 1
        except BaseException, e:
            import traceback; traceback.print_exc()
            result["message"] = str(e)
开发者ID:vincentwyshan,项目名称:tap,代码行数:32,代码来源:actions.py

示例10: valid_key

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
def valid_key(key, config):
    """
    :param key: access_key
    :return: (bool, client_id)
    """
    if not key:
        return False, None

    if not config.auth_clients:
        return False, None

    # TODO Performance improvement. support redis/memcached/mongodb
    cache_client_id = get_val(key, expire=3600)
    if cache_client_id is not None:
        for auth in config.auth_clients:
            if auth.client_id == cache_client_id:
                return True, auth.client_id

    with transaction.manager:
        for auth in config.auth_clients:
            access_key = DBSession.query(TapApiAccessKey).filter_by(
                access_key=key, client_id=auth.client_id).first()
            if not access_key:
                # return False, None
                continue

            expire = access_key.access_expire
            if expire >= time.time():
                # set key again
                set_val(key, access_key.client_id)
                return True, access_key.client_id
        return False, access_key.client_id
开发者ID:vincentwyshan,项目名称:tap,代码行数:34,代码来源:auth.py

示例11: gen_active

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
def gen_active(request):
    result = dict()
    if request.path.startswith('/management/database'):
        result['active_database'] = True
    elif request.path.startswith('/management/project'):
        result['active_project'] = True
        try:
            result['current_project_id'] = int(request.matchdict['project_id'])
        except:
            pass
    elif request.path.startswith('/management/api'):
        result['active_project'] = True
        api_id = int(request.matchdict['api_id'])
        with transaction.manager:
            try:
                api = DBSession.query(TapApi).get(api_id)
                result['current_project_id'] = api.project.id
            except:
                pass
    elif request.path == '/':
        result['active_home'] = True
    elif request.path.startswith('/management/client'):
        result['active_client'] = True
    elif request.path.startswith('/management/user'):
        result['active_users'] = True
    elif request.path.startswith('/management/docs'):
        result['active_docs'] = True
    return result
开发者ID:vincentwyshan,项目名称:tap,代码行数:30,代码来源:uicontrol.py

示例12: authclient_token

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
 def authclient_token(self):
     result = dict(success=0, message="")
     with transaction.manager:
         auth_id = int(self.request.params['auth_id'])
         auth = DBSession.query(TapApiAuth).get(auth_id)
         result['token'] = auth.token
         result['success'] = 1
     return result
开发者ID:vincentwyshan,项目名称:tap,代码行数:10,代码来源:actions.py

示例13: cache_delete

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
    def cache_delete(self):
        result = dict(success=0, message="")
        api_id = int(self.request.params['api_id'])
        version = int(self.request.params['version'])
        with transaction.manager:
            try:
                api = DBSession.query(TapApi).get(api_id)
                release = DBSession.query(TapApiRelease)\
                    .filter_by(api_id=api.id, version=version).first()
                config = dict2api(json.loads(release.content))
                cache_delete(config, release.version, dict(self.request.params))
            except BaseException as e:
                result['message'] = str(e)
                return result

        result['success'] = 1
        return result
开发者ID:vincentwyshan,项目名称:tap,代码行数:19,代码来源:actions.py

示例14: gen_project_names

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
def gen_project_names(request):
    result = []
    with transaction.manager:
        projects = DBSession.query(TapProject).order_by(TapProject.id.desc())
        for project in projects:
            result.append(
                dict(id=project.id, name=project.cnname)
            )
        return result
开发者ID:vincentwyshan,项目名称:tap,代码行数:11,代码来源:uicontrol.py

示例15: cache_gen

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import query [as 别名]
 def cache_gen(self):
     result = dict(success=0, message='')
     api_id = int(self.request.params['api_id'])
     version = int(self.request.params['version'])
     with transaction.manager:
         try:
             api = DBSession.query(TapApi).get(api_id)
             release = DBSession.query(TapApiRelease)\
                 .filter_by(api_id=api.id, version=version).first()
             config = dict2api(json.loads(release.content))
             Program(config, release.version).run(dict(self.request.params))
         except BaseException as e:
             import traceback
             msg = traceback.format_exc()
             result['message'] = msg
             return result
     result['success'] = 1
     return result
开发者ID:vincentwyshan,项目名称:tap,代码行数:20,代码来源:actions.py


注:本文中的tap.models.DBSession.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。