本文整理汇总了Python中camelot.core.orm.Session.expunge方法的典型用法代码示例。如果您正苦于以下问题:Python Session.expunge方法的具体用法?Python Session.expunge怎么用?Python Session.expunge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类camelot.core.orm.Session
的用法示例。
在下文中一共展示了Session.expunge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fixture
# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import expunge [as 别名]
def test_fixture( self ):
from camelot.model.party import Person
from camelot.model.fixture import Fixture
session = Session()
self.assertEqual( Fixture.find_fixture_key( Person, -1 ), None )
p1 = Person()
self.assertEqual( Fixture.find_fixture_key_and_class( p1 ),
(None, None) )
session.expunge( p1 )
# insert a new Fixture
p2 = Fixture.insert_or_update_fixture( Person, 'test',
{'first_name':'Peter',
'last_name':'Principle'},
fixture_class = 'test' )
# see if we can find it back
self.assertEqual( Fixture.find_fixture_key( Person, p2.id ), 'test' )
self.assertEqual( Fixture.find_fixture_key_and_class( p2 ),
('test', 'test') )
self.assertEqual( Fixture.find_fixture_keys_and_classes( Person )[p2.id],
('test', 'test') )
# delete the person, and insert it back in the same fixture
session.delete( p2 )
session.flush()
p3 = Fixture.insert_or_update_fixture( Person, 'test',
{'first_name':'Peter',
'last_name':'Principle'},
fixture_class = 'test' )
self.assertNotEqual( p2, p3 )
# remove all fixtures
Fixture.remove_all_fixtures( Person )
示例2: model_run
# 需要导入模块: from camelot.core.orm import Session [as 别名]
# 或者: from camelot.core.orm.Session import expunge [as 别名]
def model_run( self, model_context ):
import sqlalchemy.exc as sa_exc
from camelot.core.orm import Session
from camelot.view import action_steps
from camelot.view.remote_signals import get_signal_handler
LOGGER.debug('session refresh requested')
progress_db_message = ugettext('Reload data from database')
progress_view_message = ugettext('Update screens')
session = Session()
signal_handler = get_signal_handler()
refreshed_objects = []
expunged_objects = []
#
# Loop over the objects one by one to be able to detect the deleted
# objects
#
session_items = len( session.identity_map )
for i, (_key, obj) in enumerate( session.identity_map.items() ):
try:
session.refresh( obj )
refreshed_objects.append( obj )
except sa_exc.InvalidRequestError:
#
# this object could not be refreshed, it was probably deleted
# outside the scope of this session, so assume it is deleted
# from the application its point of view
#
session.expunge( obj )
expunged_objects.append( obj )
if i%10 == 0:
yield action_steps.UpdateProgress( i,
session_items,
progress_db_message )
yield action_steps.UpdateProgress( text = progress_view_message )
for obj in refreshed_objects:
signal_handler.sendEntityUpdate( None, obj )
for obj in expunged_objects:
signal_handler.sendEntityDelete( None, obj )
yield action_steps.Refresh()