Package Camelot :: Package camelot :: Package view :: Package wizard :: Package pages :: Module update_entities_page
[frames] | no frames]

Source Code for Module Camelot.camelot.view.wizard.pages.update_entities_page

 1  ''' 
 2  Created on Jan 18, 2010 
 3   
 4  @author: tw55413 
 5  ''' 
 6   
 7  from progress_page import ProgressPage 
 8   
 9   
10 -class UpdateEntitiesPage(ProgressPage):
11 """A progress page that updates each entity in a collection, 12 then flushes the entity, and informs all views that the entity 13 has been updated. Subclass this page and implement update_entity 14 to make this page do something. 15 """ 16
17 - def __init__(self, collection_getter, parent):
18 super(UpdateEntitiesPage, self).__init__( parent ) 19 self._wizard = parent 20 self._collection_getter = collection_getter
21
22 - def update_entity(self, entity):
23 """Implement this method to update the entities in the 24 collection. 25 26 :param entity: the entity that should be updated 27 :return: None or a string that will be displayed in the progress 28 screen. 29 """ 30 pass
31
32 - def run(self):
33 from sqlalchemy.orm.session import Session 34 from camelot.view.remote_signals import get_signal_handler 35 signal_handler = get_signal_handler() 36 collection = list(self._collection_getter()) 37 self.emit(self.update_maximum_signal, len(collection)) 38 for i, entity in enumerate(collection): 39 message = self.update_entity(entity) 40 Session.object_session( entity ).flush( [entity] ) 41 signal_handler.sendEntityUpdate( self, entity ) 42 self.emit(self.update_progress_signal, i, message)
43