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


Python DBSession.flush方法代码示例

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


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

示例1: project_save

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import flush [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

示例2: flush_log_stats

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import flush [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

示例3: gen_captcha

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import flush [as 别名]
def gen_captcha():
    with transaction.manager:
        code = random.sample(chars, 5)
        captcha = CaptchaCode()
        captcha.code = unicode(''.join(code))
        DBSession.add(captcha)
        DBSession.flush()
        assert captcha.id is not None
        return captcha.id
开发者ID:vincentwyshan,项目名称:tap,代码行数:11,代码来源:tcaptcha.py

示例4: para_new

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import flush [as 别名]
    def para_new(self):
        result = dict(success=0, message="")
        request = self.request
        api_id = request.params.get('id')
        try:

            with transaction.manager:
                api_id = int(api_id)
                para = TapParameter(api_id=api_id, name='__None__')
                DBSession.add(para)
                DBSession.flush()
                result["para_id"] = para.id
                result["para_name"] = '__None__'
                result["success"] = 1
        except BaseException, e:
            result["message"] = str(e)
开发者ID:vincentwyshan,项目名称:tap,代码行数:18,代码来源:actions.py

示例5: client_paranew

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import flush [as 别名]
    def client_paranew(self):
        result = dict(success=0, message="")
        request = self.request
        auth_id = request.params.get('id')
        try:

            with transaction.manager:
                auth_id = int(auth_id)
                para = TapApiClientCustomPara(customauth_id=auth_id,
                                              name='__None__')
                DBSession.add(para)
                DBSession.flush()
                result["para_id"] = para.id
                result["para_name"] = '__None__'
                result["success"] = 1
        except BaseException, e:
            result["message"] = str(e)
开发者ID:vincentwyshan,项目名称:tap,代码行数:19,代码来源:actions.py

示例6: flush_log_exc

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import flush [as 别名]
def flush_log_exc(occurrence_time, api_id, client_id, exc_trace, exc):
    hash_id = unicode(hash(exc_trace))
    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(TapApiErrors)\
            .filter_by(api_id=api_id, client_id=client_id, hash_id=hash_id)
        stats = q.first()
        if not stats:
            stats = TapApiErrors(api_id=api_id, client_id=client_id,
                                 project_id=api.project_id, hash_id=hash_id,
                                 occurrence_total=0,
                                 occurrence_time=occurrence_time,
                                 occurrence_first=exc['occurrence_first'])
            DBSession.add(stats)
            DBSession.flush()

        print '\tName:', api.name, ', ClientId:', client_id, ', Error:', \
            exc['exc_type'], 'Occurrence:', exc['occurrence_total']
        stats = DBSession.query(TapApiErrors).with_lockmode('update')\
            .filter(TapApiErrors.id==stats.id).first()

        stats.occurrence_time = occurrence_time
        # stats.occurrence_time = exc['occurrence_time']
        stats.occurrence_total += exc['occurrence_total']
        stats.exc_type = exc['exc_type']
        stats.exc_message = exc['exc_message']
        stats.exc_trace = exc_trace
        stats.exc_context = exc['exc_context']
        if exc['occurrence_first'] < stats.occurrence_first:
            stats.occurrence_first = exc['occurrence_first']
        if (not stats.occurrence_last
            or exc['occurrence_last'] > stats.occurrence_last):
            stats.occurrence_last = exc['occurrence_last']
开发者ID:vincentwyshan,项目名称:tap,代码行数:39,代码来源:rpcstats.py

示例7: main

# 需要导入模块: from tap.models import DBSession [as 别名]
# 或者: from tap.models.DBSession import flush [as 别名]
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        password = encrypt_password("admin")
        user = DBSession.query(TapUser).filter_by(name=u'admin').first()
        if not user:
            user = TapUser(name=u'admin', password=password, is_admin=True)
            DBSession.add(user)
            DBSession.flush()
        project = DBSession.query(TapProject).filter_by(name=u'PROJECT0').first()
        if not project:
            project = TapProject(name=u'PROJECT0', cnname=u"测试",
                                 description=u"测试项目", uid_create=user.id)
            DBSession.add(project)

    init_permision()
开发者ID:vincentwyshan,项目名称:tap,代码行数:26,代码来源:initializedb.py


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