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


Python Session.execute方法代码示例

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


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

示例1: test_refresh

# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import execute [as 别名]
 def test_refresh( self ):
     from camelot.core.orm import Session
     from camelot.model.party import Person
     refresh_action = application_action.Refresh()
     session = Session()
     #
     # create objects in various states
     #
     p1 = Person(first_name = u'p1', last_name = u'persistent' )
     p2 = Person(first_name = u'p2', last_name = u'dirty' )
     p3 = Person(first_name = u'p3', last_name = u'deleted' )
     p4 = Person(first_name = u'p4', last_name = u'to be deleted' )
     p5 = Person(first_name = u'p5', last_name = u'detached' )
     p6 = Person(first_name = u'p6', last_name = u'deleted outside session' )
     session.flush()
     p3.delete()
     session.flush()
     p4.delete()
     p2.last_name = u'clean'
     #
     # delete p6 without the session being aware
     #
     person_table = Person.table
     session.execute( person_table.delete().where( person_table.c.party_id == p6.id ) )
     #
     # refresh the session through the action
     #
     list( refresh_action.model_run( self.context ) )
     self.assertEqual( p2.last_name, u'dirty' )
开发者ID:odmsolutions,项目名称:Camelot,代码行数:31,代码来源:test_action.py

示例2: test_i18n

# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import execute [as 别名]
 def test_i18n( self ):
     from camelot.model.i18n import Translation, ExportAsPO
     session = Session()
     session.execute( Translation.__table__.delete() )
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), None )
     # run twice to check all branches in the code
     Translation.translate_or_register( 'bucket', 'nl_BE' )
     Translation.translate_or_register( 'bucket', 'nl_BE' )
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), 'bucket' )
     self.assertEqual( Translation.translate( '', 'nl_BE' ), '' )
     self.assertEqual( Translation.translate_or_register( '', 'nl_BE' ), '' )
     # clear the cache
     Translation._cache.clear()
     # fill the cache again
     translation = Translation( language = 'nl_BE', source = 'bucket',
                                value = 'emmer', uid=1 )
     orm.object_session( translation ).flush()
     self.assertEqual( Translation.translate( 'bucket', 'nl_BE' ), 'emmer' )
     export_action = ExportAsPO()
     model_context = MockModelContext()
     model_context.obj = translation
     try:
         generator = export_action.model_run( model_context )
         file_step = generator.next()
         generator.send( ['/tmp/test.po'] )
     except StopIteration:
         pass
开发者ID:jeroendierckx,项目名称:Camelot,代码行数:29,代码来源:test_model.py

示例3: get_filter_data

# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import execute [as 别名]
    def get_filter_data(self, admin):
        """
        :return:  a :class:`filter_data` object
        """
        from sqlalchemy.sql import select
        from camelot.core.orm import Session
        session = Session()
        filter_names = []
        joins = []
        #
        # in case of inheritance, use the local table to be able to join,
        # otherwise use the mapped table, to be able to filter on views
        #
        if admin.mapper!=admin.mapper.base_mapper:
            table = admin.mapper.local_table
        else:
            table = admin.mapper.mapped_table
        path = self.attribute.split('.')
        for field_name in path:
            attributes = admin.get_field_attributes(field_name)
            filter_names.append(attributes['name'])
            # @todo: if the filter is not on an attribute of the relation, but on the relation itselves
            if 'target' in attributes:
                admin = attributes['admin']
                joins.append(field_name)
                if attributes['direction'] == 'manytoone':
                    table = admin.entity.table.join( table )
                else:
                    table = admin.entity.table

        col = getattr( admin.entity, field_name )
        query = select([col], distinct=True, order_by=col.asc()).select_from(table)
          
        def create_decorator(col, attributes, value, joins):
            def decorator(q):
                if joins:
                    q = q.join( *joins, aliased=True)
                if 'precision' in attributes:
                    delta = pow( 10,  -1*attributes['precision'])
                    return q.filter( sql.and_(col < value+delta, col > value-delta) )
                return q.filter(col==value)
              
            return decorator

        options = [ filter_option( name = _('All'),
                                   value = Filter.All,
                                   decorator = lambda q:q ) ]
        
        for value in session.execute(query):
            if 'to_string' in attributes:
                option_name = attributes['to_string'](value[0])
            else:
                option_name = value[0]
            if attributes.get( 'translate_content', False ):
                option_name = _( option_name )
        
            options.append( filter_option( name = option_name,
                                           value = value[0],
                                           decorator = create_decorator(col, attributes, value[0], joins) ) )
        
        return filter_data( name = filter_names[0],
                            options = options,
                            default = self.default )
开发者ID:Governa,项目名称:Camelot,代码行数:65,代码来源:filters.py


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